Erweiterungen
This commit is contained in:
1 parent
fbdd2a4338
commit
41d086e13e
7 files changed
+103
-44
No files matched your search
@@ -327,20 +327,23 @@ class _MainPageState extends State<MainPage> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
showLogoutAlertDialog(BuildContext context) {
|
showLogoutAlertDialog(BuildContext context) async {
|
||||||
Widget yesButton = TextButton(
|
Widget yesButton = TextButton(
|
||||||
child: const Text("Ja"),
|
child: const Text("Ja"),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
_sendLogoutMessage();
|
|
||||||
|
|
||||||
Future.delayed(const Duration(seconds: 1), () async {
|
showMessageDialog(context, "Information", "Sie werden abgemeldet.\nBitte warten...");
|
||||||
MessageService().publish<DisconnectClientMessage>(Constants.messageTopicDisconnectClient, arguments: DisconnectClientMessage());
|
|
||||||
});
|
_sendLogoutMessage();
|
||||||
|
|
||||||
_loggedOut = true;
|
_loggedOut = true;
|
||||||
|
|
||||||
|
Future.delayed(const Duration(seconds: 5), () async {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
+5
-3
@@ -449,10 +449,12 @@ class _MainState extends State<Main> with SingleTickerProviderStateMixin {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _connectionStatusChanged(ConnectionStatus connectionStatus) {
|
void _connectionStatusChanged(ConnectionStatus newConnectionStatus) {
|
||||||
Util.logInfo("_connectionStatusChanged called: $connectionStatus");
|
var currentConnectionStatus = newConnectionStatus.status;
|
||||||
|
|
||||||
_connectionLostValueNotifier.value = connectionStatus.status == ConnectionStatusEnum.notConnected;
|
Util.logInfo("_connectionStatusChanged called: $currentConnectionStatus");
|
||||||
|
|
||||||
|
_connectionLostValueNotifier.value = newConnectionStatus.status == ConnectionStatusEnum.notConnected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _jobReceived(Job job) async {
|
void _jobReceived(Job job) async {
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
|
|
||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:expandable/expandable.dart';
|
import 'package:expandable/expandable.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:isar/isar.dart';
|
|
||||||
import 'package:mqtt_client/mqtt_client.dart';
|
import 'package:mqtt_client/mqtt_client.dart';
|
||||||
import 'package:stadtbote/main.dart';
|
import 'package:stadtbote/main.dart';
|
||||||
import 'package:stadtbote/protocoll_messages/accept_job_message.dart';
|
import 'package:stadtbote/protocoll_messages/accept_job_message.dart';
|
||||||
@@ -57,14 +55,16 @@ Future<void> showAcceptJobsPopup(BuildContext context, List<Job> jobs, Function(
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
MessageService().subscribe<JobReceivedMessage>(Constants.messageTopicJobReceived, jobs, (jobdMessage) async {
|
MessageService().subscribe<JobReceivedMessage>(Constants.messageTopicJobReceived, jobs, (jobMessage) async {
|
||||||
jobs.removeWhere((value) => value.id == jobdMessage.job.id);
|
jobs.removeWhere((value) => value.id == jobMessage.job.id);
|
||||||
|
|
||||||
jobs.add(jobdMessage.job);
|
if (jobMessage.job.state == 0) {
|
||||||
|
jobs.add(jobMessage.job);
|
||||||
|
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
@@ -74,15 +74,30 @@ Future<void> showAcceptJobsPopup(BuildContext context, List<Job> jobs, Function(
|
|||||||
child: Container(
|
child: Container(
|
||||||
height: 100,
|
height: 100,
|
||||||
padding: const EdgeInsets.all(5),
|
padding: const EdgeInsets.all(5),
|
||||||
child: ListView.builder(
|
child: FutureBuilder<List<Widget>>(
|
||||||
itemCount: jobs.length,
|
future: fetchJobWidgets(jobs),
|
||||||
itemBuilder: (_, i) {
|
builder: (context, snapshot) {
|
||||||
var job = jobs[i];
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||||
|
return Util.getWaitWidget(context);
|
||||||
|
} else {
|
||||||
|
return ListView(
|
||||||
|
children: snapshot.requireData,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
));
|
||||||
|
})));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<Widget>> fetchJobWidgets(List<Job> jobs) async {
|
||||||
|
List<Widget> widgets = [];
|
||||||
|
|
||||||
for (var job in jobs) {
|
for (var job in jobs) {
|
||||||
int enableDelay = job.delayOrderTime;
|
int enableDelay = 3; //job.delayOrderTime;
|
||||||
if (job.firstDisplayTime == null) {
|
if (job.firstDisplayTime == null) {
|
||||||
MyApp.isarInstance.writeTxn(() async {
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
job.firstDisplayTime = DateTime.now();
|
job.firstDisplayTime = DateTime.now();
|
||||||
|
|
||||||
await MyApp.isarInstance.jobs.put(job);
|
await MyApp.isarInstance.jobs.put(job);
|
||||||
@@ -91,9 +106,7 @@ Future<void> showAcceptJobsPopup(BuildContext context, List<Job> jobs, Function(
|
|||||||
enableDelay = max(0, DateTime.now().difference(job.firstDisplayTime!).inSeconds);
|
enableDelay = max(0, DateTime.now().difference(job.firstDisplayTime!).inSeconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
job.enableDelay = enableDelay;
|
widgets.add(StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||||
}
|
|
||||||
|
|
||||||
return ExpandableNotifier(
|
return ExpandableNotifier(
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
contentPadding: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
|
||||||
@@ -186,8 +199,7 @@ Future<void> showAcceptJobsPopup(BuildContext context, List<Job> jobs, Function(
|
|||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Row(children: [
|
Row(children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: getDefaultButton(!job.global ? 'Ablehnen' : 'Ignorieren',
|
child: getDefaultButton(!job.global ? 'Ablehnen' : 'Ignorieren', () {
|
||||||
() {
|
|
||||||
_sendAnswer(job, !job.global ? 2 : 3);
|
_sendAnswer(job, !job.global ? 2 : 3);
|
||||||
|
|
||||||
jobs.removeWhere((value) => value.id == job.id);
|
jobs.removeWhere((value) => value.id == job.id);
|
||||||
@@ -197,7 +209,7 @@ Future<void> showAcceptJobsPopup(BuildContext context, List<Job> jobs, Function(
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 20),
|
const SizedBox(width: 20),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: getDefaultButton('Annehmen', enabledTimerActive: job.global == false && job.enableDelay > 0, enabledTimerDelay: job.enableDelay, () {
|
child: getDefaultButton('Annehmen', enabledTimerActive: enableDelay > 0, enabledTimerDelay: enableDelay, () {
|
||||||
_sendAnswer(job, 1);
|
_sendAnswer(job, 1);
|
||||||
|
|
||||||
jobs.removeWhere((value) => value.id == job.id);
|
jobs.removeWhere((value) => value.id == job.id);
|
||||||
@@ -213,11 +225,10 @@ Future<void> showAcceptJobsPopup(BuildContext context, List<Job> jobs, Function(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
}));
|
||||||
)),
|
}
|
||||||
);
|
|
||||||
})));
|
return widgets;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_sendAnswer(Job job, int item) async {
|
_sendAnswer(Job job, int item) async {
|
||||||
@@ -234,9 +245,10 @@ _sendAnswer(Job job, int item) async {
|
|||||||
message.track.pos!.long = currentPosition != null ? currentPosition.longitude : 0.0;
|
message.track.pos!.long = currentPosition != null ? currentPosition.longitude : 0.0;
|
||||||
message.track.pos!.acc = currentPosition != null ? currentPosition.accuracy.toInt() : 0;
|
message.track.pos!.acc = currentPosition != null ? currentPosition.accuracy.toInt() : 0;
|
||||||
|
|
||||||
MessageService().publish<PublishPayloadMessage>(Constants.messageTopicPublishPayload, arguments: PublishPayloadMessage(topic: "reaction", message: message.toJson(), qos: MqttQos.exactlyOnce));
|
MessageService().publish<PublishPayloadMessage>(Constants.messageTopicPublishPayload,
|
||||||
|
arguments: PublishPayloadMessage(topic: "reaction", message: message.toJson(), qos: MqttQos.exactlyOnce));
|
||||||
|
|
||||||
await MyApp.isarInstance.writeTxn(() async{
|
await MyApp.isarInstance.writeTxn(() async {
|
||||||
await MyApp.isarInstance.jobs.delete(job.id);
|
await MyApp.isarInstance.jobs.delete(job.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ import 'util.dart';
|
|||||||
|
|
||||||
enum ConnectionStateEnum { notConnected, connected }
|
enum ConnectionStateEnum { notConnected, connected }
|
||||||
|
|
||||||
//const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('app_icon');
|
|
||||||
|
|
||||||
class MqttCore {
|
class MqttCore {
|
||||||
late ConnectionStateEnum connectionState = ConnectionStateEnum.notConnected;
|
late ConnectionStateEnum connectionState = ConnectionStateEnum.notConnected;
|
||||||
|
|
||||||
@@ -81,18 +79,21 @@ class MqttCore {
|
|||||||
_processBootstrap();
|
_processBootstrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
_disconnect() {
|
_disconnectMqttClient() {
|
||||||
|
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));
|
||||||
|
|
||||||
_disconnectInProgress = true;
|
_disconnectInProgress = true;
|
||||||
|
|
||||||
_cancelReconnectTimer();
|
_cancelReconnectTimer();
|
||||||
|
|
||||||
_cancelTrackTimer();
|
_cancelTrackTimer();
|
||||||
|
|
||||||
if (_mqttClient != null) {
|
if (_mqttClient != null && _mqttClient!.connectionStatus == ConnectionStateEnum.connected) {
|
||||||
_mqttClient!.disconnect();
|
_mqttClient!.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
connectionState = ConnectionStateEnum.notConnected;
|
connectionState = ConnectionStateEnum.notConnected;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_connectToBroker() async {
|
_connectToBroker() async {
|
||||||
@@ -102,6 +103,7 @@ class MqttCore {
|
|||||||
Util.logInfo("broker uri: $_brokerUri");
|
Util.logInfo("broker uri: $_brokerUri");
|
||||||
Util.logInfo("broker port: $_brokerPort");
|
Util.logInfo("broker port: $_brokerPort");
|
||||||
|
|
||||||
|
if (_mqttClient == null) {
|
||||||
_mqttClient = MqttServerClient.withPort(_brokerUri, clientId, _brokerPort);
|
_mqttClient = MqttServerClient.withPort(_brokerUri, clientId, _brokerPort);
|
||||||
_mqttClient!.logging(on: false);
|
_mqttClient!.logging(on: false);
|
||||||
_mqttClient!.keepAlivePeriod = 60;
|
_mqttClient!.keepAlivePeriod = 60;
|
||||||
@@ -111,6 +113,7 @@ class MqttCore {
|
|||||||
_mqttClient!.onAutoReconnect = _clientDisconnected;
|
_mqttClient!.onAutoReconnect = _clientDisconnected;
|
||||||
_mqttClient!.onAutoReconnected = _clientConnected;
|
_mqttClient!.onAutoReconnected = _clientConnected;
|
||||||
_mqttClient!.connectionMessage = MqttConnectMessage().withClientIdentifier(await Util.getAppUuid()).authenticateAs("app", "apppwd");
|
_mqttClient!.connectionMessage = MqttConnectMessage().withClientIdentifier(await Util.getAppUuid()).authenticateAs("app", "apppwd");
|
||||||
|
}
|
||||||
|
|
||||||
await _mqttClient!.connect();
|
await _mqttClient!.connect();
|
||||||
|
|
||||||
@@ -384,17 +387,19 @@ class MqttCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _cancelReconnectTimer() {
|
void _cancelReconnectTimer() {
|
||||||
|
if (!_disconnectInProgress) {
|
||||||
if (_reconnectTimer != null && _reconnectTimer!.isActive) {
|
if (_reconnectTimer != null && _reconnectTimer!.isActive) {
|
||||||
_reconnectTimer!.cancel();
|
_reconnectTimer!.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _clientDisconnected() {
|
void _clientDisconnected() {
|
||||||
Util.logInfo("_clientDisconnected called");
|
Util.logInfo("_clientDisconnected called");
|
||||||
|
|
||||||
connectionState = ConnectionStateEnum.notConnected;
|
connectionState = ConnectionStateEnum.notConnected;
|
||||||
|
|
||||||
_startTrackTimer();
|
_cancelTrackTimer();
|
||||||
|
|
||||||
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));
|
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));
|
||||||
}
|
}
|
||||||
@@ -546,7 +551,7 @@ class MqttCore {
|
|||||||
|
|
||||||
MessageService().subscribe<DisconnectClientMessage>(Constants.messageTopicDisconnectClient, this,
|
MessageService().subscribe<DisconnectClientMessage>(Constants.messageTopicDisconnectClient, this,
|
||||||
(DisconnectClientMessage disconnectClientMessage) {
|
(DisconnectClientMessage disconnectClientMessage) {
|
||||||
_disconnect();
|
_disconnectMqttClient();
|
||||||
});
|
});
|
||||||
|
|
||||||
MessageService().subscribe<ConnectClientMessage>(Constants.messageTopicConnectClient, this, (ConnectClientMessage connectClientMessage) {
|
MessageService().subscribe<ConnectClientMessage>(Constants.messageTopicConnectClient, this, (ConnectClientMessage connectClientMessage) {
|
||||||
|
|||||||
+15
-2
@@ -220,8 +220,8 @@ class Util {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getDefaultButton(String text, Function() onPressed, {Image? image, double? buttonHeight, bool enabledTimerActive = true, int enabledTimerDelay = 0}) {
|
Widget getDefaultButton(String text, Function() onPressed, {Image? image, double? buttonHeight, bool enabledTimerActive = false, int enabledTimerDelay = 0}) {
|
||||||
bool enabledState = enabledTimerActive;
|
bool enabledState = !enabledTimerActive;
|
||||||
|
|
||||||
return StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
return StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||||
if (!enabledState) {
|
if (!enabledState) {
|
||||||
@@ -411,6 +411,19 @@ Future<void> showAlertDialog(BuildContext context, String title, String message)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> showMessageDialog(BuildContext context, String title, String message) async {
|
||||||
|
await showDialog(
|
||||||
|
barrierDismissible: false,
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(title),
|
||||||
|
content: Text(message),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
class DecimalTextInputFormatter extends TextInputFormatter {
|
class DecimalTextInputFormatter extends TextInputFormatter {
|
||||||
int maxLength;
|
int maxLength;
|
||||||
|
|
||||||
|
|||||||
+26
-2
@@ -209,6 +209,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.0"
|
version: "1.3.0"
|
||||||
|
charcode:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: charcode
|
||||||
|
sha256: fb98c0f6d12c920a02ee2d998da788bca066ca5f148492b7085ee23372b12306
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "1.3.1"
|
||||||
checked_yaml:
|
checked_yaml:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -972,10 +980,10 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: mqtt_client
|
name: mqtt_client
|
||||||
sha256: ba10ec490ded55dc4e77bbc992529d823fb15d0d5ec68c2895f960312060c541
|
sha256: "001861aba553eaf419aab60b7956227af47a9d1e1efe0d2fcb3957d3fc30d110"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "9.8.1"
|
version: "10.2.1"
|
||||||
open_filex:
|
open_filex:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@@ -1429,6 +1437,22 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.3.1"
|
version: "0.3.1"
|
||||||
|
universal_html:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: universal_html
|
||||||
|
sha256: "56536254004e24d9d8cfdb7dbbf09b74cf8df96729f38a2f5c238163e3d58971"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.4"
|
||||||
|
universal_io:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: universal_io
|
||||||
|
sha256: "1722b2dcc462b4b2f3ee7d188dad008b6eb4c40bbd03a3de451d82c78bba9aad"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.2"
|
||||||
url_launcher:
|
url_launcher:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|||||||
+2
-2
@@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
|
|||||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
|
||||||
# In Windows, build-name is used as the major, minor, and patch parts
|
# In Windows, build-name is used as the major, minor, and patch parts
|
||||||
# of the product and file versions while build-number is used as the build suffix.
|
# of the product and file versions while build-number is used as the build suffix.
|
||||||
version: 317.0.0+317
|
version: 319.0.0+319
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: '>=2.19.6 <3.0.0'
|
sdk: '>=2.19.6 <3.0.0'
|
||||||
@@ -43,7 +43,7 @@ dependencies:
|
|||||||
open_filex: ^4.3.2
|
open_filex: ^4.3.2
|
||||||
path_provider: ^2.0.14
|
path_provider: ^2.0.14
|
||||||
split_view: ^3.2.1
|
split_view: ^3.2.1
|
||||||
mqtt_client: ^9.8.1
|
mqtt_client: ^10.2.1
|
||||||
isar_flutter_libs: ^3.1.0+1
|
isar_flutter_libs: ^3.1.0+1
|
||||||
isar: ^3.1.0+1
|
isar: ^3.1.0+1
|
||||||
json_serializable: ^6.6.2
|
json_serializable: ^6.6.2
|
||||||
|
|||||||
Reference in new issue
Block a user