简体   繁体   中英

I am trying to navigate home screen via Start screen through main.dart but failed to navigate. I am new to flutter and can't understand this error. Pl

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.

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(),
    ),
  );
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM