check if the app is ignoring battery optimizations , open IGNORE BATTERY OPTIMIZATION SETTINGS (Android Only)
OptimizationBattery.isIgnoringBatteryOptimizations().then((onValue) {
setState(() {
if (onValue) {
// Igonring Battery Optimization
} else {
// App is under battery optimization
}
});
});
this opens the battery optimization settings. Apps can be placed on the whitelist through the settings UI
OptimizationBattery.openBatteryOptimizationSettings();
use BatteryOptimizationsObserver widget to detect the IgnoringBatteryOptimizations value after user openBatteryOptimizationSettings and return to the app
BatteryOptimizationsObserver(builder: (context, isIgonre) {
return Column(
children: [
Text('isIgonred : $isIgonre'),
if (isIgonre != null && !isIgonre)
ElevatedButton(
onPressed: () {
OptimizationBattery.openBatteryOptimizationSettings();
},
child: const Text("open igonre battery setting"))
],
);
})
isIgonre
will be null on ios and also at start before complete loading the state and will update the value every time user return to the app
this plugin is inspired from battery_optimization but with supporting null safety and new android plugin APIs and BatteryOptimizationsObserver