diff options
| author | Mica White <botahamec@outlook.com> | 2025-12-26 18:49:24 -0500 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2025-12-26 18:49:24 -0500 |
| commit | 5ef290f3fe7bac7cad26aae16d884cd23dce0e30 (patch) | |
| tree | 04ecac5730f2e0affc93d519795a09a157203486 /lib/main.dart | |
| parent | be582b269e4901a9bd5f2549f2dc1d4cfd9d31a7 (diff) | |
Fix permissioning
Diffstat (limited to 'lib/main.dart')
| -rwxr-xr-x | lib/main.dart | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/lib/main.dart b/lib/main.dart index f6bbb92..273f93f 100755 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,7 +17,7 @@ extension on SpeedUnit { };
}
-void main() {
+void main() async {
runApp(const MyApp());
}
@@ -56,9 +56,7 @@ class _HomePageState extends State<HomePage> { SpeedUnit _speedUnit = SpeedUnit.milesPerHour;
LocationSettings _locationSettings = LocationSettings();
- @override
- void initState() {
- super.initState();
+ _initPositionStream() {
_positionStream =
Geolocator.getPositionStream(
locationSettings: _locationSettings,
@@ -73,6 +71,26 @@ class _HomePageState extends State<HomePage> { }
@override
+ void initState() {
+ super.initState();
+
+ Geolocator.checkPermission()
+ .then(
+ (permission) => permission == LocationPermission.denied
+ ? Geolocator.requestPermission()
+ : permission,
+ )
+ .then((permission) {
+ if (![
+ LocationPermission.deniedForever,
+ LocationPermission.denied,
+ ].contains(permission)) {
+ _initPositionStream();
+ }
+ });
+ }
+
+ @override
void dispose() {
super.dispose();
_positionStream?.cancel();
@@ -106,11 +124,11 @@ class _HomePageState extends State<HomePage> { children: [
Flex(direction: Axis.horizontal),
Text(
- '${_speedUnit.fromMetersPerSecond(_speed)} ${_speedUnit.acronym}',
+ '${_speedUnit.fromMetersPerSecond(_speed).round()} ${_speedUnit.acronym}',
style: Theme.of(context).textTheme.displayLarge,
),
Text(
- '± ${_speedUnit.fromMetersPerSecond(_speedAccuracy)} ${_speedUnit.acronym}',
+ '± ${_speedUnit.fromMetersPerSecond(_speedAccuracy).round()} ${_speedUnit.acronym}',
style: Theme.of(context).textTheme.displaySmall,
),
],
|
