get_it_future_builder 0.1.0 get_it_future_builder: ^0.1.0 copied to clipboard
Wait for your async `get_it` dependencies to be ready in the presentation layer.
Get It Future Builder #
get_it_future_builder
provides a widget named GetItFutureBuilder
to wait for your async dependencies to be ready on your presentation layer.
This project is in its infancy stage, where any suggestions and PRs are welcome.
Installation 💻 #
❗ In order to start using Get It Future Builder you must have the Flutter SDK installed on your machine.
Add get_it_future_builder
to your pubspec.yaml
:
dependencies:
get_it_future_builder:
Install it:
flutter packages get
How to Use It #
You can also see example directory.
Register your async dependency through GetIt
as such:
GetIt.I.registerSingletonAsync<Directory>(
() async {
return await getApplicationDocumentsDirectory();
},
instanceName: 'documents_dir', // optional
);
In our example, we'll use getApplicationDocumentsDirectory method of path_provider. Since it calls native code through MethodChannel
, it has to be asynchronous.
Then, in the presentation layer, you can simply do:
// notice how we get the dependency with generics
GetItFutureBuilder<Directory>(
// optional
instanceName: 'documentsDir',
// render this widget while loading
loading: (context) => LinearProgressIndicator(),
// render this widget when it's ready
ready: (context, instance) => Text('documents dir is: ${instance.path}'),
)