Cleanup
This commit is contained in:
1 parent
e7409ac26b
commit
70fb6dd5ef
2 files changed
+71
-48
No files matched your search
+66
-14
@@ -2,6 +2,7 @@ import 'dart:async';
|
|||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_broadcast_receiver/flutter_broadcast_receiver.dart';
|
import 'package:flutter_broadcast_receiver/flutter_broadcast_receiver.dart';
|
||||||
|
import 'package:geolocator/geolocator.dart';
|
||||||
import 'package:isar/isar.dart';
|
import 'package:isar/isar.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:stadtbote/model/message.dart';
|
import 'package:stadtbote/model/message.dart';
|
||||||
@@ -29,14 +30,11 @@ Future<void> main() async {
|
|||||||
MessageSchema,
|
MessageSchema,
|
||||||
], directory: dir.path);
|
], directory: dir.path);
|
||||||
|
|
||||||
runZonedGuarded(() {
|
runZonedGuarded(() {}, (error, stackTrace) {
|
||||||
}, (error, stackTrace) {
|
|
||||||
_traceUncaughtExceptions(error, stackTrace);
|
_traceUncaughtExceptions(error, stackTrace);
|
||||||
});
|
});
|
||||||
|
|
||||||
MqttCore.setup();
|
runApp(MyApp());
|
||||||
|
|
||||||
runApp(const MyApp());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _traceUncaughtExceptions(Object error, StackTrace stackTrace) {
|
void _traceUncaughtExceptions(Object error, StackTrace stackTrace) {
|
||||||
@@ -45,10 +43,16 @@ void _traceUncaughtExceptions(Object error, StackTrace stackTrace) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
class MyApp extends StatelessWidget {
|
||||||
const MyApp({super.key});
|
MyApp({super.key}) {
|
||||||
|
MqttCore.setup();
|
||||||
|
|
||||||
|
_startLocationService();
|
||||||
|
}
|
||||||
|
|
||||||
static late Isar isarInstance;
|
static late Isar isarInstance;
|
||||||
|
|
||||||
|
static Position? currentPosition;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
@@ -59,6 +63,56 @@ class MyApp extends StatelessWidget {
|
|||||||
home: const Main(),
|
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 {
|
class Main extends StatefulWidget {
|
||||||
@@ -134,9 +188,7 @@ class _MainState extends State<Main> {
|
|||||||
key: GlobalKey(),
|
key: GlobalKey(),
|
||||||
child: PopScope(
|
child: PopScope(
|
||||||
canPop: contentStack.isNotEmpty,
|
canPop: contentStack.isNotEmpty,
|
||||||
onPopInvoked: (didPop) => {
|
onPopInvoked: (didPop) => {_popContentView()},
|
||||||
_popContentView()
|
|
||||||
},
|
|
||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
appBar: PreferredSize(
|
appBar: PreferredSize(
|
||||||
preferredSize: const Size.fromHeight(100),
|
preferredSize: const Size.fromHeight(100),
|
||||||
@@ -203,9 +255,7 @@ class _MainState extends State<Main> {
|
|||||||
SizedBox(
|
SizedBox(
|
||||||
height: 100,
|
height: 100,
|
||||||
width: 300,
|
width: 300,
|
||||||
child: Center(
|
child: Center(heightFactor: 1, child: _currentTitleWidget),
|
||||||
heightFactor: 1,
|
|
||||||
child: _currentTitleWidget),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -224,11 +274,13 @@ class _MainState extends State<Main> {
|
|||||||
height: 30,
|
height: 30,
|
||||||
color: Colors.red,
|
color: Colors.red,
|
||||||
child: const Center(
|
child: const Center(
|
||||||
child: Text("*** OFFLINE ***",
|
child: Text(
|
||||||
|
"*** OFFLINE ***",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontSize: 15.0,
|
fontSize: 15.0,
|
||||||
),),
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -163,38 +163,9 @@ Future<List<Widget>> _createListEntries() async {
|
|||||||
return entries;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
private void SendAnswer(int item)
|
|
||||||
{
|
|
||||||
JObject payloadObject;
|
|
||||||
|
|
||||||
var location = App.CurrentLocation;
|
|
||||||
if (location != null)
|
|
||||||
payloadObject = new JObject(
|
|
||||||
new JProperty("reaction", new JObject(
|
|
||||||
new JProperty("id", _jobViewModel.IdString),
|
|
||||||
new JProperty("ver", _jobViewModel.Version),
|
|
||||||
new JProperty("item", item),
|
|
||||||
new JProperty("track", new JObject(
|
|
||||||
new JProperty("time", DateTime.Now.ToString("o")),
|
|
||||||
new JProperty("pos", new JObject(
|
|
||||||
new JProperty("lat", location.Latitude),
|
|
||||||
new JProperty("long", location.Longitude),
|
|
||||||
new JProperty("acc", location.Accuracy))))))));
|
|
||||||
else
|
|
||||||
payloadObject = new JObject(
|
|
||||||
new JProperty("reaction", new JObject(
|
|
||||||
new JProperty("id", _jobViewModel.IdString),
|
|
||||||
new JProperty("ver", _jobViewModel.Version),
|
|
||||||
new JProperty("item", item),
|
|
||||||
new JProperty("track", new JObject(
|
|
||||||
new JProperty("time", DateTime.Now.ToString("o")))))));
|
|
||||||
|
|
||||||
App.Core.SendJsonMessageAsync("job", payloadObject);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
_sendAnswer(Job job, int item) {
|
_sendAnswer(Job job, int item) {
|
||||||
|
var currentPosition = MyApp.currentPosition;
|
||||||
|
|
||||||
var message = AcceptJobMessage();
|
var message = AcceptJobMessage();
|
||||||
message.reaction = Reaction();
|
message.reaction = Reaction();
|
||||||
message.reaction.id = job.id.toString();
|
message.reaction.id = job.id.toString();
|
||||||
@@ -203,9 +174,9 @@ _sendAnswer(Job job, int item) {
|
|||||||
message.reaction.track = Track();
|
message.reaction.track = Track();
|
||||||
message.reaction.track.time = DateTime.now().toUtc().toIso8601String();
|
message.reaction.track.time = DateTime.now().toUtc().toIso8601String();
|
||||||
message.reaction.track.pos = Pos();
|
message.reaction.track.pos = Pos();
|
||||||
message.reaction.track.pos.lat = 0;
|
message.reaction.track.pos.lat = currentPosition != null ? currentPosition.latitude : 0.0;
|
||||||
message.reaction.track.pos.long = 0;
|
message.reaction.track.pos.long = currentPosition != null ? currentPosition.longitude : 0.0;
|
||||||
message.reaction.track.pos.acc = 1;
|
message.reaction.track.pos.acc = currentPosition != null ? currentPosition.accuracy : 0.0;
|
||||||
|
|
||||||
MqttCore.instance.publishPayloadMessage("job", message.toJson());
|
MqttCore.instance.publishPayloadMessage("job", message.toJson());
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user