简体   繁体   English

Provider 在 ReorderableListView 中拖动 Widget 时退出 scope 并抛出错误

[英]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:以下是帮助可视化用例的图像: 网格中的每一行都是 ReorderableListView 的一个 List 项 错误


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.

相关问题 使用 flutter Provider 小部件时出现以下错误 - iget the following error while using the flutter Provider widget 提供了上下文但抛出错误找不到正确的提供者<Data>在这个 MyApp Widget Flutter 之上 - context provided but throws error Could not find the correct Provider<Data> above this MyApp Widget Flutter ReorderableListView 无法识别自定义小部件中的键 - ReorderableListView does not identify keys in Custom Widget ReorderableListView 在项目列表中出现 Slider 时抛出 - ReorderableListView throws when Slider in item list 删除从 ReorderableListView (Flutter) 拖动项目时出现的阴影 - Removing the shadow that appears when dragging an item from a ReorderableListView (Flutter) 扩展的小部件抛出“RenderBox没有布局”异常 - Expanded Widget throws “ RenderBox was not laid out” Exception 展开的小部件抛出“RenderBox 未布局”异常 - Expanded widget throws "RenderBox was not laid out" exception 当构建器获得大于 9 的值时,PageView 小部件中出现超出范围错误 - Out of range error in PageView widget when the builder gets a value greater than 9 错误:找不到此 Widget 上方的正确 Provider< > - Error: Could not find the correct Provider< > above this Widget 提供程序在屏幕上调用小部件时出错 - Provider gives error when calling a widget on the screen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM