Erweiterungen

This commit is contained in:
Sven committed 2024-02-03 11:25:46 +01:00
1 parent 70fb6dd5ef
commit 70a8c04516
3 files changed
+46 -17

No files matched your search

+28 -14
View File
@@ -122,7 +122,7 @@ class Main extends StatefulWidget {
State<Main> createState() => _MainState(); State<Main> createState() => _MainState();
} }
class _MainState extends State<Main> { class _MainState extends State<Main> with SingleTickerProviderStateMixin {
late ContentViewWidget _currentContent; late ContentViewWidget _currentContent;
late WidgetStack<ContentViewWidget> contentStack = WidgetStack(); late WidgetStack<ContentViewWidget> contentStack = WidgetStack();
@@ -141,10 +141,17 @@ class _MainState extends State<Main> {
final ValueNotifier<bool> _connectionLostValueNotifier = ValueNotifier<bool>(true); final ValueNotifier<bool> _connectionLostValueNotifier = ValueNotifier<bool>(true);
late AnimationController _animationController;
late Animation<double> _animation;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_animationController = AnimationController(vsync: this, duration: const Duration(milliseconds: 1000));
_animationController.repeat(reverse: true);
_animation = Tween<double>(begin: 0.5, end: 1.0).animate(_animationController);
WidgetsBinding.instance.addPostFrameCallback((_) async { WidgetsBinding.instance.addPostFrameCallback((_) async {
_initMessages(); _initMessages();
@@ -269,26 +276,33 @@ class _MainState extends State<Main> {
builder: (context, value, child) { builder: (context, value, child) {
return Visibility( return Visibility(
visible: value, visible: value,
child: Container( child: Column(
width: MediaQuery.of(context).size.width, children: [
height: 30, const SizedBox(height: 1),
color: Colors.red, Container(
child: const Center( width: MediaQuery.of(context).size.width,
child: Text( height: 40,
"*** OFFLINE ***", color: Constants.colorPrimary,
style: TextStyle( child: Center(
color: Colors.white, child: FadeTransition(
fontSize: 15.0, opacity: _animation,
), child: const Text(
"*** OFFLINE ***",
style: TextStyle(
color: Colors.white,
fontSize: 25.0,
),
),
)),
), ),
), ],
), ),
); );
}, },
), ),
Expanded(child: _currentContent), Expanded(child: _currentContent),
], ],
), // This trailing comma makes auto-formatting nicer for build methods. ),
), ),
), ),
); );
+5 -3
View File
@@ -1,12 +1,15 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:kumi_popup_window/kumi_popup_window.dart'; import 'package:kumi_popup_window/kumi_popup_window.dart';
import 'package:stadtbote/main.dart';
import 'package:stadtbote/model/status.dart'; import 'package:stadtbote/model/status.dart';
import 'package:stadtbote/tools/mqtt_core.dart';
import 'package:stadtbote/tools/util.dart'; import 'package:stadtbote/tools/util.dart';
void showInfosPopup(BuildContext context, Status? status) { void showInfosPopup(BuildContext context, Status? status) {
var text = "Versionsnummer: a203\n"; var text = "Versionsnummer: a203\n";
text += "Verbindungsstatus: Unbekannt\n"; text += "Verbindungsstatus: ${MqttCore.instance.connectionState == ConnectionStateEnum.connected ? "Verbunden" : "NICHT verbunden"}\n";
text += "GPS-Status: Unbekannt\n"; text += "GPS-Status: ${MyApp.currentPosition != null ? "Position gefunden" : "Position NICHT gefunden"}\n";
text += "Version GPS: ${MyApp.currentPosition != null ? MyApp.currentPosition!.timestamp.toString() : "Unbekannt"}\n";
text += "\n"; text += "\n";
text += "User Status:\n"; text += "User Status:\n";
if (status != null) { if (status != null) {
@@ -16,7 +19,6 @@ void showInfosPopup(BuildContext context, Status? status) {
text += "vht_id: ${status.vhtId}\n"; text += "vht_id: ${status.vhtId}\n";
text += "server_version: ${status.serverVersion}\n"; text += "server_version: ${status.serverVersion}\n";
text += "server_instance: ${status.serverInstance}\n"; text += "server_instance: ${status.serverInstance}\n";
text += "Version GPS: Unbekannt";
} else { } else {
text += "Keine Informationen gefunden"; text += "Keine Informationen gefunden";
} }
+13
View File
@@ -30,9 +30,16 @@ import '../model/status.dart';
import 'constants.dart'; import 'constants.dart';
import 'util.dart'; import 'util.dart';
enum ConnectionStateEnum {
not_connected,
connected
}
class MqttCore { class MqttCore {
static late MqttCore instance; static late MqttCore instance;
late ConnectionStateEnum connectionState = ConnectionStateEnum.not_connected;
late String _brokerUri; late String _brokerUri;
late int _brokerPort; late int _brokerPort;
late String _fromServerTopic; late String _fromServerTopic;
@@ -191,6 +198,8 @@ class MqttCore {
} }
void _sessionMessageReceived(payloadData) async { void _sessionMessageReceived(payloadData) async {
connectionState = ConnectionStateEnum.connected;
await _sendSyncMessage(); await _sendSyncMessage();
var statusMessage = Status.fromJson(payloadData['status']); var statusMessage = Status.fromJson(payloadData['status']);
@@ -265,6 +274,8 @@ class MqttCore {
} }
void _startReconnectTimer() { void _startReconnectTimer() {
connectionState = ConnectionStateEnum.not_connected;
Util.logInfo("_startReconnectTimer called"); Util.logInfo("_startReconnectTimer called");
_reconnectDelay = min(_reconnectDelay + 1, 30); _reconnectDelay = min(_reconnectDelay + 1, 30);
@@ -275,6 +286,8 @@ class MqttCore {
} }
void _clientDisconnected() { void _clientDisconnected() {
connectionState = ConnectionStateEnum.not_connected;
Util.logInfo("_clientDisconnected called"); Util.logInfo("_clientDisconnected called");
BroadcastReceiver().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected)); BroadcastReceiver().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));