There is a problem with the first call I have to get the value list of values from the first API to make a second API call. how do update the data to UI. I have two listviews one is for loading from the first API and the second listview is for the second API
After getting a response from the first API listview2 gets a null value getting an exception. because the state is not emitted of FacilityUnitsload
My code is below. What am I missing?
_loadstoragetype(){_bookingCubit.facilitystoragetype());}
_loadfacilityunits(){ _bookingCubit.facilitystorageunits(jsonEncode(
StoragetypeunitsRequest(storagetypelist,locationlist))); }
@override
void didChangeDependencies() {
_loadstoragetype();
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return
MultiBlocProvider(
providers: [
BlocProvider<BookingCubit>.value(value: _bookingCubit),
],
child: Scaffold(
body: BlocProvider.value(
value: _bookingCubit,
child: BlocConsumer<BookingCubit,BookingState>(
builder: (context, state) {
if (state is BookingLoading) {
return Loading();
} else if (state is ErrorState) {
return ErrorTxt(
message: '${state.error}',
ontap: () => _loadtype(),
);
}
if (state is FacilityUnitTypeload) {
if (state.storageTypeModel.isSuccess!) {
_loadfacilityunits();
return ListView.builder(
itemCount: storagetypelist?.length,
scrollDirection: Axis.horizontal,
itemBuilder: (BuildContext context, int index) {
return GestureDetector(
onTap: () => '',
child:Text('${storagetypelist[index].name}'),
);
},)
} else {
return Text('Error')
}
}
if (state is FacilityUnitsload) {
if (state.storageTypeUnits.isSuccess!) {
return Expanded(
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
itemCount: stypeunits.length,
itemBuilder: (BuildContext context, int index) {
return Text('${state.storageTypeUnits.result[index].name}'),
},
));
} else {
return Text('Error')
}
}
return //_buildbookunits();
},
listener: (context, state) {
},
buildWhen: (context, state) {
return state is FacilityUnitTypeload;
},
),
)
);}