1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-26 10:50:29 +02:00
immich/mobile/lib/extensions/asyncvalue_extensions.dart
shenlong 983473261b
refactor(mobile): riverpod codegen + riverpod lint (#4836)
* build(mobile): add riverpod_lint

* refactor(mobile): riverpod_generator for providers

* test(mobile): fix integration test helper

* refactor: ApiService to riverpod codegen

* refactor(mobile): return curatedcontent instead of people dto

* refactor: person provider to asyncnotifier

* mobile: update service providers to use lambda

* mobile: update scaffoldbody default error icon

* remove logger mixin

---------

Co-authored-by: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
2023-11-19 10:04:44 -06:00

28 lines
800 B
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 ScaffoldBody<T> on AsyncValue<T> {
static final Logger _scaffoldBodyLog = Logger("ScaffoldBody");
Widget scaffoldBodyWhen({
required Widget Function(T data) onData,
Widget? onError,
}) {
if (isLoading) {
return const Center(
child: ImmichLoadingIndicator(),
);
}
if (hasError && !hasValue) {
_scaffoldBodyLog.severe("Error occured in AsyncValue", error, stackTrace);
return onError ?? const ScaffoldErrorBody();
}
return onData(requireValue);
}
}