Why doesn't FutureBuilder execute a condition when the data is not ready yet? I.e. block else where '-------------' is not executed.
Before I used provider, that block would execute, i.e. it would show CircularProgressIndicator.
The provider value (ChangeNotifierProvider) is changed in the PaginationAppBar.
Future<List<ProfileData>> fetchProfiles(int page) {
WebService webService = locator<WebService>();
return webService.fetchProfiles(Gender.female, page); //future
}
@override
Widget build(BuildContext context) {
final pagerModel = context.watch<PagerModel>();
return FutureBuilder<List<ProfileData>>(
future: fetchProfiles(pagerModel.page),
builder: (context, snapshot) {
if (snapshot.hasData) {
final data = snapshot.data;
debugPrint('snapshot data length ${snapshot.data?.length}');
if (data!.isEmpty) {
return const ErrorWithMessage(message: 'data loading error');
}
return Scaffold(
appBar: const PaginationAppBar(Gender.female),
body: ProfileGrid(data),
);
} else if (snapshot.hasError) {
return _processError(snapshot);
} else {
debugPrint('-------------this else does not execute');
return const Scaffold(
appBar: PaginationAppBar(Gender.female),
body: CircularProgressIndicator(),
);
}
},
);
}
}