4

エラー: I/flutter ( 5919): ══╡ 例外がウィジェット ライブラリーによってキャッチされました═══════════════════════════ I/flutter (5919): 次のアサーションがビルド ビルダーにスローされました: I/flutter (5919): BlocProvider Bloc タイプの Bloc を含まないコンテキストで .of() が呼び出されました。I/flutter (5919): I/flutter (5919): BlocProvider.of>() に渡されたコンテキストから始まる祖先が見つかりませんでした。私/フラッター ( 5919):
これは、使用したコンテキストが BlocProvider の上のウィジェットに由来する場合に発生する可能性があります。I/flutter ( 5919): 使用されたコンテキストは: BlocBuilder, dynamic>(dirty, state: I/flutter ( 5919): _BlocBuilderBaseState, dynamic>#55a7d(lifecycle state: created)) I/flutter ( 5919): 関連するエラーの原因となったウィジェット: I/flutter (5919): MaterialApp /lib/main.dart:35:12

これが私のメインです

void main() {
  final StorageRepository storageRepository = StorageRepository();
  final AuthenticationRepository authenticationRepository =
      AuthenticationRepository();
  runApp(BlocProvider<AuthenticationBloc>(
      create: (_) => AuthenticationBloc(
          authenticationRepository: authenticationRepository,
          storageRepository: storageRepository),
      child: MyApp()));
}

MaterialApp ウィジェット

MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.deepPurple),
      home: BlocBuilder(
        builder: (context, state) {
          print(state);
          if (state is Authenticated) {
            return MainPage();
          } else if (state is Unauthenticated) {
            return LoginPage();
          } else if (state is Uninitialized) {
            return SplashScreen();
          }

          return Container();
        },
      ),
4

2 に答える 2