[英]Provider gets out of scope while dragging Widget in ReorderableListView and throws Error
The app I am trying to make includes a ReorderableListView
.我正在尝试制作的应用程序包括
ReorderableListView
。 The List comprises of items that use a Consumer
widget and the ChangeNotifierProvider
for that widget is placed directly below the Scaffold in a MultiProvider
. List 包含使用
Consumer
小部件的项目,并且该小部件的ChangeNotifierProvider
直接放置在MultiProvider
中的 Scaffold 下方。
The List Items itself are designed with Options.列表项本身是用选项设计的。 For example, the user can choose to make the list item blue,red or green.
例如,用户可以选择将列表项设为蓝色、红色或绿色。 So when I'm dragging and reordering the list item, the item should move with the decoration specified by the User.
因此,当我拖动并重新排序列表项时,该项目应与用户指定的装饰一起移动。
Here's images to help with visualizing the usecase:以下是帮助可视化用例的图像:
However, I am getting the following error when I try to reorder an item:但是,当我尝试重新订购商品时出现以下错误:
Error: Could not find the correct Provider above this Selector<TopsterBoxesController, TopsterBoxData> Widget错误:在此 Selector<TopsterBoxesController, TopsterBoxData> 小部件上方找不到正确的提供程序
This happens because you used a BuildContext
that does not include the provider of your choice.发生这种情况是因为您使用的
BuildContext
不包括您选择的提供者。
So basically, what I am understanding is, when I reorder List items, the draggable when dragged is going out of scope and not able to find my provider.所以基本上,我的理解是,当我重新排序列表项时,拖动时的可拖动对象超出 scope 并且无法找到我的提供者。 I tried to place the
ChangeNotifierProvider
right above my MaterialApp
widget too, but that also yields the same error.我也尝试将
ChangeNotifierProvider
放在MaterialApp
小部件的正上方,但这也会产生相同的错误。
When the reorder is complete, there is no problem.重新排序完成后,没有问题。 My ListItem automatically moves and settles with the appropriate design, so it is able to find the Provider again.
我的 ListItem 会自动移动并以适当的设计安顿下来,因此它能够再次找到 Provider。
Would greatly appreciate if anybody knows of a workaround.如果有人知道解决方法,将不胜感激。 Thanks in advance.
提前致谢。
Wrap your list item with a InheritedProvider<T>.value(value: T,child: YourListItem())
用
InheritedProvider<T>.value(value: T,child: YourListItem())
包装您的列表项
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.