From a52f2c0b5aa2309236d2ec8ddc2b9e3b38c515d3 Mon Sep 17 00:00:00 2001 From: Mohammad Salameh Date: Tue, 19 Mar 2024 15:17:40 +0300 Subject: [PATCH] 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. --- lib/features/devices/bloc/devices_cubit.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/features/devices/bloc/devices_cubit.dart b/lib/features/devices/bloc/devices_cubit.dart index 2f3c7e1..cebe17e 100644 --- a/lib/features/devices/bloc/devices_cubit.dart +++ b/lib/features/devices/bloc/devices_cubit.dart @@ -24,6 +24,13 @@ class DevicesCubit extends Cubit { DevicesCubit() : super(DevicesInitial()) { fetchGroups(SpacesCubit.selectedSpace!.id!); } + bool _isClosed = false; + + @override + Future close() { + _isClosed = true; + return super.close(); + } static DevicesCubit get(context) => BlocProvider.of(context); @@ -229,6 +236,8 @@ class DevicesCubit extends Cubit { } fetchGroups(int spaceId) async { + if (_isClosed) return; + try { emit(DevicesCategoriesLoading()); allCategories = await DevicesAPI.fetchGroups(spaceId);