English 中文(简体)
多方保存人 提供商 Blac
原标题:MultiRepositoryProvider doesn t instantiate Bloc

我最近开始开发一个闪电灯,使该地区变得更新。 因此,我一直在研究如何使用布洛茨。 然而,当我反省我的布洛茨和我的服务时,一切都会奏效。 在我使用<代码>之前, 供应商。 我有两部法典。 第一:

return RepositoryProvider<AuthenticationService>(
      create: (context) {
        return FakeAuthenticationService();
      },
      // Injects the Authentication BLoC
      child: BlocProvider<AuthenticationBloc>(
        create: (context) {
          final authService = RepositoryProvider.of<AuthenticationService>(context);
          return AuthenticationBloc(authService)..add(AppLoaded());
        },
        child:  MaterialApp(
          title:  Authentication Demo ,
          theme: appTheme(),
          home: BlocBuilder<AuthenticationBloc, AuthenticationState>(
            builder: (context, state) {
              if (state is AuthenticationAuthenticated) {
                // show home page
                return HomePage(
                  user: state.user,
                );
              }
              // otherwise show login page
              return StartupPage();
            },
          ),
        )
      ),
    );

该法典实行罚款,但第2版则完全相同,但使用<代码>Multi RepositoryProvider的除外。 第二部法典:

return MultiRepositoryProvider(
      providers: [
        RepositoryProvider<AuthenticationService>(
          create: (context) => FakeAuthenticationService(),
          child: BlocProvider<AuthenticationBloc>(
            create: (context) {
              final authService = RepositoryProvider.of<AuthenticationService>(context);
              return AuthenticationBloc(authService)..add(AppLoaded());
            },
          ),
        )
      ],
      child: MaterialApp(
        title:  Authentication Demo ,
        theme: appTheme(),
        home: BlocBuilder<AuthenticationBloc, AuthenticationState>(
          builder: (context, state) {
            if (state is AuthenticationAuthenticated) {
              // show home page
              return HomePage(
                user: state.user,
              );
            }
            // otherwise show login page
            return StartupPage();
          },
        ),
      ),
    );

现在,第二部法典给我留下了以下错误:BlocProvider.of() ,其背景并不包含AthenticationBloc类的缩略语。

是否有任何人知道第二部法典为什么不奏效?

问题回答

我是同一件事,我错了,但现在解决了。

return MultiRepositoryProvider(
    providers: [
      RepositoryProvider<TranslationRepository>(
        create: (context) => TranslationRepository(),
      ),
      RepositoryProvider<WeatherRepository>(
        create: (context) => WeatherRepository(),
      ),
    ],
    child: MultiBlocProvider(
        providers: [
          BlocProvider<WeatherBloc>(
            create: (context) =>
                WeatherBloc(context.read<WeatherRepository>()),
          ),
          BlocProvider<ConnectivityBloc>(
            create: (context) => ConnectivityBloc(),
          ),
          BlocProvider<TranslationBloc>(
            create: (context) =>
                TranslationBloc(context.read<TranslationRepository>()),
          ),
        ],
        child: MaterialApp(
          title:  Material App ,
          onGenerateRoute: router.generateRoute,
          initialRoute:  / ,
        )));

First, in my create function I overrided the context with "_" but I got the same error. Now with this snippet it works perfectly, just put the same context name as my providers before

www.un.org/Depts/DGACM/index_spanish.htm 错误: 不能找到高于这一附录的正确供应商。

我正在发现这一错误,即供应商在目前的道路或环境中找不到。 而现在,以下的法典将处以罚款。 我作出的唯一改动是,在创建供应商方法时写“文字”而不是“......”:

www.un.org/Depts/DGACM/index_spanish.htm (c) 创建:

www.un.org/Depts/DGACM/index_spanish.htm Correct Code

class AppWrapper extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiRepositoryProvider(
      providers: [RepositoryProvider<AuthRepository>(create: (_) => AuthRepository())],
      child: MaterialApp(
        title:  Pokedex App ,
        theme: themeData,
        home: MultiBlocProvider(
          providers: [
            BlocProvider<AuthBloc>(
              create: (_) => AuthBloc(
                authRepository: context.read<AuthRepository>(),
              ),
            ),
            BlocProvider(
              create: (_) => LoginCubit(
                authRepository: context.read<AuthRepository>(),
              ),
            ),
            BlocProvider(
              create: (_) => SignupCubit(
                authRepository: context.read<AuthRepository>(),
              ),
            ),
          ],
          child: SignupScreen(),
        ),
      ),
    );
  }
}




相关问题
Mock testing with Repository pattern example

I m refactoring existing class to support Products import from CSV file.   Requirements: 1) during import products are identified by special product number. 2) product has category attribute. ...

Entity Framework using Generic Predicates

I use DTO s to map between my Business and Entity Framework layer via the Repository Pattern. A Standard call would look like public IClassDTO Fetch(Guid id) { var query = from s in _db.Base....

Create, Approve, Edit, Approve pattern for site content

I m working on a modification to a site to allowing users to enter content. However, once they ve created that content it needs to be approved before it can be published. This is fairly easy to ...

Repository + NHibernate + DTO

I have an application with a repository layer (and a nhibernate implementation), service (bussiness) layer, and an asp.net mvc in the web layer. Because I also need to create a small silverlight ...

Organizing classes using the repository design pattern

I have started upgrading one of our internal software applications, written in ASP.NET Web Forms, and moving to ASP.NET MVC. I am trying to leverage the Repository design pattern for my classes, ...