Skip to content

Commit

Permalink
fix: #1697 - checking hasError instead of hasData in FutureBuilder (#…
Browse files Browse the repository at this point in the history
…1705)

Impacted file:
* `loading_dialog.dart`: checking hasError instead of hasData - hasData is not reliable as data can be void or null.
  • Loading branch information
monsieurtanuki authored Apr 29, 2022
1 parent 34939ca commit 20a9da0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/smooth_app/lib/generic_lib/loading_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,22 @@ class LoadingDialog<T> {
body: FutureBuilder<T>(
future: future,
builder: (BuildContext context, AsyncSnapshot<T> snapshot) {
if (snapshot.hasData) {
if (snapshot.connectionState == ConnectionState.done) {
// Now it's either hasError or successful.
// We cannot check hasData because data can be null or void.
if (snapshot.hasError) {
return ListTile(
title: Text(appLocalizations!.error_occurred),
);
}
_popDialog(context, snapshot.data);
// whatever, anyway we've just pop'ed
return Container();
} else if (snapshot.hasError) {
return ListTile(
title: Text(appLocalizations!.error_occurred),
);
} else {
return ListTile(
leading: const CircularProgressIndicator(),
title: Text(title),
);
}
return ListTile(
leading: const CircularProgressIndicator(),
title: Text(title),
);
},
),
actions: <SmoothActionButton>[
Expand Down

0 comments on commit 20a9da0

Please sign in to comment.