Reputation: 5101
This is the root widget from my Flutter app:
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
SharedPreferences prefs = await SharedPreferences.getInstance();
var email = prefs.getString('email');
print(email);
runApp(
EasyLocalization(
child: ChangeNotifierProvider(
create: (BuildContext context) => ClinicaProvider(),
child: MaterialApp(
debugShowCheckedModeBanner: false,
home: email == null || email == '' ? Splash2() : HomeScreen())),
path: "assets/translations",
saveLocale: true,
supportedLocales: [Locale('en', 'EN'), Locale('es', 'ES')],
),
);
}
I have instantiate ClinicaProvider(), but now I need to add more providers, for example UsersProvider(), what is the best way to do it?
Upvotes: 1
Views: 207
Reputation: 2714
You can work with MultiProviders
example:
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MultiProvider(
providers: [
ChangeNotifierProvider(create: (context) => SwipePlayerControls()),
ChangeNotifierProvider(
create: (context) => SongNotifier()),
],
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
accentColor: Color.fromRGBO(236, 36, 105, 1),
canvasColor: Color.fromRGBO(15, 15, 16, 1),
),
home: MyHomePage(),
),
);
}
}
Upvotes: 2