Bloc: BlocProvider.value not working in MultiBlocProvider

Created on 2 Jan 2020  路  1Comment  路  Source: felangel/bloc

Describe the bug
When showing a dialog and sharing the old bloc with the new context tree, it will work correctly when using BlocProvider.value, but not when including it in MultiBlocProvider.

To Reproduce
Works:

showDialog(
        context: context,
        builder: (_) {
          return BlocProvider.value(
              value: BlocProvider.of<A>(context),
              child: MultiBlocProvider(providers: <BlocProvider>[
                BlocProvider<B>(
                  create: (BuildContext context) => B(),
                ),
                BlocProvider<C>(
                  create: (BuildContext context) => C()
              ], child: S()));
        });

Not working:

    showDialog(
        context: context,
        builder: (_) {
          return MultiBlocProvider(providers: <BlocProvider>[
              BlocProvider.value(
                value: BlocProvider.of<A>(context)),
              BlocProvider<B>(
                create: (BuildContext context) => B(),
              ),
              BlocProvider<C>(
                create: (BuildContext context) => C()
              ], child: S()));
        });
question

Most helpful comment

Hi @polivmi1 馃憢
Thanks for opening an issue!

When using MultiBlocProvider you just explicitly specify the bloc type

BlocProvider<B>.value(...)

Hope that helps 馃憤

>All comments

Hi @polivmi1 馃憢
Thanks for opening an issue!

When using MultiBlocProvider you just explicitly specify the bloc type

BlocProvider<B>.value(...)

Hope that helps 馃憤

Was this page helpful?
0 / 5 - 0 ratings