Use Provider like a Factory
169
Take a look at Riverpod's .family. You can pass a parameter in just like that and create separate providers.
Comments
-
WebMaster over 1 year
Can I use
Provider
in flutter like a factory constructor? I want towatch
,read
anddispose
my objectCurrently to watch a value we can use
context.watch<MyValue>()
, I want to watch multiple instance ofMyValue
and I want to know can provider do it for me?class MyValue{ final int id; MyValue({this.id}); }
I need something like
final a = context.watch<MyValue>(id:1); final b = context.watch<MyValue>(id:2); final c = context.watch<MyValue>(id:3); final d = context.watch<MyValue>(id:1); assert(a==d); assert(a!=b);
If
Provider
cannot do it, How can I implement it, or is there another library?