Skip to content

Commit

Permalink
Fixes #120 and issue where the state was was resetting to Initial sta…
Browse files Browse the repository at this point in the history
…te of BluetoothHomeState after navigating back
  • Loading branch information
mediocre9 committed Jan 16, 2024
1 parent 1319a73 commit 29b8956
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
23 changes: 15 additions & 8 deletions lib/screens/bluetooth_home_screen/cubit/bluetooth_home_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ class BluetoothHomeCubit extends Cubit<BluetoothHomeState> {
_init();
}

Future _init() async {
if (await _handlePermissions()) {
await _startBluetoothAdapterListener();
await _getPairedDevices();
}
void _init() {
_handlePermissions().then((granted) {
if (granted) {
_startBluetoothAdapterListener();
}

bluetooth.isEnabled().then((enabled) {
if (granted && enabled!) {
_getPairedDevices();
}
});
});
}

Future<bool> _handlePermissions() async {
Expand Down Expand Up @@ -67,9 +74,9 @@ class BluetoothHomeCubit extends Cubit<BluetoothHomeState> {
}

Future<void> startScan() async {
// Before proceeding to use the bluetooth features,
// permissions must have to be ensured and allowed
// to avoid the potential crashes.
// Ensure necessary permissions
// before using Bluetooth features
// to avoid potential crashes.
bool hasPermissions = await _handlePermissions();
if (!hasPermissions) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ class _BluetoothRemoteControlScreenState
[DeviceOrientation.portraitUp],
);

Navigator.pushReplacementNamed(
Navigator.pushNamedAndRemoveUntil(
context,
AppRoutes.bluetoothHome,
(route) => false,
);
showSnackBarWidget(context, state.message);
}
Expand Down

0 comments on commit 29b8956

Please sign in to comment.