add helper methods for commands

This commit is contained in:
Adam Velebil 2024-08-30 14:16:34 +02:00
parent 44e3bc7691
commit dd1c52fbd9
No known key found for this signature in database
GPG Key ID: C9B1E4A3CBBD2E10
2 changed files with 22 additions and 24 deletions

View File

@ -60,22 +60,18 @@ class _DialogProvider extends Notifier<int> {
processingTimer = Timer(Duration(milliseconds: timeout), () {
if (!explicitAction) {
// show the widget
notifier.sendCommand(NfcEventCommand(
event: NfcShowViewEvent(
child: NfcContentWidget(
notifier.sendCommand(showNfcView(NfcContentWidget(
title: properties.operationProcessing,
subtitle: '',
inProgress: true,
))));
)));
} else {
// the processing view will only be shown if the timer is still active
notifier.sendCommand(NfcEventCommand(
event: NfcUpdateViewEvent(
child: NfcContentWidget(
notifier.sendCommand(updateNfcView(NfcContentWidget(
title: properties.operationProcessing,
subtitle: l10n.s_nfc_hold_key,
inProgress: true,
))));
)));
}
});
break;
@ -83,30 +79,26 @@ class _DialogProvider extends Notifier<int> {
explicitAction = false; // next action might not be explicit
processingTimer?.cancel();
if (properties.showSuccess ?? false) {
notifier.sendCommand(NfcEventCommand(
event: NfcUpdateViewEvent(
child: NfcActivityClosingCountdownWidgetView(
notifier.sendCommand(
updateNfcView(NfcActivityClosingCountdownWidgetView(
closeInSec: 5,
child: NfcContentWidget(
title: properties.operationSuccess,
subtitle: l10n.s_nfc_remove_key,
inProgress: false,
),
))));
)));
} else {
// directly hide
notifier.sendCommand(
NfcEventCommand(event: const NfcHideViewEvent(timeoutMs: 0)));
notifier.sendCommand(hideNfcView);
}
break;
case NfcActivity.processingInterrupted:
explicitAction = false; // next action might not be explicit
notifier.sendCommand(NfcEventCommand(
event: NfcUpdateViewEvent(
child: NfcContentWidget(
notifier.sendCommand(updateNfcView(NfcContentWidget(
title: properties.operationFailure,
inProgress: false,
))));
)));
break;
case NfcActivity.notActive:
debugPrint('Received not handled notActive');
@ -122,19 +114,16 @@ class _DialogProvider extends Notifier<int> {
switch (call.method) {
case 'show':
explicitAction = true;
notifier.sendCommand(NfcEventCommand(
event: NfcShowViewEvent(
child: NfcContentWidget(
notifier.sendCommand(showNfcView(NfcContentWidget(
title: l10n.s_nfc_tap_for(
properties.operationName ?? '[OPERATION NAME MISSING]'),
subtitle: '',
inProgress: false,
))));
)));
break;
case 'close':
notifier.sendCommand(
NfcEventCommand(event: const NfcHideViewEvent(timeoutMs: 0)));
notifier.sendCommand(hideNfcView);
break;
default:

View File

@ -64,3 +64,12 @@ class NfcEventCommand with _$NfcEventCommand {
@Default(NfcEvent()) NfcEvent event,
}) = _NfcEventCommand;
}
final hideNfcView =
NfcEventCommand(event: const NfcHideViewEvent(timeoutMs: 0));
NfcEventCommand updateNfcView(Widget child) =>
NfcEventCommand(event: NfcUpdateViewEvent(child: child));
NfcEventCommand showNfcView(Widget child) =>
NfcEventCommand(event: NfcShowViewEvent(child: child));