简体   繁体   中英

Provider gets out of scope while dragging Widget in ReorderableListView and throws Error

The app I am trying to make includes a 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 .

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

This happens because you used a BuildContext that does not include the provider of your choice.

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. I tried to place the ChangeNotifierProvider right above my MaterialApp widget too, but that also yields the same error.

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.

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())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM