Closed ianjaspersantos closed 4 years ago
The official Consumer of provider works
Final output! Thanks hero! 💙💙💙
return StateNotifierProvider<CounterStateNotifier, CounterState>(
create: (BuildContext context) => CounterStateNotifier(CounterState(0)),
child: Consumer2<CounterStateNotifier, CounterState>(
builder: (BuildContext context, CounterStateNotifier counterStateNotifier, CounterState counterState, Widget child) {
counterStateNotifier.increment();
counterStateNotifier.decrement();
counterState.value;
return Scaffold();
},
),
);
PS: I would still love to see if you will out of the box support this kind of syntax, cause it will be a lovely match to StateNotifierProvider.
class StateNotifierConsumer<A extends StateNotifier<B>, B> extends StatelessWidget {}
I do not see any reason to do such thing, as StateNotifierConsumer == Consumer
With Dart upcoming typedefs for classes, this becomes trivial:
typedef StateNotifierConsumer<A extends StateNotifier<B>, B> = Consumer2<A, B>;
Honestly you're right! There's no reason to do such thing. It's just a matter of (my) naming preferences. Hopefully, I can see typedefs for classes in action very soon. 💙💙💙
You can do, as of today, the following :
mixin _Noop {}
class StateNotifierConsumer<A extends StateNotifier<B>, B> = Consumer2<A, B> with _Noop;
Best part about flutter community while still learning 💙
You can do, as of today, the following :
mixin _Noop {} class StateNotifierConsumer<A extends StateNotifier<B>, B> = Consumer2<A, B> with _Noop;
Currently, the implementation of StateNotifierBuilder widget requires stateNotifier property which will be coming from the Consumer widget or (from the context extension if possible).
While it's good and working like a charm, I'd like to know if you have a plan adding support for the following syntax. :)