【发布时间】:2020-09-27 02:57:14
【问题描述】:
// Are these the same?
final model = Provider.of<Model>(context, listen: false);
final model = context.read<Model>();
// Are these the same?
final model = Provider.of<Model>(context);
final model = context.watch<Model>();
它们是否相同?如果是,那么当我在 build() 方法中使用 read 而 Provider.of() 有效时,为什么会出现此错误?
尝试在
build方法或提供者的update回调中使用context.read<Model>。
【问题讨论】: