To Reproduce
I have futureProvider is
final currentProfileProvider = FutureProvider<Profile>((ref) async {
final currentMSV = await SharedPrefs.instance.getCurrentMSV();
return ref.read(profileRepositoryProvider).getUserByMSV(currentMSV);
});
usage:
final currentProfile = context.read(currentProfileProvider);
currentProfile.whenData((profile) {
print(profile.toJson());
print('data is ${profile.toJson()}');
showAlertMessage(context, profile.Token);
});
in the first click: nothing happens.
second click: dialog show with data.
third click: dialog show with data.

whenData does not wait for the future to resolve. It's a synchronous operation, and if the future isn't completed, nothing happens.
What you want is to await the future instead:
final profile = await context.read(currentProfileProvider.future);
print(profile.toJson());
print('data is ${profile.toJson()}');
showAlertMessage(context, profile.Token);
It worked. Thank you a lot!
Most helpful comment
whenDatadoes not wait for the future to resolve. It's a synchronous operation, and if the future isn't completed, nothing happens.What you want is to await the future instead: