diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 5440fd1..7ac4caf 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -23,6 +23,7 @@ "disableElasticityLabel": "Disable elasticity", "stopDetectionLabel": "Stop detection", "trackingLabel": "Continuous tracking", + "motionLabel": "Active movement", "advancedLabel": "Advanced settings", "startAction": "Start service", "stopAction": "Stop service", diff --git a/lib/main_screen.dart b/lib/main_screen.dart index 38f4aba..a553604 100644 --- a/lib/main_screen.dart +++ b/lib/main_screen.dart @@ -17,6 +17,8 @@ class MainScreen extends StatefulWidget { class _MainScreenState extends State { bool trackingEnabled = false; + bool? stopDetection; + bool? isMoving; @override void initState() { @@ -28,12 +30,19 @@ class _MainScreenState extends State { final state = await bg.BackgroundGeolocation.state; setState(() { trackingEnabled = state.enabled; + stopDetection = Preferences.instance.getBool(Preferences.stopDetection); + isMoving = state.isMoving; }); bg.BackgroundGeolocation.onEnabledChange((bool enabled) { setState(() { trackingEnabled = enabled; }); }); + bg.BackgroundGeolocation.onMotionChange((bg.Location location) { + setState(() { + isMoving = location.isMoving; + }); + }); } Widget _buildTrackingCard() { @@ -65,6 +74,19 @@ class _MainScreenState extends State { } }, ), + 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), OverflowBar( spacing: 8, @@ -118,7 +140,9 @@ class _MainScreenState extends State { FilledButton.tonal( onPressed: () async { await Navigator.push(context, MaterialPageRoute(builder: (_) => const SettingsScreen())); - setState(() {}); + setState(() { + stopDetection = Preferences.instance.getBool(Preferences.stopDetection); + }); }, child: Text(AppLocalizations.of(context)!.settingsButton), ),