title: How to check if user change a given permission or disable location or bluetooth?
body: <br>
  I've some trouble on my flutter project.<br>
  I want to ask location permission, check if location and bluetooth are enabled and then, when they are granted and enabled, change the page.<br>
  So far so good but now i want that if user, during the app usage, disable location, bluetooth or remove the location permission will go back and see the corresponding message.<br>
  My attempt was to check when the app is resumed and then call the method askPermission() that if return granted will go to check location state and then the bluetooth state.<br>
  My problem is thet if i disabled location or bluetooth nothing happens but if i remove the location permission when resume the app it will ask for permission and THEN ask to turn on the GPS or BLE.<br>
  I can't understand why it happen...can you pin point me to the issue?
  <p>This is my first page that after 5 seconds route the app to permission.dart:</p>
  <pre class="lang-dart prettyprint-override"><code>import 'package:get/get.dart';
  import 'package:flutter/material.dart';
  import 'package:permessi/routes/index_routes.dart';
  import 'dart:async';
  
  class Initial extends StatefulWidget {
    const Initial({Key? key}) : super(key: key);
    @override
    State&lt;Initial&gt; createState() =&gt; InitialState();
  }
  
  class InitialState extends State&lt;Initial&gt; {
    @override
    initState() {
      super.initState();
      Timer(const Duration(seconds: 5), handleTimeout);
    }
  
    void handleTimeout() {
      Get.toNamed(AppRoutes.permission);
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: AppBar(
          backgroundColor: const Color(0xFF0e0c20),
          title: const Text('INITIAL'),
          elevation: 0,
          centerTitle: true,
        ),
        body: const Center(
          child: Text(
            'INITIAL',
            style: TextStyle(
              fontSize: 60,
            ),
          ),
        ),
      );
    }
  }
  
  </code></pre>
  <p>This my permission.dart file:</p>
  <pre class="lang-dart prettyprint-override"><code>import 'package:app_settings/app_settings.dart';
  import 'package:flutter/material.dart';
  import 'package:get/get.dart';
  import 'package:geolocator/geolocator.dart';
  import 'package:google_fonts/google_fonts.dart';
  import 'package:permession/routes/index_routes.dart';
  import 'package:flutter_blue_elves/flutter_blue_elves.dart';
  import 'dart:io' show Platform;
  
  enum AppStatus { 
     permissionCheck, 
     gpsCheck, 
     bleCheck,  
  }
  
  class Permissions extends StatefulWidget {
    const Permissions({Key? key}) : super(key: key);
  
    @override
    State&lt;Permissions&gt; createState() =&gt; PermissionsState();
  }
  
  class PermissionsState extends State&lt;Permissions&gt; with WidgetsBindingObserver {
    
    double opacity = 0;
    bool openedSettings = false;
    LocationPermission? permission;
    bool serviceEnabled = false;
    String? platform;
    bool bleEnabled = false;
    AppStatus appStatus = AppStatus.permissionCheck;
    String title = '';
    String message = '';
  
    @override
    initState() {
      super.initState();
      WidgetsBinding.instance?.addObserver(this);
      //start checking permission
      askPermissions();
    }
  
    @override
    void dispose() {
      WidgetsBinding.instance?.removeObserver(this);
      super.dispose();
    }
  
    void askPermissions() async {
      //set the appStatus to permissionCheck
      appStatus = AppStatus.permissionCheck;
      //check if permission are already granted
      permission = await Geolocator.checkPermission();
      if ((permission != LocationPermission.always) || (permission != LocationPermission.whileInUse)) {
        //location permission not yet granted - requested it
        permission = await Geolocator.requestPermission();
        if ((permission == LocationPermission.always) || (permission == LocationPermission.whileInUse)) {
          //location was granted
          //start checking if location are enabled
          checkGPS();
        } else {
          //location was rejected
          openedSettings = false;
          //pass the title &amp; message to the showMessage() and call it
          showMessage(
            'Location Permission',
            'We need your permission to have access to your position.\nPlease open app setting and grant it.',
          );
        }
      } else {
        //location was granted
        //start checking if location are enabled
        checkGPS();
      }
    }
    
    void checkGPS() async {
      //set the appStatus to gpsCheck
      appStatus = AppStatus.gpsCheck;
      //check if location are enabled
      serviceEnabled = await Geolocator.isLocationServiceEnabled();
      //location not enabled
      if (!serviceEnabled) {
        openedSettings = false;
        //pass the title &amp; message to the showMessage() and call it
        showMessage(
          'GPS Not Enabled',
          'We need GPS to be enabled to have access to your position.\nPlease open system setting and enable it.',
        );
      } else {
        //location is enabled
        //start checking if bluetooth is enabled based on platform
        checkPlatform();
      }
    }
  
    void checkPlatform() {
      appStatus = AppStatus.bleCheck;
      if (Platform.isAndroid) {
        platform = 'android';
        checkBLEAndroid();
      } else if (Platform.isIOS) {
        platform = 'ios';
        checkBLEiOs();
      }
    }
  
    void checkBLEAndroid() async {
      //set the appStatus to bleCheck
      appStatus = AppStatus.bleCheck;
      //check if bluetooth is enabled
      FlutterBlueElves.instance.androidCheckBlueLackWhat().then(
        (values) {
          if (values.contains(AndroidBluetoothLack.bluetoothFunction)) {
            //bluetooth not enabled
            openedSettings = false;
            //pass the title &amp; message to the showMessage() and call it
            showMessage(
              'Bluetooth is OFF',
              'We need bluetooth turned on to be able to connect with it.\nPlease open the Bluetooth setting and turn it on.',
            );
          } else {
            //bluetooth is enabled
            //all done, go to the final page but not replace it
            Get.toNamed(AppRoutes.pagina);
          }
        },
      );
    }
  
    void checkBLEiOs() async {
      //set the appStatus to bleCheck
      appStatus = AppStatus.bleCheck;
      //check if bluetooth is enabled
      FlutterBlueElves.instance.iosCheckBluetoothState().then(
        (value) {
          if (value == IosBluetoothState.unKnown) {
            //bluetooth not enabled
            openedSettings = false;
            //pass the title &amp; message to the showMessage() and call it
            showMessage(
              'Bluetooth is OFF',
              'We need bluetooth turned on to be able to connect with it.\nPlease open the Bluetooth setting and turn it on.',
            );
          } else if (value == IosBluetoothState.resetting) {
            //bluetooth not enabled
            openedSettings = false;
            //pass the title &amp; message to the showMessage() and call it
            showMessage(
              'Bluetooth is OFF',
              'We need bluetooth turned on to be able to connect with it.\nPlease open the Bluetooth setting and turn it on.',
            );
          } else if (value == IosBluetoothState.unSupport) {
            //bluetooth not enabled
            openedSettings = false;
            //pass the title &amp; message to the showMessage() and call it
            showMessage(
              'Bluetooth is OFF',
              'We need bluetooth turned on to be able to connect with it.\nPlease open the Bluetooth setting and turn it on.',
            );
          } else if (value == IosBluetoothState.unAuthorized) {
            //bluetooth not enabled
            openedSettings = false;
            //pass the title &amp; message to the showMessage() and call it
            showMessage(
              'Bluetooth is OFF',
              'We need bluetooth turned on to be able to connect with it.\nPlease open the Bluetooth setting and turn it on.',
            );
          } else if (value == IosBluetoothState.poweredOff) {
            //bluetooth not enabled
            openedSettings = false;
            //pass the title &amp; message to the showMessage() and call it
            showMessage(
              'Bluetooth is OFF',
              'We need bluetooth turned on to be able to connect with it.\nPlease open the Bluetooth setting and turn it on.',
            );
          } else {
            //bluetooth is enabled
            //all done, go to the final page but not replace it
            Get.toNamed(AppRoutes.pagina);
          }
        },
      );
    }
  
    void showMessage(String titolo, String messaggio) {
      //use the recived value to update the message string
      //change opacity to show the message
      setState(() {
        title = titolo;
        message = messaggio;
        opacity = 1;
      });
    }
  
    @override
    void didChangeAppLifecycleState(AppLifecycleState state) async {
      switch (state) {
        case AppLifecycleState.resumed:
          //if app is resumed all variable are resetted
          //and call the askPermissions() to restart all the previus check (GPS &amp; BLE included)
          if (openedSettings) {
            appStatus = AppStatus.permissionCheck;
            opacity = 0;
            openedSettings = false;
            serviceEnabled = false;
            bleEnabled = false;
            title = '';
            message = '';
            askPermissions();
          }
          debugPrint('App resumed');
          break;
        case AppLifecycleState.inactive:
          debugPrint('App inactive');
          break;
        case AppLifecycleState.paused:
          setState(() {
            opacity = 0;
          });
          debugPrint('App paused');
          openedSettings = true;
          break;
        case AppLifecycleState.detached:
          debugPrint('App detached');
          break;
      }
    }
  
    @override
    Widget build(BuildContext context) {
      //build the screen with a container as a dialog box
      return Scaffold(
        backgroundColor: const Color(0xFF2b2b3d),
        body: SafeArea(
          child: Center(
            child: Opacity(
              opacity: opacity,
              child: Padding(
                padding: const EdgeInsets.only(
                  left: 32,
                  right: 32,
                ),
                child: SizedBox(
                  width: double.infinity,
                  height: 180,
                  child: Container(
                    decoration: BoxDecoration(
                      gradient: const LinearGradient(
                        colors: [
                          Color(0xFF4D4D64),
                          Color(0xFF363649)
                        ],
                        stops: [
                          0,
                          1
                        ],
                        begin: AlignmentDirectional(1, -1),
                        end: AlignmentDirectional(-1, 1),
                      ),
                      borderRadius: BorderRadius.circular(30),
                    ),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Padding(
                          padding: const EdgeInsets.all(16),
                          child: Text(
                            //using the variable title updated in showMessage()
                            title,
                            textAlign: TextAlign.center,
                            style: GoogleFonts.outfit(
                              fontSize: 25,
                              textStyle: const TextStyle(color: Color(0xFFFFFFFF)),
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.only(left: 16, right: 16),
                          child: Text(
                            //using the variable message updated in showMessage()
                            message,
                            textAlign: TextAlign.center,
                            style: GoogleFonts.outfit(
                              fontSize: 16,
                              textStyle: const TextStyle(color: Color(0xFFFFFFFF)),
                            ),
                          ),
                        ),
                        Padding(
                          padding: const EdgeInsets.all(16),
                          child: SizedBox(
                            width: 130,
                            height: 40,
                            //the button that open the setting page based on the AppStatus
                            child: ElevatedButton(
                              style: ButtonStyle(
                                backgroundColor: MaterialStateProperty.all(const Color(0xFFFFFFFF)),
                                shape: MaterialStateProperty.all&lt;RoundedRectangleBorder&gt;(
                                  RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(18.0),
                                    side: const BorderSide(color: Colors.black),
                                  ),
                                ),
                              ),
                              onPressed: () {
                                //this variable is used in the resumed state of didChangeAppLifecycleState
                                openedSettings = true;
                                switch (appStatus){
                                  case AppStatus.permissionCheck:
                                    AppSettings.openAppSettings();
                                    break;
                                  case AppStatus.gpsCheck:
                                    AppSettings.openLocationSettings();
                                    break;
                                  case AppStatus.bleCheck:
                                    AppSettings.openBluetoothSettings();
                                    break;
                                }
                                setState(() {
                                  opacity = 1;
                                });
                              },
                              child: Text(
                                'OK',
                                textAlign: TextAlign.center,
                                style: GoogleFonts.outfit(
                                  fontSize: 16,
                                  textStyle: const TextStyle(color: Colors.black),
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      );
    }
  }
  </code></pre>