diff --git a/lib/content_views/main_page.dart b/lib/content_views/main_page.dart index 57311bc..158cd0a 100644 --- a/lib/content_views/main_page.dart +++ b/lib/content_views/main_page.dart @@ -329,7 +329,7 @@ class _MainPageState extends State { showLogoutAlertDialog(BuildContext context) async { Widget yesButton = TextButton( child: const Text("Ja"), - onPressed: () { + onPressed: () async { Navigator.of(context).pop(); showMessageDialog(context, "Information", "Sie werden abgemeldet.\nBitte warten..."); @@ -338,7 +338,10 @@ class _MainPageState extends State { _loggedOut = true; + await MessageService().publish(Constants.messageTopicDisconnectClient, arguments: DisconnectClientMessage()); + Future.delayed(const Duration(seconds: 5), () async { + Navigator.of(context).pop(); setState(() {}); diff --git a/lib/main.dart b/lib/main.dart index ef4e9cb..01e5142 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -71,6 +71,8 @@ void _traceUncaughtExceptions(Object error, StackTrace stackTrace) { class MyApp extends StatefulWidget { MyApp({super.key}); + static final appNavigatorKey = GlobalKey(); + static late Isar isarInstance; static Position? currentPosition; @@ -93,6 +95,7 @@ class _MyAppState extends State { @override Widget build(BuildContext context) { return MaterialApp( + navigatorKey: MyApp.appNavigatorKey, title: 'Stadtbote', theme: ThemeData( primarySwatch: Colors.blue, diff --git a/lib/popups/accept_jobs_popup.dart b/lib/popups/accept_jobs_popup.dart index 9fe2be2..fc54e84 100644 --- a/lib/popups/accept_jobs_popup.dart +++ b/lib/popups/accept_jobs_popup.dart @@ -21,10 +21,12 @@ import '../tools/messages/publish_payload_message.dart'; late bool _initTimer; late Timer _checkForNewJobsTimer; late Map _firstDelayTimeMap; +late Map _infoExpandedMap; Future showAcceptJobsPopup(BuildContext context, SharedMapReference mapReference, Function() onFinished) async { _initTimer = true; _firstDelayTimeMap = {}; + _infoExpandedMap = {}; await showDialog( context: context, @@ -104,7 +106,7 @@ Future> _fetchJobWidgets(StateSetter dialogState, Function() onFini for (var jobEntry in entries) { var job = jobEntry.value; - int enableDelay = 3; //job.delayOrderTime; + int enableDelay = job.delayOrderTime; if (!_firstDelayTimeMap.containsKey(job.id)) { _firstDelayTimeMap[job.id] = DateTime.now(); } else { @@ -113,6 +115,17 @@ Future> _fetchJobWidgets(StateSetter dialogState, Function() onFini enableDelay = min(0, diffInSeconds); } + ExpandableController controller = ExpandableController(); + controller.expanded = _infoExpandedMap[job.id] != null ? _infoExpandedMap[job.id]! : false; + + controller.addListener(() { + if (controller.expanded) { + _infoExpandedMap[job.id] = true; + } else { + _infoExpandedMap[job.id] = false; + } + }); + widgets.add(StatefulBuilder(builder: (BuildContext context, StateSetter setState) { return ExpandableNotifier( child: ListTile( @@ -170,6 +183,7 @@ Future> _fetchJobWidgets(StateSetter dialogState, Function() onFini scrollOnExpand: true, scrollOnCollapse: false, child: ExpandablePanel( + controller: controller, theme: const ExpandableThemeData( headerAlignment: ExpandablePanelHeaderAlignment.center, tapBodyToCollapse: true, diff --git a/lib/protocoll_messages/bootstrap_response_payload.dart b/lib/protocoll_messages/bootstrap_response_payload.dart index 3cf8dba..75da072 100644 --- a/lib/protocoll_messages/bootstrap_response_payload.dart +++ b/lib/protocoll_messages/bootstrap_response_payload.dart @@ -14,6 +14,10 @@ class BootstrapResponse @JsonKey(name: "from_server") late String fromServer; + late int status; + + late String message; + BootstrapResponse(); factory BootstrapResponse.fromJson(Map json) => _$BootstrapResponseFromJson(json); diff --git a/lib/protocoll_messages/bootstrap_response_payload.g.dart b/lib/protocoll_messages/bootstrap_response_payload.g.dart index f1d0c58..c69d6d4 100644 --- a/lib/protocoll_messages/bootstrap_response_payload.g.dart +++ b/lib/protocoll_messages/bootstrap_response_payload.g.dart @@ -11,7 +11,9 @@ BootstrapResponse _$BootstrapResponseFromJson(Map json) => ..broker = json['broker'] as String ..id = json['id'] as String ..toServer = json['to_server'] as String - ..fromServer = json['from_server'] as String; + ..fromServer = json['from_server'] as String + ..status = json['status'] as int + ..message = json['message'] as String; Map _$BootstrapResponseToJson(BootstrapResponse instance) => { @@ -19,4 +21,6 @@ Map _$BootstrapResponseToJson(BootstrapResponse instance) => 'id': instance.id, 'to_server': instance.toServer, 'from_server': instance.fromServer, + 'status': instance.status, + 'message': instance.message, }; diff --git a/lib/tools/mqtt_core.dart b/lib/tools/mqtt_core.dart index 23ac324..276c335 100644 --- a/lib/tools/mqtt_core.dart +++ b/lib/tools/mqtt_core.dart @@ -4,7 +4,6 @@ import 'dart:math'; import 'package:archive/archive.dart'; import 'package:device_info_plus/device_info_plus.dart'; -import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; import 'package:isar/isar.dart'; import 'package:mqtt_client/mqtt_client.dart'; @@ -151,8 +150,12 @@ class MqttCore { return true; } catch (ex) { + Util.logInfo("send failed!"); + if (enqueueOnError) { _enqueueMessage(topic, text); + + Util.logInfo("message enqueued"); } } @@ -443,14 +446,23 @@ class MqttCore { var bootstrapResponsePayload = BootstrapResponse.fromJson(jsonDecode(responseText)); - var brokerUriAndPortArray = bootstrapResponsePayload.broker.replaceFirst("mqtt://", "").split(":"); - _brokerUri = brokerUriAndPortArray[0]; - _brokerPort = int.parse(brokerUriAndPortArray[1]); - _clientId = bootstrapResponsePayload.id; - _fromServerTopic = bootstrapResponsePayload.fromServer; - _toServerTopic = bootstrapResponsePayload.toServer; + var status = bootstrapResponsePayload.status; + var message = bootstrapResponsePayload.message; - _connectToBroker(); + if (status > 0) { + showAlertDialog(MyApp.appNavigatorKey.currentContext!, status == 1 ? "Information" : "Fehler", message); + } + + if (status < 2) { + var brokerUriAndPortArray = bootstrapResponsePayload.broker.replaceFirst("mqtt://", "").split(":"); + _brokerUri = brokerUriAndPortArray[0]; + _brokerPort = int.parse(brokerUriAndPortArray[1]); + _clientId = bootstrapResponsePayload.id; + _fromServerTopic = bootstrapResponsePayload.fromServer; + _toServerTopic = bootstrapResponsePayload.toServer; + + _connectToBroker(); + } } catch (ex) { Util.logException("bootstrap failed: {$ex}"); diff --git a/pubspec.yaml b/pubspec.yaml index d11ed67..1dddd14 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 # 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. -version: 320.0.0+320 +version: 321.0.0+321 environment: sdk: '>=2.19.6 <3.0.0'