enable method
Enable the background service.
Implementation
Future<bool> enable() async {
if (!_initialized) {
warning('$runtimeType - Background service is not initialized.');
return false;
}
bool enabled = FlutterBackground.isBackgroundExecutionEnabled;
if (enabled) {
warning('$runtimeType - Background service is already enabled.');
return true;
}
bool hasPermissions = await FlutterBackground.hasPermissions;
if (!hasPermissions) {
warning('$runtimeType - Background service does not have permissions.');
return false;
}
info('Enabling background service...');
_enabled = await FlutterBackground.enableBackgroundExecution();
if (!_enabled) {
warning('$runtimeType - Failed to enable background service.');
}
debug('$runtimeType - Background service enabled: $_enabled');
return _enabled;
}