didPush method

  1. @override
void didPush(
  1. Route route,
  2. Route? previousRoute
)
override

The Navigator pushed route.

The route immediately below that one, and thus the previously active route, is previousRoute.

Implementation

@override
void didPush(Route route, Route? previousRoute) {
  super.didPush(route, previousRoute);
  if (route.settings.name == '/DeviceScreen') {
    // Start listening to Bluetooth state changes when a new route is pushed
    _adapterStateSubscription ??= FlutterBluePlus.adapterState.listen((state) {
      if (state != BluetoothAdapterState.on) {
        // Pop the current route if Bluetooth is off
        navigator?.pop();
      }
    });
  }
}