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(),
],
),
);
}
}
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
#2) Extending the apps into widget observer
#3) Check the user condition in initState, and initializing WidgetBinding to check if application state changing, dispose function
#4) Checking if user going back to the application again