summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/main.dart30
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,
),
],