1
ChangeNotifierProvider(
              create: (context) => BuyValuableNotifier(),
              child: OpenContainer(
              
                closedBuilder: (context, action) {
                  return Container();
                },
                openBuilder: (context, action) {
                  return SingleWidget();
                },
              ),
            ),

so I have this error when call openBuilder: Error: Could not find the correct Provider above this SingleWidget Widget

OpenContainer(
              closedBuilder: (context, action) {
                return Container();
              },
              openBuilder: (context, action) {
                return ChangeNotifierProvider(
                    create: (context) => BuyValuableNotifier(),
                    child: SingleWidget();
              },
            ),

and if I do this I will loose data when openBuilder closes what do I do?

farzin
  • 11
  • 1

1 Answers1

0

Hey I know I'm late but maybe I still help someone. The issue is that the builders of OpenContainer create a new context, so the returning widget of closedBuilder and openBuilder should be wrapped with ChangeNotifierProvider.value usually. This way you also wouldn't lose data when openBuilder closes because you'd be using the same provider instance.

FLjubic
  • 161
  • 1
  • 4