File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed
bluetooth_home_screen/cubit Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -18,11 +18,18 @@ class BluetoothHomeCubit extends Cubit<BluetoothHomeState> {
18
18
_init ();
19
19
}
20
20
21
- Future _init () async {
22
- if (await _handlePermissions ()) {
23
- await _startBluetoothAdapterListener ();
24
- await _getPairedDevices ();
25
- }
21
+ void _init () {
22
+ _handlePermissions ().then ((granted) {
23
+ if (granted) {
24
+ _startBluetoothAdapterListener ();
25
+ }
26
+
27
+ bluetooth.isEnabled ().then ((enabled) {
28
+ if (granted && enabled! ) {
29
+ _getPairedDevices ();
30
+ }
31
+ });
32
+ });
26
33
}
27
34
28
35
Future <bool > _handlePermissions () async {
@@ -67,9 +74,9 @@ class BluetoothHomeCubit extends Cubit<BluetoothHomeState> {
67
74
}
68
75
69
76
Future <void > startScan () async {
70
- // Before proceeding to use the bluetooth features,
71
- // permissions must have to be ensured and allowed
72
- // to avoid the potential crashes.
77
+ // Ensure necessary permissions
78
+ // before using Bluetooth features
79
+ // to avoid potential crashes.
73
80
bool hasPermissions = await _handlePermissions ();
74
81
if (! hasPermissions) return ;
75
82
Original file line number Diff line number Diff line change @@ -119,9 +119,10 @@ class _BluetoothRemoteControlScreenState
119
119
[DeviceOrientation .portraitUp],
120
120
);
121
121
122
- Navigator .pushReplacementNamed (
122
+ Navigator .pushNamedAndRemoveUntil (
123
123
context,
124
124
AppRoutes .bluetoothHome,
125
+ (route) => false ,
125
126
);
126
127
showSnackBarWidget (context, state.message);
127
128
}
You can’t perform that action at this time.
0 commit comments