refactor(legacy): replace showTopSnackbar with feedback dialogs

This commit is contained in:
2026-04-26 05:27:17 +02:00
parent 5bebe110fc
commit c034d781af
2 changed files with 12 additions and 31 deletions

View File

@@ -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(

View File

@@ -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<bool> 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;