Skip to content

Commit 29b8956

Browse files
committed
Fixes #120 and issue where the state was was resetting to Initial state of BluetoothHomeState after navigating back
1 parent 1319a73 commit 29b8956

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

lib/screens/bluetooth_home_screen/cubit/bluetooth_home_cubit.dart

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,18 @@ class BluetoothHomeCubit extends Cubit<BluetoothHomeState> {
1818
_init();
1919
}
2020

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+
});
2633
}
2734

2835
Future<bool> _handlePermissions() async {
@@ -67,9 +74,9 @@ class BluetoothHomeCubit extends Cubit<BluetoothHomeState> {
6774
}
6875

6976
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.
7380
bool hasPermissions = await _handlePermissions();
7481
if (!hasPermissions) return;
7582

lib/screens/bluetooth_remote_screen/bluetooth_remote_screen.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,10 @@ class _BluetoothRemoteControlScreenState
119119
[DeviceOrientation.portraitUp],
120120
);
121121

122-
Navigator.pushReplacementNamed(
122+
Navigator.pushNamedAndRemoveUntil(
123123
context,
124124
AppRoutes.bluetoothHome,
125+
(route) => false,
125126
);
126127
showSnackBarWidget(context, state.message);
127128
}

0 commit comments

Comments
 (0)