i'm building a flutter App using navigation 2.0 and i'm starting to use ObjectBox library to store user appdata.
for now i initialize it that way in my main.dart then import the variable objectBox whenever i want to use it in the viewModels.
late ObjectBox objectBox;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
objectBox = await ObjectBox.init();
runApp(const MyApp());
}
i initialise it like that and put objectBox as a global variable ... but i think it's not good at all. what are the good practices around that?
MyApp is basically
MaterialApp.router(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
routeInformationParser: NavigationParser(),
routerDelegate: NavigationDelegate(),
)
with the router ( NavigationDelegate() ) where i get to normally store global variables and initialise things i need in the app.
what would you advice me?
thanks, Badr