Flutter Provider: what is the best way to dispatch the action properly?

拟墨画扇 提交于 2020-06-29 03:39:55

问题


The question is related to my previous question: Why can't I use context.read in build(), but I can use Provider.of with listen: false? You said that an old Provider.of<X>(context, listen: false) syntax is unsafe. However, it works.

I believe fetchTransactions() method won't change, so there's no need to watch it.

I can't use context.read because it's not in the closure and will throw the "don't use context.read in a build method" error.

I can't use context.watch or context.select with FutureBuilder, because it will cause an infinite rebuild loop.

来源:https://stackoverflow.com/questions/62539885/flutter-provider-what-is-the-best-way-to-dispatch-the-action-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!