Home > Net >  I am trying to navigate home screen via Start screen through main.dart but failed to navigate. I am
I am trying to navigate home screen via Start screen through main.dart but failed to navigate. I am

Time:05-12

This is my main .dart and the error is here that is In This Image this is the error that I got on the screen. I am trying to solve but it is not in my hand to solve, Swipe Bloc throws an error, I tried too much to solve it but every time I see failure to solve it.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  // runApp(MyApp());
  runApp(
    MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyLogin(),
      routes: {
        'register': (context) => MyRegister(),
        'login': (context) => MyLogin(),
      },
    )
  );
}

Here is the stateless widget which throws the particular error which I don't know where it throws.

class MyHome extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiRepositoryProvider(  
      providers: [
        RepositoryProvider(
          create: (context) => AuthRepository(),
        ),
        RepositoryProvider(
          create: (context) => StorageRepository(),
        ),
        RepositoryProvider(
          create: (context) => DatabaseRepository(),
        ),
      ],
      child: MultiBlocProvider(
        providers: [
          BlocProvider(
            create: (context) => AuthBloc(
              authRepository: context.read<AuthRepository>(),
            ),
          ),
          // BlocProvider(
          //   create: (context) => SwipeBloc()
          //   ..add(
          //     LoadUsers(users: User.users.where((user) => user.id != 1).toList(),
          //     ),
          //   ),
          // ),
          BlocProvider<SignupCubit>(
          create: (context) =>
            SignupCubit(authRepository: context.read<AuthRepository>()),
          ),
          BlocProvider<OnboardingBloc>(
            create: (context) => OnboardingBloc(
              databaseRepository: context.read<DatabaseRepository>(),
              storageRepository: context.read<StorageRepository>(),
              ),
            ),
            BlocProvider(
              create: (context) => ProfileBloc(
                authBloc: context.read<AuthBloc>(),
                databaseRepository: context.read<DatabaseRepository>(),
              )..add(
                LoadProfile(userId: context.read<AuthBloc>().state.user!.uid),
              ),
            ),
        ],
        child: MultiBlocProvider(
        providers: [
          BlocProvider(
            create: (context) => SwipeBloc()
            ..add(
              LoadUsers(users: User.users.where((user) => user.id != 1).toList(),
              ),
            ),
          ),
        ],
        
        child: 
        MaterialApp(
          
        ),
        ),
      ),
    );
  }
}

This error I got on my android sceen.

CodePudding user response:

Try to initialize all your providers above MaterialApp, like in this code

void main() {
  runApp(
    MultiRepositoryProvider(  
  providers: [
    RepositoryProvider(
      create: (context) => AuthRepository(),
    ),
    RepositoryProvider(
      create: (context) => StorageRepository(),
    ),
    RepositoryProvider(
      create: (context) => DatabaseRepository(),
    ),
  ],
  child: MultiBlocProvider(
    providers: [
      BlocProvider(
        create: (context) => AuthBloc(
          authRepository: context.read<AuthRepository>(),
        ),
      ),
      ],
      child: MaterialApp(),
    ),
  );
}
  • Related