如何根据CUBIT的flutter响应第一个响应来进行第二个API呼叫?

发布于 2025-01-18 10:16:49 字数 2418 浏览 4 评论 0原文

第一个呼叫我必须从第一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文