Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 像工厂一样使用供应商_Flutter_Dart_Provider_Riverpod - Fatal编程技术网

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。您可以像这样传入一个参数并创建单独的提供程序