Erweiterungen

This commit is contained in:
Sven committed 2024-08-07 10:00:59 +02:00
1 parent 7015d83fd1
commit 6981cfbf8a
4 files changed
+56 -39

No files matched your search

+50 -24
View File
@@ -18,11 +18,14 @@ import 'package:badges/badges.dart' as badges;
import '../tools/messages/publish_payload_message.dart';
Timer? _checkForNewJobsTimer;
Map<int, DateTime> _firstDelayTimeMap = {};
late bool _initTimer;
late Timer _checkForNewJobsTimer;
late Map<int, DateTime> _firstDelayTimeMap;
Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapReference, Function() onFinished) async {
_initTimer = true;
_firstDelayTimeMap = {};
await showDialog<void>(
context: context,
builder: (BuildContext context) {
@@ -41,7 +44,11 @@ Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapRef
shadowColor: Colors.transparent,
backgroundColor: Colors.white,
content: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
_startTimer(mapReference, setState);
if (_initTimer) {
_initTimer = false;
_startTimer(context, mapReference, setState, onFinished);
}
return SizedBox(
key: GlobalKey(),
@@ -51,7 +58,7 @@ Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapRef
height: 100,
padding: const EdgeInsets.all(5),
child: FutureBuilder<List<Widget>>(
future: _fetchJobWidgets(mapReference),
future: _fetchJobWidgets(setState, onFinished, mapReference),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Util.getWaitWidget(context);
@@ -67,26 +74,28 @@ Future<void> showAcceptJobsPopup(BuildContext context, SharedMapReference mapRef
});
}
void _startTimer(SharedMapReference mapReference, StateSetter setState) {
_checkForNewJobsTimer ??= Timer.periodic(const Duration(seconds: 5), (Timer t) async {
void _startTimer(BuildContext context, SharedMapReference mapReference, StateSetter setState, Function() onFinished) {
_checkForNewJobsTimer = Timer.periodic(const Duration(seconds: 5), (Timer t) async {
var jobMap = SharedMap<int, Job>.fromSharedReference(mapReference);
if (await jobMap.length() > 0) {
setState(() { });
} else {
_stopTimer();
Navigator.of(context).pop();
onFinished();
}
});
}
void _stopTimer() {
if (_checkForNewJobsTimer != null) {
_checkForNewJobsTimer!.cancel();
_checkForNewJobsTimer = null;
}
_checkForNewJobsTimer.cancel();
}
Future<List<Widget>> _fetchJobWidgets(SharedMapReference mapReference) async {
Future<List<Widget>> _fetchJobWidgets(StateSetter dialogState, Function() onFinished, SharedMapReference mapReference) async {
List<Widget> widgets = [];
var jobMap = SharedMap<int, Job>.fromSharedReference(mapReference);
@@ -198,20 +207,40 @@ Future<List<Widget>> _fetchJobWidgets(SharedMapReference mapReference) async {
Row(children: [
Expanded(
child: getDefaultButton(!job.global ? 'Ablehnen' : 'Ignorieren', () {
setState(() {
_sendAnswer(job, !job.global ? 2 : 3);
dialogState(() {
if (jobMap.length() == 1) {
_stopTimer();
}
//jobs.removeWhere((value) => value.id == job.id);
_sendAnswer(mapReference, job, !job.global ? 2 : 3);
jobMap.remove(job.id);
if (jobMap.length() == 0) {
Navigator.of(context).pop();
onFinished();
}
});
}),
),
const SizedBox(width: 20),
Expanded(
child: getDefaultButton('Annehmen', enabledTimerActive: enableDelay > 0, enabledTimerDelay: enableDelay, () {
setState(() {
_sendAnswer(job, 1);
dialogState(() {
if (jobMap.length() == 1) {
_stopTimer();
}
//jobs.removeWhere((value) => value.id == job.id);
_sendAnswer(mapReference, job, 1);
jobMap.remove(job.id);
if (jobMap.length() == 0) {
Navigator.of(context).pop();
onFinished();
}
});
}),
)
@@ -229,7 +258,7 @@ Future<List<Widget>> _fetchJobWidgets(SharedMapReference mapReference) async {
return widgets;
}
_sendAnswer(Job job, int item) async {
_sendAnswer(SharedMapReference mapReference, Job job, int item) async {
var currentPosition = MyApp.currentPosition;
var message = Reaction();
@@ -245,9 +274,6 @@ _sendAnswer(Job job, int item) async {
await MessageService().publish<PublishPayloadMessage>(Constants.messageTopicPublishPayload, arguments: PublishPayloadMessage(topic: "reaction", message: message.toJson(), qos: MqttQos.exactlyOnce));
await MyApp.isarInstance.writeTxn(() async {
await MyApp.isarInstance.jobs.delete(job.id);
});
await MessageService().publish(Constants.messageTopicUpdateBadges, arguments: RefreshBadgesMessage());
}
+1 -1
View File
@@ -18,7 +18,7 @@ showZipPopup(BuildContext context, String text, String buttonText, Function(Stri
return SizedBox(
key: GlobalKey(),
height: 280,
height: 293,
width: MediaQuery.of(context).size.width * 0.8,
child: Container(
height: 100,