mirror of
https://github.com/immich-app/immich.git
synced 2024-12-23 02:06:15 +02:00
513f252a0c
* refactor: scaffoldwhen to log errors during scaffold body render * refactor: onError and onLoading scaffoldbody * refactor: more scaffold body to custom extension * refactor: add skiploadingonrefresh * Snackbar color --------- Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
38 lines
1.1 KiB
Dart
38 lines
1.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/shared/ui/immich_loading_indicator.dart';
|
|
import 'package:immich_mobile/shared/ui/scaffold_error_body.dart';
|
|
import 'package:logging/logging.dart';
|
|
|
|
extension LogOnError<T> on AsyncValue<T> {
|
|
static final Logger _asyncErrorLogger = Logger("AsyncValue");
|
|
|
|
Widget widgetWhen({
|
|
bool skipLoadingOnRefresh = true,
|
|
Widget Function()? onLoading,
|
|
Widget Function(Object? error, StackTrace? stack)? onError,
|
|
required Widget Function(T data) onData,
|
|
}) {
|
|
if (isLoading) {
|
|
bool skip = false;
|
|
if (isRefreshing) {
|
|
skip = skipLoadingOnRefresh;
|
|
}
|
|
|
|
if (!skip) {
|
|
return onLoading?.call() ??
|
|
const Center(
|
|
child: ImmichLoadingIndicator(),
|
|
);
|
|
}
|
|
}
|
|
|
|
if (hasError && !hasValue) {
|
|
_asyncErrorLogger.severe("Error occured", error, stackTrace);
|
|
return onError?.call(error, stackTrace) ?? const ScaffoldErrorBody();
|
|
}
|
|
|
|
return onData(requireValue);
|
|
}
|
|
}
|