Erweiterungen
This commit is contained in:
1 parent
fbdd2a4338
commit
41d086e13e
7 files changed
+244
-185
No files matched your search
+22
-17
@@ -52,8 +52,6 @@ import 'util.dart';
|
||||
|
||||
enum ConnectionStateEnum { notConnected, connected }
|
||||
|
||||
//const AndroidInitializationSettings initializationSettingsAndroid = AndroidInitializationSettings('app_icon');
|
||||
|
||||
class MqttCore {
|
||||
late ConnectionStateEnum connectionState = ConnectionStateEnum.notConnected;
|
||||
|
||||
@@ -81,18 +79,21 @@ class MqttCore {
|
||||
_processBootstrap();
|
||||
}
|
||||
|
||||
_disconnect() {
|
||||
_disconnectMqttClient() {
|
||||
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));
|
||||
|
||||
_disconnectInProgress = true;
|
||||
|
||||
_cancelReconnectTimer();
|
||||
|
||||
_cancelTrackTimer();
|
||||
|
||||
if (_mqttClient != null) {
|
||||
if (_mqttClient != null && _mqttClient!.connectionStatus == ConnectionStateEnum.connected) {
|
||||
_mqttClient!.disconnect();
|
||||
}
|
||||
|
||||
connectionState = ConnectionStateEnum.notConnected;
|
||||
|
||||
}
|
||||
|
||||
_connectToBroker() async {
|
||||
@@ -102,15 +103,17 @@ class MqttCore {
|
||||
Util.logInfo("broker uri: $_brokerUri");
|
||||
Util.logInfo("broker port: $_brokerPort");
|
||||
|
||||
_mqttClient = MqttServerClient.withPort(_brokerUri, clientId, _brokerPort);
|
||||
_mqttClient!.logging(on: false);
|
||||
_mqttClient!.keepAlivePeriod = 60;
|
||||
_mqttClient!.disconnectOnNoResponsePeriod = 10;
|
||||
_mqttClient!.autoReconnect = true;
|
||||
_mqttClient!.onDisconnected = _clientDisconnected;
|
||||
_mqttClient!.onAutoReconnect = _clientDisconnected;
|
||||
_mqttClient!.onAutoReconnected = _clientConnected;
|
||||
_mqttClient!.connectionMessage = MqttConnectMessage().withClientIdentifier(await Util.getAppUuid()).authenticateAs("app", "apppwd");
|
||||
if (_mqttClient == null) {
|
||||
_mqttClient = MqttServerClient.withPort(_brokerUri, clientId, _brokerPort);
|
||||
_mqttClient!.logging(on: false);
|
||||
_mqttClient!.keepAlivePeriod = 60;
|
||||
_mqttClient!.disconnectOnNoResponsePeriod = 10;
|
||||
_mqttClient!.autoReconnect = true;
|
||||
_mqttClient!.onDisconnected = _clientDisconnected;
|
||||
_mqttClient!.onAutoReconnect = _clientDisconnected;
|
||||
_mqttClient!.onAutoReconnected = _clientConnected;
|
||||
_mqttClient!.connectionMessage = MqttConnectMessage().withClientIdentifier(await Util.getAppUuid()).authenticateAs("app", "apppwd");
|
||||
}
|
||||
|
||||
await _mqttClient!.connect();
|
||||
|
||||
@@ -384,8 +387,10 @@ class MqttCore {
|
||||
}
|
||||
|
||||
void _cancelReconnectTimer() {
|
||||
if (_reconnectTimer != null && _reconnectTimer!.isActive) {
|
||||
_reconnectTimer!.cancel();
|
||||
if (!_disconnectInProgress) {
|
||||
if (_reconnectTimer != null && _reconnectTimer!.isActive) {
|
||||
_reconnectTimer!.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,7 +399,7 @@ class MqttCore {
|
||||
|
||||
connectionState = ConnectionStateEnum.notConnected;
|
||||
|
||||
_startTrackTimer();
|
||||
_cancelTrackTimer();
|
||||
|
||||
MessageService().publish<ConnectionStatus>(Constants.messageTopicConnectionStatusChanged, arguments: ConnectionStatus(status: ConnectionStatusEnum.notConnected));
|
||||
}
|
||||
@@ -546,7 +551,7 @@ class MqttCore {
|
||||
|
||||
MessageService().subscribe<DisconnectClientMessage>(Constants.messageTopicDisconnectClient, this,
|
||||
(DisconnectClientMessage disconnectClientMessage) {
|
||||
_disconnect();
|
||||
_disconnectMqttClient();
|
||||
});
|
||||
|
||||
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}) {
|
||||
bool enabledState = enabledTimerActive;
|
||||
Widget getDefaultButton(String text, Function() onPressed, {Image? image, double? buttonHeight, bool enabledTimerActive = false, int enabledTimerDelay = 0}) {
|
||||
bool enabledState = !enabledTimerActive;
|
||||
|
||||
return StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
|
||||
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 {
|
||||
int maxLength;
|
||||
|
||||
|
||||
Reference in new issue
Block a user