how to dispose the provider that is wrapping the entire MaterialApp in Flutter

Viewed 728

When I wrap the widget that is the home of the MaterialApp with MultiProvider it works fine but when I want to navigate to another page that already contains widgets that depend on the provider,

a message shows up that tell me

"Could not find the correct Provider above .... et cetera"

but when I wrap the entire MaterialApp, It works fine

but the problem is

even when I remove all Widget tree and insert a new page

the provider still has its data and I need it to dispose

cause I can access the data of the provider from inside the newly inserted page after removing all the previous pages from the navigator stack

how can I force the disposing of the provider that is already wrapping the MaterialApp

here is the sample code

            class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MultiProvider(
          providers: [
            ChangeNotifierProvider<CommonWidgetsStateProvider>(
              create: (context) => CommonWidgetsStateProvider(),
            ),
            ChangeNotifierProvider<CollegePostSignUpState>(
            create: (context) => CollegePostSignUpState()),
            ChangeNotifierProvider<SchoolStudentPostSignupState>(
            create: (context) => SchoolStudentPostSignupState()),
            ChangeNotifierProvider(create: (context) => ExecutionState())
           ],
          child: MaterialApp(
          debugShowCheckedModeBanner: false,
          home: LandingPage(),
          routes: NavigatorServices.navigatorRoutes),
         );
        }
}```
0 Answers
Related