Flutter Cubit Listener Listview 数据在按下按钮时不刷新?
我有两个listViews是水平的,当我单击“水平列表视图”按钮以获取API的数据并在垂直列表视图中更新值时,另一个是垂直的。
这里正在发生API调用,但值未更新ListView和Cubit中未显示的进度栏。
我已经在侦听器Bool变量IS Lifate IS Loading中使用了默认情况下。当Tap上发生在水平列表视图IS Loading集合中时,请设置为true。
OnInitState我使用了
setState(() {
isLoading;
stypeunits;
});
集团消费者和听众代码
BlocProvider.value(
value: _unitBookingCubit,
child: BlocConsumer<UnitBookingCubit,UnitBookingState>(
builder: (context, state) {
if (state is UnitBookingLoading) {
return Loading();
} else if (state is ErrorState) {
return ErrorTxt(
message: '${state.error}',
ontap: () => _loadstoragetype(),
);
}
if (state is FacilityUnitTypeload) {
if (state.storageTypeModel.isSuccess!) {
stypeunits=state.storageTypeUnits?.result!;
return buildunitWidgets(storagetypelist:state.storageTypeModel.result);
} else {
return Container(
height: double.infinity,
child: Center(
child: textStyle(
text: state.storageTypeModel.returnMessage!,
style: TextStyles.subTitle2,
)),
);
}
}
if (state is FacilityUnitsload) {
print('Unitsloaded buil');
if (state.storageTypeUnits.isSuccess!) {
print('Unitsloaded1');
stypeunits=state.storageTypeUnits.result;
return buildunitWidgets();
} else {
return Container(
height: double.infinity,
child: Center(
child: textStyle(
text: state.storageTypeUnits.returnMessage!,
style: TextStyles.subTitle2,
)),
);
}
}
return buildunitWidgets();
},
listener: (context, state) {
if (state is UnitBookingLoading) {
isLoading=true;
}
if (state is FacilityUnitsload) {
print('Unitsloaded');
if (state.storageTypeUnits.isSuccess!) {
print('Unitsloaded1');
stypeunits=state.storageTypeUnits.result!;
print('Unitsloaded1${stypeunits?.length}');
isLoading=false;
}
}
},
buildWhen: (context, state) {
return state is FacilityUnitTypeload;
},
),
)
I have two listviews one is horizontal the other is vertical when I click on the horizontal listview button to fetch the data from API and update the value in the vertical listview.
Here API call is happening but values not updating in listview and the progress bar not showing in a cubit.
I have used inside listener bool variable isloading by default false.when on tap is happened in horizontal listview isloading set as true.
oninitState i have used
setState(() {
isLoading;
stypeunits;
});
bloc consumer and listener code
BlocProvider.value(
value: _unitBookingCubit,
child: BlocConsumer<UnitBookingCubit,UnitBookingState>(
builder: (context, state) {
if (state is UnitBookingLoading) {
return Loading();
} else if (state is ErrorState) {
return ErrorTxt(
message: '${state.error}',
ontap: () => _loadstoragetype(),
);
}
if (state is FacilityUnitTypeload) {
if (state.storageTypeModel.isSuccess!) {
stypeunits=state.storageTypeUnits?.result!;
return buildunitWidgets(storagetypelist:state.storageTypeModel.result);
} else {
return Container(
height: double.infinity,
child: Center(
child: textStyle(
text: state.storageTypeModel.returnMessage!,
style: TextStyles.subTitle2,
)),
);
}
}
if (state is FacilityUnitsload) {
print('Unitsloaded buil');
if (state.storageTypeUnits.isSuccess!) {
print('Unitsloaded1');
stypeunits=state.storageTypeUnits.result;
return buildunitWidgets();
} else {
return Container(
height: double.infinity,
child: Center(
child: textStyle(
text: state.storageTypeUnits.returnMessage!,
style: TextStyles.subTitle2,
)),
);
}
}
return buildunitWidgets();
},
listener: (context, state) {
if (state is UnitBookingLoading) {
isLoading=true;
}
if (state is FacilityUnitsload) {
print('Unitsloaded');
if (state.storageTypeUnits.isSuccess!) {
print('Unitsloaded1');
stypeunits=state.storageTypeUnits.result!;
print('Unitsloaded1${stypeunits?.length}');
isLoading=false;
}
}
},
buildWhen: (context, state) {
return state is FacilityUnitTypeload;
},
),
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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