Flutter 像工厂一样使用供应商
我是否可以像工厂构造函数一样在颤振中使用Flutter 像工厂一样使用供应商,flutter,dart,provider,riverpod,Flutter,Dart,Provider,Riverpod,我是否可以像工厂构造函数一样在颤振中使用提供程序?我想观看,阅读和处置我的对象 当前要查看一个值,我们可以使用context.watch(),我想查看MyValue的多个实例,我想知道提供者能帮我做吗 类MyValue{ 最终int id; MyValue({this.id}); } 我需要像这样的东西 final a=context.watch(id:1); final b=context.watch(id:2); final c=context.watch(id:3); final d=c
提供程序
?我想观看
,阅读
和处置
我的对象
当前要查看一个值,我们可以使用context.watch()
,我想查看MyValue
的多个实例,我想知道提供者能帮我做吗
类MyValue{
最终int id;
MyValue({this.id});
}
我需要像这样的东西
final a=context.watch(id:1);
final b=context.watch(id:2);
final c=context.watch(id:3);
final d=context.watch(id:1);
断言(a==d);
断言(a!=b);
如果
Provider
无法实现,我如何实现它,或者是否有其他库?请查看Riverpod的.family。您可以像这样传入一个参数并创建单独的提供程序