fixPowerSettings method Null safety
Optimize device power settings by calling showPowerSaving and showBatteryOptimizations sequentially.
If a step fails the errorHandler
will be called with the provided
title
and either powerSavingError
or batteryOptimizationError
depending on the step that failed.
If no errorHandler
is provided a confirmation dialog is shown with the
title
and appropriate message for the step failed.
Implementation
fixPowerSettings({
required String title,
required String powerSavingError,
required String batteryOptimizationError,
Function(String, String)? errorHandler,
}) async {
/// Error message to be shown if step fails
late String message;
try {
message = powerSavingError;
await showPowerSaving();
message = batteryOptimizationError;
await showBatteryOptimizations();
// coverage:ignore-start
} on Exception catch (error) {
// Depending on Manufacturer/Model/OS Version, a Device may not implement
// a particular Settings screen.
print(error);
errorHandler ??= _onFixPowerSettingsFailed;
errorHandler(title, message);
}
}