'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:

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.
Solution 1:[1]
Wrap your list item with a
InheritedProvider<T>.value(value: T,child: YourListItem())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ebrahim Soliman |
