Skip to content

Instantly share code, notes, and snippets.

@Daniel-Sogbey
Last active June 3, 2023 15:02
Show Gist options
  • Save Daniel-Sogbey/c360f28507ceac45a6fd30c67af004ff to your computer and use it in GitHub Desktop.
Save Daniel-Sogbey/c360f28507ceac45a6fd30c67af004ff to your computer and use it in GitHub Desktop.
// method in a widget that inherits stateful widget
Future<void> _refreshFoo(BuildContext context) async {
// First category: Foo
await Provider.of<Foo>(context, listen: false)
.fetchFoo(true);
//Second category: Bar
await Provider.of<Bar>(context, listen: false)
.fetchBar(true);
}
// Your home page body
body: FutureBuilder(
future: _refreshProducts(context),
builder: (ctx, snapshot) =>
snapshot.connectionState == ConnectionState.waiting
? Center(
child: Container(
width: 100,
height: 100,
margin: EdgeInsets.all(100.0),
child: Spinner(),
),
)
: RefreshIndicator(
onRefresh: () => _refreshFoo(context),
child: Consumer<Products>(
builder: (ctx, foo, _) {
return // your home page content
}
),
),
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment