Created
September 3, 2020 12:49
-
-
Save vlasentiy/e38d02d560fcc70fcc4a8087ace16802 to your computer and use it in GitHub Desktop.
FutureProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyWidget extends StatelessWidget { | |
// Future<String> callAsyncFetch() => Future.delayed(Duration(seconds: 3), () => "hi bro"); | |
@override | |
Widget build(BuildContext context) { | |
// print('building widget'); | |
return FutureProvider<String>( | |
create: (_) { | |
// print('calling future'); | |
return callAsyncFetch(); | |
}, | |
child: Consumer<String>( | |
builder: (_, value, __) => Text(value ?? 'Loading...'), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment