onInit method

  1. @override
FutureOr<void> onInit(
  1. BuildContext context
)
override

Describe the initialization process after the screen is displayed.

After this process is complete, the user is taken to the first screen.

画面表示後の初期化処理を記述します。

この処理が終わると最初の画面に遷移します。

Implementation

@override
FutureOr<void> onInit(BuildContext context) async {
  final adapter =
      MasamuneAdapterScope.of<SimpleBlogModuleMasamuneAdapter>(context);
  try {
    await wait([
      appPrefs.load(),
      adapter!.ref.model(NoteModel.collection()).load(),
      adapter.notification?.subscribe(),
      Future.delayed(2.s),
    ]);
  } catch (e, stacktrace) {
    await Modal.alert(
      context,
      submitText: ml().close,
      title: ml().error,
      text: ml().initializationFailedExitTheApplication.$(e).$(stacktrace),
      onSubmit: () async {
        await SystemNavigator.pop();
        exit(0);
      },
    );
  }
}