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 = MasamuneModuleSimpleblogMasamuneAdapter.primary;
  if (adapter.option.logoImage != null) {
    await precacheImage(adapter.option.logoImage!.toImageProvider(), context);
  }
  try {
    await adapter.auth.tryRestoreAuth();
    if (adapter.auth.isSignedIn) {
      final user = UserModel.document(adapter.auth.userId).read(adapter.ref);
      await user.load();
      if (user.value == null) {
        await user.save(UserModel(name: ml().guest));
      }
    }
  } catch (e, stacktrace) {
    await Modal.alert(
      context,
      submitText: ml().close,
      title: ml().error,
      text: ml().initializationFailedExitTheApplication.$(e).$(stacktrace),
      onSubmit: () async {
        await SystemNavigator.pop();
      },
    );
  }
}