Last active
June 3, 2023 15:02
-
-
Save Daniel-Sogbey/c360f28507ceac45a6fd30c67af004ff to your computer and use it in GitHub Desktop.
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
// 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