Skip to content

Instantly share code, notes, and snippets.

@vlasentiy
Created September 3, 2020 12:49
Show Gist options
  • Save vlasentiy/e38d02d560fcc70fcc4a8087ace16802 to your computer and use it in GitHub Desktop.
Save vlasentiy/e38d02d560fcc70fcc4a8087ace16802 to your computer and use it in GitHub Desktop.
FutureProvider
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