mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
removed try catch
This commit is contained in:
@ -76,19 +76,24 @@ class SpaceManagementBloc
|
||||
|
||||
Future<List<SpaceTemplateModel>> fetchSpaceModels(
|
||||
SpaceManagementState previousState) async {
|
||||
List<SpaceTemplateModel> prevSpaceModels = [];
|
||||
try {
|
||||
List<SpaceTemplateModel> prevSpaceModels = [];
|
||||
|
||||
if (previousState is SpaceManagementLoaded || previousState is BlankState) {
|
||||
prevSpaceModels = List<SpaceTemplateModel>.from(
|
||||
(previousState as dynamic).spaceModels ?? [],
|
||||
);
|
||||
if (previousState is SpaceManagementLoaded ||
|
||||
previousState is BlankState) {
|
||||
prevSpaceModels = List<SpaceTemplateModel>.from(
|
||||
(previousState as dynamic).spaceModels ?? [],
|
||||
);
|
||||
}
|
||||
|
||||
if (prevSpaceModels.isEmpty) {
|
||||
prevSpaceModels = await _spaceModelApi.listSpaceModels(page: 1);
|
||||
}
|
||||
|
||||
return prevSpaceModels;
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (prevSpaceModels.isEmpty) {
|
||||
prevSpaceModels = await _spaceModelApi.listSpaceModels(page: 1);
|
||||
}
|
||||
|
||||
return prevSpaceModels;
|
||||
}
|
||||
|
||||
void _onloadProducts() async {
|
||||
@ -184,6 +189,7 @@ class SpaceManagementBloc
|
||||
LoadCommunityAndSpacesEvent event,
|
||||
Emitter<SpaceManagementState> emit,
|
||||
) async {
|
||||
var prevState = state;
|
||||
emit(SpaceManagementLoading());
|
||||
try {
|
||||
_onloadProducts();
|
||||
@ -205,12 +211,11 @@ class SpaceManagementBloc
|
||||
}).toList(),
|
||||
);
|
||||
|
||||
List<SpaceTemplateModel> spaceModels =
|
||||
await _spaceModelApi.listSpaceModels(page: 1);
|
||||
final prevSpaceModels = await fetchSpaceModels(prevState);
|
||||
emit(SpaceManagementLoaded(
|
||||
communities: updatedCommunities,
|
||||
products: _cachedProducts ?? [],
|
||||
spaceModels: spaceModels));
|
||||
spaceModels: prevSpaceModels));
|
||||
} catch (e) {
|
||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
||||
}
|
||||
@ -487,6 +492,8 @@ class SpaceManagementBloc
|
||||
SpaceModelLoadEvent event, Emitter<SpaceManagementState> emit) async {
|
||||
emit(SpaceManagementLoading());
|
||||
try {
|
||||
var prevState = state;
|
||||
|
||||
List<CommunityModel> communities = await _api.fetchCommunities();
|
||||
|
||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||
@ -505,12 +512,12 @@ class SpaceManagementBloc
|
||||
}).toList(),
|
||||
);
|
||||
|
||||
List<SpaceTemplateModel> spaceModels =
|
||||
await _spaceModelApi.listSpaceModels(page: 1);
|
||||
var prevSpaceModels = await fetchSpaceModels(prevState);
|
||||
|
||||
emit(SpaceModelLoaded(
|
||||
communities: updatedCommunities,
|
||||
products: _cachedProducts ?? [],
|
||||
spaceModels: spaceModels));
|
||||
spaceModels: prevSpaceModels));
|
||||
} catch (e) {
|
||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
||||
}
|
||||
|
Reference in New Issue
Block a user