Cleanup
This commit is contained in:
1 parent
e7409ac26b
commit
70fb6dd5ef
2 files changed
+72
-49
No files matched your search
+67
-15
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_broadcast_receiver/flutter_broadcast_receiver.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:isar/isar.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:stadtbote/model/message.dart';
|
||||
@@ -29,14 +30,11 @@ Future<void> main() async {
|
||||
MessageSchema,
|
||||
], directory: dir.path);
|
||||
|
||||
runZonedGuarded(() {
|
||||
}, (error, stackTrace) {
|
||||
runZonedGuarded(() {}, (error, stackTrace) {
|
||||
_traceUncaughtExceptions(error, stackTrace);
|
||||
});
|
||||
|
||||
MqttCore.setup();
|
||||
|
||||
runApp(const MyApp());
|
||||
runApp(MyApp());
|
||||
}
|
||||
|
||||
void _traceUncaughtExceptions(Object error, StackTrace stackTrace) {
|
||||
@@ -45,10 +43,16 @@ void _traceUncaughtExceptions(Object error, StackTrace stackTrace) {
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
MyApp({super.key}) {
|
||||
MqttCore.setup();
|
||||
|
||||
_startLocationService();
|
||||
}
|
||||
|
||||
static late Isar isarInstance;
|
||||
|
||||
static Position? currentPosition;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
@@ -59,6 +63,56 @@ class MyApp extends StatelessWidget {
|
||||
home: const Main(),
|
||||
);
|
||||
}
|
||||
|
||||
_startLocationService() async {
|
||||
var result = await _handleLocationPermissions();
|
||||
|
||||
if (result) {
|
||||
LocationSettings locationSettings = const LocationSettings(
|
||||
accuracy: LocationAccuracy.high,
|
||||
distanceFilter: 0,
|
||||
);
|
||||
|
||||
Geolocator.getPositionStream(locationSettings: locationSettings).listen((Position? position) {
|
||||
MyApp.currentPosition = position;
|
||||
|
||||
Util.logInfo(position == null ? 'Unknown' : '${position.latitude.toString()}, ${position.longitude.toString()}');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> _handleLocationPermissions() async {
|
||||
// Test if location services are enabled.
|
||||
var serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) {
|
||||
// Location services are not enabled don't continue
|
||||
// accessing the position and request users of the
|
||||
// App to enable the location services.
|
||||
return false;
|
||||
//return Future.error('Location services are disabled.');
|
||||
}
|
||||
|
||||
var permission = await Geolocator.checkPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
permission = await Geolocator.requestPermission();
|
||||
if (permission == LocationPermission.denied) {
|
||||
// Permissions are denied, next time you could try
|
||||
// requesting permissions again (this is also where
|
||||
// Android's shouldShowRequestPermissionRationale
|
||||
// returned true. According to Android guidelines
|
||||
// your App should show an explanatory UI now.
|
||||
//return Future.error('Location permissions are denied');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (permission == LocationPermission.deniedForever) {
|
||||
//return Future.error('Location permissions are permanently denied, we cannot request permissions.');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class Main extends StatefulWidget {
|
||||
@@ -134,9 +188,7 @@ class _MainState extends State<Main> {
|
||||
key: GlobalKey(),
|
||||
child: PopScope(
|
||||
canPop: contentStack.isNotEmpty,
|
||||
onPopInvoked: (didPop) => {
|
||||
_popContentView()
|
||||
},
|
||||
onPopInvoked: (didPop) => {_popContentView()},
|
||||
child: Scaffold(
|
||||
appBar: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(100),
|
||||
@@ -203,9 +255,7 @@ class _MainState extends State<Main> {
|
||||
SizedBox(
|
||||
height: 100,
|
||||
width: 300,
|
||||
child: Center(
|
||||
heightFactor: 1,
|
||||
child: _currentTitleWidget),
|
||||
child: Center(heightFactor: 1, child: _currentTitleWidget),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -224,11 +274,13 @@ class _MainState extends State<Main> {
|
||||
height: 30,
|
||||
color: Colors.red,
|
||||
child: const Center(
|
||||
child: Text("*** OFFLINE ***",
|
||||
child: Text(
|
||||
"*** OFFLINE ***",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 15.0,
|
||||
),),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -236,7 +288,7 @@ class _MainState extends State<Main> {
|
||||
),
|
||||
Expanded(child: _currentContent),
|
||||
],
|
||||
),// This trailing comma makes auto-formatting nicer for build methods.
|
||||
), // This trailing comma makes auto-formatting nicer for build methods.
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user