Add close method override in DevicesCubit

Add override for close method in DevicesCubit to set _isClosed flag and call super.close(). This prevents further operations after closing.
This commit is contained in:
Mohammad Salameh
2024-03-19 15:17:40 +03:00
parent d4a9cfb7ab
commit a52f2c0b5a
@@ -24,6 +24,13 @@ class DevicesCubit extends Cubit<DevicesState> {
DevicesCubit() : super(DevicesInitial()) {
fetchGroups(SpacesCubit.selectedSpace!.id!);
}
bool _isClosed = false;
@override
Future<void> close() {
_isClosed = true;
return super.close();
}
static DevicesCubit get(context) => BlocProvider.of(context);
@@ -229,6 +236,8 @@ class DevicesCubit extends Cubit<DevicesState> {
}
fetchGroups(int spaceId) async {
if (_isClosed) return;
try {
emit(DevicesCategoriesLoading());
allCategories = await DevicesAPI.fetchGroups(spaceId);