i have a cubit that has more than 2 lists, as follows
class HomeCubit extends Cubit<HomeState> {
final HomeRepository homeRepository;
HomeCubit(
this.homeRepository,
) : super(HomeInitial());
List<SubCatModal> mySubCat = [];
List<SubCatModal> subCat() {
emit(HomeLoaded());
homeRepository.getSubCatRepository().then((respone) {
emit(HomeSubCatSuccessCase(subCatList: respone));
mySubCat = respone;
});
return mySubCat;
}
List<FirstSlideModal> myFirstSlider = [];
List<FirstSlideModal> sliderListCubit() {
emit(HomeLoaded());
homeRepository.getFirstSliderRepository().then((respone) {
try {
emit(HomeFirstSliderSuccessCase(firstSliderList: respone));
} catch (e) {
emit(HomeErrorCase(message: respone));
}
myFirstSlider = respone;
});
return myFirstSlider;
}
}
and in the app route, I use the following
case Routes.homeScreen:
return MaterialPageRoute(
builder: (_) => BlocProvider(
create: (BuildContext context) =>
HomeCubit(HomeRepository(homeApi: HomeApi())),
child: const Homepage(),
),
);
and I call the cubit by using
void initState() {
super.initState();
var subCubit = BlocProvider.of<HomeCubit>(context).subCat();
}
so how can I build a multi bloc builder for each myFirstSlider and subCat in the UI through one cubit
short answer - no way. you don't need multi bloc builder. moreover, if you thinking this way then there is something you don't get clear enough.
anyway, you shouldn't hold lists in cubit. they should be in state, that should be equatable or freezed e.g.:
You can pass repos to your cubit:
one more potential problem here that you create your cubit in router. more clear:
where
Homepageis:then you use BlocBulder for whole screen or just for one widget, that need this data: