Add motion switch
This commit is contained in:
parent
1dc26d8f4a
commit
a19da07ac5
2 changed files with 26 additions and 1 deletions
|
|
@ -23,6 +23,7 @@
|
||||||
"disableElasticityLabel": "Disable elasticity",
|
"disableElasticityLabel": "Disable elasticity",
|
||||||
"stopDetectionLabel": "Stop detection",
|
"stopDetectionLabel": "Stop detection",
|
||||||
"trackingLabel": "Continuous tracking",
|
"trackingLabel": "Continuous tracking",
|
||||||
|
"motionLabel": "Active movement",
|
||||||
"advancedLabel": "Advanced settings",
|
"advancedLabel": "Advanced settings",
|
||||||
"startAction": "Start service",
|
"startAction": "Start service",
|
||||||
"stopAction": "Stop service",
|
"stopAction": "Stop service",
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ class MainScreen extends StatefulWidget {
|
||||||
|
|
||||||
class _MainScreenState extends State<MainScreen> {
|
class _MainScreenState extends State<MainScreen> {
|
||||||
bool trackingEnabled = false;
|
bool trackingEnabled = false;
|
||||||
|
bool? stopDetection;
|
||||||
|
bool? isMoving;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
|
@ -28,12 +30,19 @@ class _MainScreenState extends State<MainScreen> {
|
||||||
final state = await bg.BackgroundGeolocation.state;
|
final state = await bg.BackgroundGeolocation.state;
|
||||||
setState(() {
|
setState(() {
|
||||||
trackingEnabled = state.enabled;
|
trackingEnabled = state.enabled;
|
||||||
|
stopDetection = Preferences.instance.getBool(Preferences.stopDetection);
|
||||||
|
isMoving = state.isMoving;
|
||||||
});
|
});
|
||||||
bg.BackgroundGeolocation.onEnabledChange((bool enabled) {
|
bg.BackgroundGeolocation.onEnabledChange((bool enabled) {
|
||||||
setState(() {
|
setState(() {
|
||||||
trackingEnabled = enabled;
|
trackingEnabled = enabled;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
bg.BackgroundGeolocation.onMotionChange((bg.Location location) {
|
||||||
|
setState(() {
|
||||||
|
isMoving = location.isMoving;
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildTrackingCard() {
|
Widget _buildTrackingCard() {
|
||||||
|
|
@ -65,6 +74,19 @@ class _MainScreenState extends State<MainScreen> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
if (stopDetection == false)
|
||||||
|
SwitchListTile(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
title: Text(AppLocalizations.of(context)!.motionLabel),
|
||||||
|
value: isMoving == true,
|
||||||
|
onChanged: (bool value) {
|
||||||
|
if (value) {
|
||||||
|
bg.BackgroundGeolocation.changePace(true);
|
||||||
|
} else {
|
||||||
|
bg.BackgroundGeolocation.changePace(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
OverflowBar(
|
OverflowBar(
|
||||||
spacing: 8,
|
spacing: 8,
|
||||||
|
|
@ -118,7 +140,9 @@ class _MainScreenState extends State<MainScreen> {
|
||||||
FilledButton.tonal(
|
FilledButton.tonal(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await Navigator.push(context, MaterialPageRoute(builder: (_) => const SettingsScreen()));
|
await Navigator.push(context, MaterialPageRoute(builder: (_) => const SettingsScreen()));
|
||||||
setState(() {});
|
setState(() {
|
||||||
|
stopDetection = Preferences.instance.getBool(Preferences.stopDetection);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
child: Text(AppLocalizations.of(context)!.settingsButton),
|
child: Text(AppLocalizations.of(context)!.settingsButton),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue