Erweiterungen
This commit is contained in:
1 parent
3c2e9ceecb
commit
85d6d49258
16 files changed
+98
-77
No files matched your search
+13
-11
@@ -144,7 +144,7 @@ class MqttCore {
|
||||
_mqttClient.updates?.listen((List<MqttReceivedMessage<MqttMessage>> c) {
|
||||
try {
|
||||
final MqttPublishMessage message = c[0].payload as MqttPublishMessage;
|
||||
final payload = MqttPublishPayload.bytesToStringAsString(message.payload.message);
|
||||
String payload = utf8.decode(MqttPublishPayload.bytesToStringAsString(message.payload.message).codeUnits);
|
||||
var topic = message.variableHeader?.topicName;
|
||||
|
||||
Util.logInfo('message received');
|
||||
@@ -238,6 +238,14 @@ class MqttCore {
|
||||
MyApp.isarInstance.jobs.putSync(newJob);
|
||||
});
|
||||
|
||||
if (newJob.state == 0) {
|
||||
if (newJob.global) {
|
||||
await Util.playMp3('aaa.mp3');
|
||||
} else {
|
||||
await Util.playMp3('job_received.mp3');
|
||||
}
|
||||
}
|
||||
|
||||
MessageService().publish<JobReceivedMessage>(Constants.messageTopicJobReceived, arguments: JobReceivedMessage(job: newJob));
|
||||
}
|
||||
}
|
||||
@@ -259,15 +267,7 @@ class MqttCore {
|
||||
void _syncRequestReceived(payloadData) async {
|
||||
Util.logInfo('_syncRequestReceived');
|
||||
|
||||
/*for (var foundJobData in payloadData) {
|
||||
Job newJob = Job.fromJson(foundJobData);
|
||||
|
||||
await MyApp.isarInstance.writeTxn(() async {
|
||||
await MyApp.isarInstance.jobs.put(newJob);
|
||||
});
|
||||
|
||||
BroadcastReceiver().publish<JobReceivedMessage>(Constants.messageTopicJobReceived, arguments: JobReceivedMessage(job: newJob));
|
||||
}*/
|
||||
_sendSyncMessage();
|
||||
}
|
||||
|
||||
void _messageMessageReceived(Map<String, dynamic> payloadData) async {
|
||||
@@ -277,6 +277,8 @@ class MqttCore {
|
||||
await MyApp.isarInstance.messages.put(newMessage);
|
||||
});
|
||||
|
||||
await Util.playMp3('asbeep.mp3');
|
||||
|
||||
MessageService().publish<MessageReceivedMessage>(Constants.messageTopicMessageReceived, arguments: MessageReceivedMessage(message: newMessage));
|
||||
}
|
||||
|
||||
@@ -400,7 +402,7 @@ class MqttCore {
|
||||
}
|
||||
|
||||
void _cancelTrackTimer() {
|
||||
if (_trackTimer != null) {
|
||||
if (_trackTimer != null && _trackTimer!.isActive) {
|
||||
_trackTimer!.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
+7
-37
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -181,45 +182,14 @@ class Util {
|
||||
throw Exception('Could not launch $websiteUrl');
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> playMp3(String name) async {
|
||||
final player = AudioPlayer();
|
||||
await player.play(AssetSource('sounds/$name'), volume: 1);
|
||||
}
|
||||
}
|
||||
|
||||
Widget getDefaultButton(String text, Function() onPressed, {Image? image, double? buttonHeight}) {
|
||||
/*return SizedBox(
|
||||
height: buttonHeight ?? 60,
|
||||
child: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(0),
|
||||
child: Expanded(
|
||||
child: SizedBox(
|
||||
height: 60,
|
||||
child: ElevatedButton(
|
||||
style: ButtonStyle(
|
||||
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
|
||||
RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
side: const BorderSide(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
backgroundColor: MaterialStateProperty.all<Color>(const Color.fromARGB(255, 220, 220, 220)),
|
||||
foregroundColor: MaterialStateProperty.all<Color>(Colors.black),
|
||||
),
|
||||
onPressed: () {
|
||||
onPressed();
|
||||
},
|
||||
child: Text(text)),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Positioned(left: 20, top: 15, child: Center(child: image))
|
||||
],
|
||||
),
|
||||
);*/
|
||||
return SizedBox(
|
||||
height: buttonHeight ?? 50,
|
||||
child: MaterialButton(
|
||||
@@ -244,7 +214,7 @@ Widget getDefaultButton(String text, Function() onPressed, {Image? image, double
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(color: Colors.black, fontSize: 18.0),
|
||||
style: const TextStyle(color: Colors.black, fontSize: 14.0),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user