Add wake lock and optimization
This commit is contained in:
parent
e0f2bde919
commit
4ac4f1f892
8 changed files with 108 additions and 18 deletions
|
|
@ -3,6 +3,7 @@ import 'dart:io';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg;
|
||||
import 'package:wakelock_partial_android/wakelock_partial_android.dart';
|
||||
|
||||
import 'l10n/app_localizations.dart';
|
||||
import 'preferences.dart';
|
||||
|
|
@ -179,6 +180,14 @@ class _SettingsScreenState extends State<SettingsScreen> {
|
|||
value: wakelock,
|
||||
onChanged: (value) async {
|
||||
await Preferences.instance.setBool(Preferences.wakelock, value);
|
||||
if (value) {
|
||||
final state = await bg.BackgroundGeolocation.state;
|
||||
if (state.isMoving == true) {
|
||||
WakelockPartialAndroid.acquire();
|
||||
}
|
||||
} else {
|
||||
WakelockPartialAndroid.release();
|
||||
}
|
||||
setState(() => wakelock = value);
|
||||
},
|
||||
),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue