From c034d781afd2a0baae778e60e4b5ecd7172e9640 Mon Sep 17 00:00:00 2001 From: JulianAlcala Date: Sun, 26 Apr 2026 05:27:17 +0200 Subject: [PATCH] refactor(legacy): replace showTopSnackbar with feedback dialogs --- .../presentation/control_panel_screen.dart | 17 +++++------- .../lib/src/utils/device_command_guard.dart | 26 ++++--------------- 2 files changed, 12 insertions(+), 31 deletions(-) diff --git a/modules/legacy/modules/control_panel/lib/src/features/control_panel/presentation/control_panel_screen.dart b/modules/legacy/modules/control_panel/lib/src/features/control_panel/presentation/control_panel_screen.dart index 6f40f9c9..c9824db2 100644 --- a/modules/legacy/modules/control_panel/lib/src/features/control_panel/presentation/control_panel_screen.dart +++ b/modules/legacy/modules/control_panel/lib/src/features/control_panel/presentation/control_panel_screen.dart @@ -27,11 +27,7 @@ class ControlPanelScreen extends ConsumerWidget { ), (_, hasError) { if (hasError) { - showTopSnackbar( - context, - message: context.translate(I18n.errorPositions), - type: MessageType.error, - ); + showErrorDialog(context, I18n.errorPositions); } }, ); @@ -257,13 +253,14 @@ class _MapSection extends ConsumerWidget { onPressed: () async { try { await vm.refreshPositions(); + if (!context.mounted) return; + await showSuccessDialog( + context, + I18n.positionUpdated, + ); } catch (e) { if (!context.mounted) return; - showTopSnackbar( - context, - message: formatErrorMessage(e), - type: MessageType.error, - ); + await showErrorDialog(context, I18n.errorPositions); } }, icon: Icon( diff --git a/modules/legacy/packages/legacy_device_state/lib/src/utils/device_command_guard.dart b/modules/legacy/packages/legacy_device_state/lib/src/utils/device_command_guard.dart index 9c73fb4f..188d1c53 100644 --- a/modules/legacy/packages/legacy_device_state/lib/src/utils/device_command_guard.dart +++ b/modules/legacy/packages/legacy_device_state/lib/src/utils/device_command_guard.dart @@ -1,41 +1,25 @@ -import 'dart:async'; - -import 'package:design_system/design_system.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:sf_localizations/sf_localizations.dart'; import 'package:sf_shared/sf_shared.dart'; const _deviceConnectionTtl = Duration(seconds: 30); -const _snackbarDelay = Duration(milliseconds: 400); Future guardDeviceCommand(BuildContext context, WidgetRef ref) async { final notifier = ref.read(legacyDevicesProvider.notifier); if (notifier.isStale(_deviceConnectionTtl)) { - final fetchFuture = notifier.refreshIfStale(_deviceConnectionTtl); - final delayedSnackbar = Timer(_snackbarDelay, () { - if (!context.mounted) return; - showTopSnackbar( - context, - message: context.translate(I18n.checkingDeviceConnection), - type: MessageType.info, - ); - }); - await fetchFuture; - delayedSnackbar.cancel(); + showInfoDialog(context, I18n.checkingDeviceConnection); + await notifier.refreshIfStale(_deviceConnectionTtl); } if (!context.mounted) return false; final device = await ref.read(selectedDeviceProvider.future); - if (device == null || device.isDisconnected) { + if (device == null) return false; + if (!device.queueCommands && device.isDisconnected) { if (!context.mounted) return false; - showTopSnackbar( - context, - message: context.translate(I18n.errorDeviceDisconnected), - type: MessageType.error, - ); + await showErrorDialog(context, I18n.errorDeviceDisconnected); return false; } return true;