如何根据CUBIT的flutter响应第一个响应来进行第二个API呼叫?
第一个呼叫我必须从第一个API获取值的值列表,以进行第二个API调用。如何将数据更新为UI。我有两个listViews一个用于从第一个API加载,第二个listView是
在第一个API ListView2获得响应后获得的第二个API,获得了异常。由于状态不是设施量下载
我的代码下方的。我想念什么?
_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;
},
),
)
);}
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;
},
),
)
);}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论