当我在集团内部使用提供程序时,我的模拟器卡住了

问题描述 投票:0回答:1

我正在 flutter 中制作一个页面。我创建了 bloc,然后致电提供者。在主页我的代码中,我设计了一个 4 阶段的广告发布屏幕,我将从每个屏幕获得的值分配给changenotifier。

我用块状态指定了这些阶段,我从最后一个状态的提供者那里获取值并将它们发送到 firebase,事实上,我做了一些尝试,我的代码正在运行,然后今天我编辑我的文件夹,文件夹命名文件名和文件夹结构,当我单击该页面时,我遇到问题,我的模拟器卡住了,屏幕上没有任何反应。然后我正在做热重启调试控制台说

return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MultiBlocProvider(
        providers: [
          BlocProvider<RegisterCubit>(
            create: (BuildContext context) => RegisterCubit(),
          ),
          BlocProvider<SignInCubit>(
            create: (BuildContext context) => SignInCubit(),
          ),
          ChangeNotifierProvider<ListingProvider>(
            create: (BuildContext context) => ListingProvider(),
          ),
          BlocProvider<PostAdBloc>(
            create: (BuildContext context) => PostAdBloc(context.read<ListingProvider>()),
          ),
        ],
        child: MainPage(),
      ) 
 ═╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following ProviderNotFoundException was thrown building PostAdPage:
Error: Could not find the correct Provider<PostAdBloc> above this BlocConsumer<PostAdBloc,
PostAdStates> Widget

This happens because you used a `BuildContext` that does not include the provider
of your choice. There are a few common scenarios:

- You added a new provider in your `main.dart` and performed a hot-reload.
  To fix, perform a hot-restart.

- The provider you are trying to read is in a different route.

  Providers are "scoped". So if you insert of provider inside a route, then
  other routes will not be able to access that provider.

- You used a `BuildContext` that is an ancestor of the provider you are trying to read.

  Make sure that BlocConsumer<PostAdBloc, PostAdStates> is under your
MultiProvider/Provider<PostAdBloc>.
  This usually happens when you are creating a provider and trying to read it immediately.

我的代码运行得不太好,我只是更改了一些文件夹结构等

我尝试热重启重编辑。我的逻辑就像我尝试设计帖子广告页面一样,我设计了一个 4 阶段名称共享屏幕,我将从每个屏幕获得的值分配给 Changenotifier。我用 blockta 状态指定了这些阶段,我从最后一个状态的提供者那里获取值并将它们发送到 firebase,事实上,我做了一些尝试,我的代码正在工作

flutter bloc provider
1个回答
0
投票

MultiProvider
中的提供者似乎不能相互依赖。你可以试试

Widget build(BuildContext context) {
    return ChangeNotifierProvider<ListingProvider>(
      create: (_) => ListingProvider(),
      child: MultiBlocProvider(
        providers: [
          BlocProvider<RegisterCubit>(
            create: (BuildContext context) => RegisterCubit(),
          ),
          BlocProvider<SignInCubit>(
            create: (BuildContext context) => SignInCubit(),
          ),
          BlocProvider<PostAdBloc>(
            create: (BuildContext context) =>
                PostAdBloc(context.read<ListingProvider>()),
          ),
        ],
        child: MaterialApp(),
      ),
    );
  }
© www.soinside.com 2019 - 2024. All rights reserved.