I'm trying to check if the active Flutter session is on developer mode using safe_device on it's version: ^1.1.4, and I'm getting this log:

W/Settings( 4572): Setting development_settings_enabled has moved from android.provider.Settings.Secure to android.provider.Settings.Global.

Here is my code

class DeveloperModeChecker extends StatefulWidget {
  const DeveloperModeChecker({Key? key}) : super(key: key);

  @override
  _DeveloperModeCheckerState createState() => _DeveloperModeCheckerState();
}

class _DeveloperModeCheckerState extends State<DeveloperModeChecker> {
  @override
  void initState() {
    super.initState();
    startCheckingDeveloperMode();
  }

  Future<void> startCheckingDeveloperMode() async {
    while (true) {
      try {
        bool developerMode = await SafeDevice.isDevelopmentModeEnable;
        //print("Developer Mode Status: $developerMode");
        if (developerMode == true){
          print("out from the app");
        }
      } catch (error) {
        print("Error: $error");
      }
      await Future.delayed(const Duration(seconds: 5));
    }
  }

  @override
  Widget build(BuildContext context) {
    return SizedBox.shrink();
  }
}
class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        resizeToAvoidBottomInset: false,
        body: Stack(
          children: [
            const LoginScreen(),
            const DeveloperModeChecker(),
          ],
        ),
      );
  }
}
1

There are 1 best solutions below

0
On

Changing the ways.

Not checking every time user on application, but in start on in resume state, to check if the user activating developer mode

#1) Adding The function

Future <bool> checkDeveloperMode() async{
    bool isDevMode = false;
    isDevMode = await SafeDevice.isDevelopmentModeEnable; 
    return isDevMode;
  } 

#2) Extending the apps into widget observer

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {}

#3) Check the user condition in initState, and initializing WidgetBinding to check if application state changing, dispose function

void initState() {
// TODO: implement initState
 checkDeveloperMode().then((value){
 print("isDeveloperMode : ${value}");
if (value == true){
 Navigator.push(context, MaterialPageRoute(builder: (context)=> Enable))
}
});
 //print("check developer mode ${checkDeveloperMode().toString()}");

 WidgetsBinding.instance!.addObserver(this);
 super.initState();
}
void dispose() {
// TODO: implement dispose
 WidgetsBinding.instance!.removeObserver(this);
 super.dispose();
}

#4) Checking if user going back to the application again

      @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    // TODO: implement didChangeAppLifecycleState
    if (state == AppLifecycleState.resumed){
      checkDeveloperMode().then((value){
        print("isDeveloperModeAfterResume : ${value}");
        if (value == true){
          Navigator.push(context, MaterialPageRoute(builder: (context)=> EnableDevChecker()));
        }
      });
    }
    super.didChangeAppLifecycleState(state);
  }