Frontend first draft
This commit is contained in:
38
frontend/pweb/lib/utils/notify.dart
Normal file
38
frontend/pweb/lib/utils/notify.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:pweb/generated/i18n/app_localizations.dart';
|
||||
import 'package:pweb/utils/snackbar.dart';
|
||||
import 'package:pweb/widgets/error/snackbar.dart';
|
||||
|
||||
|
||||
Future<void> invokeAndNotify<T>(
|
||||
BuildContext context, {
|
||||
required Future<T> Function() operation,
|
||||
String? operationSuccess,
|
||||
String? operationError,
|
||||
void Function(Object)? onError,
|
||||
void Function(T)? onSuccess,
|
||||
}) async {
|
||||
final sm = ScaffoldMessenger.of(context);
|
||||
final locs = AppLocalizations.of(context)!;
|
||||
try {
|
||||
final res = await operation();
|
||||
if (operationSuccess != null) {
|
||||
notifyUserX(sm, operationSuccess);
|
||||
}
|
||||
if (onSuccess != null) {
|
||||
onSuccess(res);
|
||||
}
|
||||
} catch (e) {
|
||||
notifyUserOfErrorX(
|
||||
scaffoldMessenger: sm,
|
||||
errorSituation: operationError ?? locs.errorInternalError,
|
||||
exception: e,
|
||||
appLocalizations: locs,
|
||||
);
|
||||
if (onError != null) {
|
||||
onError(e);
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user