refactor(legacy): replace showTopSnackbar with feedback dialogs
This commit is contained in:
@@ -27,11 +27,7 @@ class ControlPanelScreen extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
(_, hasError) {
|
(_, hasError) {
|
||||||
if (hasError) {
|
if (hasError) {
|
||||||
showTopSnackbar(
|
showErrorDialog(context, I18n.errorPositions);
|
||||||
context,
|
|
||||||
message: context.translate(I18n.errorPositions),
|
|
||||||
type: MessageType.error,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -257,13 +253,14 @@ class _MapSection extends ConsumerWidget {
|
|||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
try {
|
try {
|
||||||
await vm.refreshPositions();
|
await vm.refreshPositions();
|
||||||
|
if (!context.mounted) return;
|
||||||
|
await showSuccessDialog(
|
||||||
|
context,
|
||||||
|
I18n.positionUpdated,
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
showTopSnackbar(
|
await showErrorDialog(context, I18n.errorPositions);
|
||||||
context,
|
|
||||||
message: formatErrorMessage(e),
|
|
||||||
type: MessageType.error,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
|
|||||||
@@ -1,41 +1,25 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:design_system/design_system.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
import 'package:sf_localizations/sf_localizations.dart';
|
import 'package:sf_localizations/sf_localizations.dart';
|
||||||
import 'package:sf_shared/sf_shared.dart';
|
import 'package:sf_shared/sf_shared.dart';
|
||||||
|
|
||||||
const _deviceConnectionTtl = Duration(seconds: 30);
|
const _deviceConnectionTtl = Duration(seconds: 30);
|
||||||
const _snackbarDelay = Duration(milliseconds: 400);
|
|
||||||
|
|
||||||
Future<bool> guardDeviceCommand(BuildContext context, WidgetRef ref) async {
|
Future<bool> guardDeviceCommand(BuildContext context, WidgetRef ref) async {
|
||||||
final notifier = ref.read(legacyDevicesProvider.notifier);
|
final notifier = ref.read(legacyDevicesProvider.notifier);
|
||||||
|
|
||||||
if (notifier.isStale(_deviceConnectionTtl)) {
|
if (notifier.isStale(_deviceConnectionTtl)) {
|
||||||
final fetchFuture = notifier.refreshIfStale(_deviceConnectionTtl);
|
showInfoDialog(context, I18n.checkingDeviceConnection);
|
||||||
final delayedSnackbar = Timer(_snackbarDelay, () {
|
await notifier.refreshIfStale(_deviceConnectionTtl);
|
||||||
if (!context.mounted) return;
|
|
||||||
showTopSnackbar(
|
|
||||||
context,
|
|
||||||
message: context.translate(I18n.checkingDeviceConnection),
|
|
||||||
type: MessageType.info,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
await fetchFuture;
|
|
||||||
delayedSnackbar.cancel();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!context.mounted) return false;
|
if (!context.mounted) return false;
|
||||||
|
|
||||||
final device = await ref.read(selectedDeviceProvider.future);
|
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;
|
if (!context.mounted) return false;
|
||||||
showTopSnackbar(
|
await showErrorDialog(context, I18n.errorDeviceDisconnected);
|
||||||
context,
|
|
||||||
message: context.translate(I18n.errorDeviceDisconnected),
|
|
||||||
type: MessageType.error,
|
|
||||||
);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user