0

I have widget (FirstWidget) and 2 providers to this widget on 2 different pages.

First screen:

BlocProvider<FirstBloc>(
   create: (context) => FirstBloc()
   child: FirstWidget(),
)

Second screen:

BlocProvider<SecondBloc>(
   create: (context) => SecondBloc()
   child: FirstWidget(),
)

How to manage specific bloc in this widget using e.g. blocbuilder?

For example on first screen I wanna use in this widget FirstBloc and on second screen SecondBloc but this widget is in one file. What should i write in BlocBuilder? I tried BlocBuilder<dynamic, dynamic> but its not working.

user18084770
  • 31
  • 1
  • 3

2 Answers2

0

You could create two widgets. One wich uses BlocBuilder<FirstBloc, FirstState> and a second widget, which uses BlocBuilder<SecondBloc, SecondState>.

You could also pull the BlocBuilder out of the widget and pass some values into the widget in order to build it dependently.

Tim Brückner
  • 1,928
  • 2
  • 16
  • 27
0

Try this:

return MultiBlocProvider(
      providers: [
        
BlocProvider<FirstBloc>(
   create: (context) => FirstBloc(),
BlocProvider<SecondBloc>(
   create: (context) => SecondBloc()
   
),
child: FirstWidget(),
      ],)
Harsh Sureja
  • 1,052
  • 1
  • 9
  • 22