In my Flutter app I'm fetching some datetime info from an API but getting this error. I'm using Provider.
My display widget has this in didChangeDependencies:
_userDateTime = Provider.of<TimeZones>(context, listen: false).getDateTime(0);
print('didChangeDependencies()');
print(_localDateTime.toString());
print(DateFormat("E d MMM hh:mm a").format(_localDateTime));
and this outputs ok up until I try to use that datetime object.
flutter: didChangeDependencies()
flutter: Instance of 'Future<DateTime>'
======== Exception caught by widgets library
So I know that TimeZones is returning a DateTime object, I can test the values and see that it's right.
How do I get my widget to accept the Future and treat it as a normal DateTime?
or is there a better approach?
It looks like your
getDateTime(0)call returns a future. Try to await it:_userDateTime = await Provider.of<TimeZones>(context, listen: false).getDateTime(0);