Skip to content

Instantly share code, notes, and snippets.

@vlasentiy
Last active September 3, 2020 12:51
Show Gist options
  • Save vlasentiy/ce5bbd1291cc2ebe0b82fb13814f1bb9 to your computer and use it in GitHub Desktop.
Save vlasentiy/ce5bbd1291cc2ebe0b82fb13814f1bb9 to your computer and use it in GitHub Desktop.
HookWidget
class MyWidget extends HookWidget {
@override
Widget build(BuildContext context) {
final future = useMemoized(() {
// Future<String> callAsyncFetch() => Future.delayed(Duration(seconds: 3), () => "hi bro");
callAsyncFetch(); // or your own async function
});
return FutureBuilder<String>(
future: future,
builder: (context, snapshot) {
return Text(snapshot.hasData ? snapshot.data : 'Loading...');
}
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment