v4.3.0
- Added BuildContext extension [context.read()] and [context.watch()];
- The [context.watch()] listen changes of [Listanable], [Stream] and [Store] by Triple;
class Body extends StatelessWidget {
Widget build(BuildContext context){
final notifier = context.watch<ValueNotifier>();
return Text('${notifier.value}')
}
}- Use
selectin.watch()to select the reactive property:
class Body extends StatelessWidget {
Widget build(BuildContext context){
final bloc = context.watch<CounterBloc>((bloc) => bloc.stream);
return Text('${bloc.state}')
}
}Also, use Store Selectors in conjunction with .watch:
class OnlyErrorWidget extends StatelessWidget {
Widget build(BuildContext context){
// changes with store.setError();
final store = context.watch<MyTripleStore>((store) => store.selectError);
return Text('${store.error}')
}
}See more details here