feat: resolve and resolveWith helper support

This commit is contained in:
Kingkor Roy Tirtho
2023-06-23 22:40:20 +06:00
parent 8c7b19c0e5
commit a40dca73b5
12 changed files with 347 additions and 42 deletions
+5 -11
View File
@@ -43,17 +43,11 @@ class QueryPage extends StatelessWidget {
debugPrint('onError: $error');
},
builder: (context, query) {
if (query.isLoading) {
return const Center(
child: CircularProgressIndicator(),
);
} else if (query.hasError) {
return Center(
child: Text(query.error.toString()),
);
}
return Center(
child: Text(query.data ?? "Unfortunately, there's no data"),
return query.resolveWith(
context,
(data) => Center(child: Text(data)),
error: (error) => Center(child: Text(error.toString())),
loading: () => const Center(child: CircularProgressIndicator()),
);
},
),