To use Provider for only some specific pages in my Flutter project ?? what is a cleanner way

20 Views Asked by At
return MultiProvider(
  providers: [
    ChangeNotifierProvider(create: (_) => PageRouteProvider()),
    ChangeNotifierProvider(create: (_) => ProfileDetailsProvider()),
    ChangeNotifierProvider(create: (_) => CommonProvider()),
    ChangeNotifierProvider(create: (_) => AddListingProvider()),
  ],
  child: MaterialApp.router(
    theme: theme,
    title: 'Nobuyrent',
    builder: EasyLoading.init(),
    debugShowCheckedModeBanner: false,
    routerConfig: goRouter,
  ),
);

here ProfileDetailsProvider() and AddListingProvider() i use these provider for some group of pages only but I inject in top level of widget is that proper way ???, However, if the state managed by these providers is only relevant to a subset of pages and not used globally throughout My application, i might consider injecting these providers closer to where they are actually needed, rather than at the top level.

my code works fine, but i need to know its good practice or not

0

There are 0 best solutions below