stream_provider 0.0.1
stream_provider: ^0.0.1 copied to clipboard
A package makes it easy for you to use stream with Provider.
Stream Provider #
A package makes it easy for you to use stream with Provider.
Pros
- Doesn't need call
notifyListenerseverytime, everywhere.
- Able to use power of
streamand RxDart, when you have to deal with complex tasks
Cons
- Need to
close()every Stream that you declare into Provider insidedispose()
Usage #
Exposing a value #
Exposing a new object instance
Create a new object inside create.
StreamProvider(
create: (_) => new MyModel(),
child: ...
Reusing an existing object instance:
If you already have an object instance and want to expose it,
you should use the .value constructor of a provider.
Failing to do so may call the dispose method of your object when it is still in use.
Use StreamProvider.valueto provide an existingProvider.
MyProvider variable;
StreamProvider.value(
value: variable,
child: ...
)
Reading a value #
The easiest way to read a value is by using the static method
StreamProvider.of
or
context.provider<T>()
This method will look up in the widget tree starting from the widget associated
with the BuildContext passed and it will return the nearest variable of type
T found (or throw if nothing is found)