simplified code across the app and consolidated duplicated helpers
This commit is contained in:
@@ -8,6 +8,11 @@ typedef AsyncErrorBuilder = String Function(Object error);
|
||||
TextStyle _asyncErrorTextStyle(BuildContext context) =>
|
||||
TextStyle(color: Theme.of(context).colorScheme.error, fontSize: 13);
|
||||
|
||||
Widget _leadingLabel(Widget leading, Widget label) => Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [leading, const SizedBox(width: 8), label],
|
||||
);
|
||||
|
||||
/// Wraps [action] with a try/catch that pops up an [InfoDialog] on failure
|
||||
/// (using [errorBuilder] or the default error mapper). Returns `true` on
|
||||
/// success, `false` on caught failure.
|
||||
@@ -23,14 +28,7 @@ Future<bool> runWithErrorDialog(
|
||||
} catch (e) {
|
||||
Haptics.error();
|
||||
if (!context.mounted) return false;
|
||||
final message = errorBuilder != null
|
||||
? errorBuilder(e)
|
||||
: errorToUserMessage(e);
|
||||
final details = errorToTechnicalDetails(e);
|
||||
final body = details != null && details != message
|
||||
? '$message\n\n$details'
|
||||
: message;
|
||||
InfoDialog.show(context, body, copyable: true, title: 'Fehler');
|
||||
InfoDialog.showError(context, e, message: errorBuilder?.call(e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -55,14 +53,13 @@ class AsyncActionController extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
try {
|
||||
await action();
|
||||
_busy = false;
|
||||
notifyListeners();
|
||||
return true;
|
||||
} catch (e) {
|
||||
_busy = false;
|
||||
_error = errorBuilder != null ? errorBuilder(e) : errorToUserMessage(e);
|
||||
notifyListeners();
|
||||
return false;
|
||||
} finally {
|
||||
_busy = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user