mirror of
https://github.com/immich-app/immich
synced 2026-08-22 13:13:05 +00:00
* feat: actions undo handling # Conflicts: # mobile/lib/main.dart * address pr reviews --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
37 lines
892 B
Dart
37 lines
892 B
Dart
import 'dart:async';
|
|
|
|
import 'package:immich_ui/immich_ui.dart';
|
|
|
|
class ToastOption {
|
|
final Duration? timeout;
|
|
final FutureOr<void> Function()? onUndo;
|
|
|
|
const ToastOption({this.timeout, this.onUndo});
|
|
}
|
|
|
|
class ToastService {
|
|
const ToastService();
|
|
|
|
FutureOr<void> success(String message, {ToastOption? toast}) {
|
|
snackbar.success(message, duration: toast?.timeout, action: toast?.action);
|
|
}
|
|
|
|
FutureOr<void> info(String message, {ToastOption? toast}) {
|
|
snackbar.info(message, duration: toast?.timeout, action: toast?.action);
|
|
}
|
|
|
|
FutureOr<void> error(String message, {ToastOption? toast}) {
|
|
snackbar.error(message, duration: toast?.timeout, action: toast?.action);
|
|
}
|
|
}
|
|
|
|
extension on ToastOption {
|
|
SnackbarAction? get action {
|
|
final onUndo = this.onUndo;
|
|
if (onUndo == null) {
|
|
return null;
|
|
}
|
|
|
|
return SnackbarAction(onPressed: onUndo);
|
|
}
|
|
}
|