admin管理员组文章数量:1200976
I am creating a flutter page that uses google maps as a base, and has a search bar on top. Both components interact with the list of markers I use to populate the map, but trying to manipulate the list using callback functions is like pulling out teeth. I read that if I was trying to manipulate complex states like this, I should use state management packages like Riverpod, but reading about it makes me think that providers are like global variables? Except I don't want my list of Markers to be available to all my pages, just my main page and its child components.
The documentation for riverpod is frustrating, everything is either out of date, or really simple. The only thing that I found that was similar was scoping my providers, but that just means having a hanging provider around that is doing nothing. Is there another way to do this or am I looking at it the wrong way?
I am creating a flutter page that uses google maps as a base, and has a search bar on top. Both components interact with the list of markers I use to populate the map, but trying to manipulate the list using callback functions is like pulling out teeth. I read that if I was trying to manipulate complex states like this, I should use state management packages like Riverpod, but reading about it makes me think that providers are like global variables? Except I don't want my list of Markers to be available to all my pages, just my main page and its child components.
The documentation for riverpod is frustrating, everything is either out of date, or really simple. The only thing that I found that was similar was scoping my providers, but that just means having a hanging provider around that is doing nothing. Is there another way to do this or am I looking at it the wrong way?
Share Improve this question asked Jan 22 at 6:52 P.HuangP.Huang 134 bronze badges1 Answer
Reset to default 1This is a common misconception. Access to a provider really requires three things... the unique provider (usually but not always stored in a global variable), a "ref" (typically obtained via the context chain), and a ProviderContainer (usually enclosed in the nearest ProviderScope, which can be nested. Family providers add a fourth level of distinction in the family key.
So providers are hardly "global", because you need the right 3 or 4 values to effectively locate a specific provider.
I illustrate this in my video: https://www.youtube.com/watch?v=gHbkIgDnDyg
本文标签: flutterHow to use Riverpod Providers as a SemiGlobal VariablesStack Overflow
版权声明:本文标题:flutter - How to use Riverpod Providers as a Semi-Global Variables - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738582433a2101243.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论