Question
I created a function which takes over 150ms and often 200ms to load:
await Hive.initFlutter();
final authBox = await Hive.openBox(STORED_AUTH_STATE);
Is this normal? The delay is noticeable because I call it before my runApp function as the app depends on local state.
The delay creates a black screen on the app before it starts (since it's running the call to hive).
Code sample
boostrap().then((widget) => runApp(widget));
Version
[✓] Flutter (Channel stable, v1.12.13+hotfix.8, on Mac OS X 10.14.6 18G103, locale en-US)
• Flutter version 1.12.13+hotfix.8 at /Users/anton/Personal/flutter
• Framework revision 0b8abb4724 (5 days ago), 2020-02-11 11:44:36 -0800
• Engine revision e1e6ced81d
• Dart version 2.7.0
Looks like the delay originates from WidgetsFlutterBinding.ensureInitialized();
I wonder if there is a way around that. May need to show a temp loader while this call happens.
@abacaj Using runApp multiple times is considered good practice:
main() async {
runApp(Center(child: CircularProgressIndicator()));
await Hive.initFlutter();
final authBox = await Hive.openBox(STORED_AUTH_STATE);
// ...
runApp(MyApp());
}
I wonder if there is a way around that. May need to show a temp loader while this call happens.
This call is only needed to make sure path_provider returns a valid path. If you can provide a path yourself, you can use Hive.init().
Most helpful comment
@abacaj Using
runAppmultiple times is considered good practice: