I declare one global variable in the entire app - SharedPreferences prefs
, and initialize it in main
method.
However, SharedPreferences>
Good one from @jamesdlin .
A literal answer for your question
How does main method gets invoked and how it works in general in Dart / Flutter?
For Android apps, Dart entry point is invoked via DartExecutor
. You can take a look at here: DartExecutor class
There is a brief document, how you can manually do what FlutterApplication does for you: wiki/Experimental:-Launch-Flutter-with-non-main-entrypoint
Classes you want to look for, if you want to dig deeper: FlutterApplication
, FlutterActivity
, FlutterMain
.