Skip to content

Commit

Permalink
Use if-case to get AsyncSnapshot data
Browse files Browse the repository at this point in the history
  • Loading branch information
petlyh committed Nov 7, 2024
1 parent a1f63b7 commit 5eccb4a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions lib/screens/search/result_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ class _ResultPageContent<T extends ResultType> extends HookWidget {
: getClient().search<T>(zenEntries[index]);
},
),
if (snapshot.hasData)
..._onReponse(snapshot.requireData, key: zenIndex.value)
else if (snapshot.hasError)
if (snapshot.data case final data?)
..._onReponse(data, key: zenIndex.value)
else if (snapshot.error case final error?)
_paddedSliverAdapter(
child: ErrorIndicator(
error: snapshot.error!,
error: error,
stackTrace: snapshot.stackTrace,
onRetry: () => future.value =
getClient().search<T>(zenEntries[zenIndex.value]),
Expand Down
8 changes: 4 additions & 4 deletions lib/widgets/future_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class FutureLoader<T> extends HookWidget {

final builder = frameBuilder ?? (_, child, __) => child;

if (snapshot.hasData) {
return builder(context, handler(snapshot.data as T), snapshot.data as T);
if (snapshot.data case final data?) {
return builder(context, handler(data), data);
}

if (snapshot.hasError) {
if (snapshot.error case final error?) {
return builder(
context,
ErrorIndicator(
error: snapshot.error!,
error: error,
stackTrace: snapshot.stackTrace,
onRetry: () => future.value = onLoad(),
),
Expand Down

0 comments on commit 5eccb4a

Please sign in to comment.