1 year ago
#368662
kumar
Flutter Cubit Listener Listview data not refreshing when button pressed?
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;
},
),
)
flutter
dart
flutter-layout
bloc
flutter-cubit
0 Answers
Your Answer