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,9 +76,11 @@ class SpaceManagementBloc
|
|||||||
|
|
||||||
Future<List<SpaceTemplateModel>> fetchSpaceModels(
|
Future<List<SpaceTemplateModel>> fetchSpaceModels(
|
||||||
SpaceManagementState previousState) async {
|
SpaceManagementState previousState) async {
|
||||||
|
try {
|
||||||
List<SpaceTemplateModel> prevSpaceModels = [];
|
List<SpaceTemplateModel> prevSpaceModels = [];
|
||||||
|
|
||||||
if (previousState is SpaceManagementLoaded || previousState is BlankState) {
|
if (previousState is SpaceManagementLoaded ||
|
||||||
|
previousState is BlankState) {
|
||||||
prevSpaceModels = List<SpaceTemplateModel>.from(
|
prevSpaceModels = List<SpaceTemplateModel>.from(
|
||||||
(previousState as dynamic).spaceModels ?? [],
|
(previousState as dynamic).spaceModels ?? [],
|
||||||
);
|
);
|
||||||
@ -89,6 +91,9 @@ class SpaceManagementBloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
return prevSpaceModels;
|
return prevSpaceModels;
|
||||||
|
} catch (e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onloadProducts() async {
|
void _onloadProducts() async {
|
||||||
@ -184,6 +189,7 @@ class SpaceManagementBloc
|
|||||||
LoadCommunityAndSpacesEvent event,
|
LoadCommunityAndSpacesEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
) async {
|
) async {
|
||||||
|
var prevState = state;
|
||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
try {
|
try {
|
||||||
_onloadProducts();
|
_onloadProducts();
|
||||||
@ -205,12 +211,11 @@ class SpaceManagementBloc
|
|||||||
}).toList(),
|
}).toList(),
|
||||||
);
|
);
|
||||||
|
|
||||||
List<SpaceTemplateModel> spaceModels =
|
final prevSpaceModels = await fetchSpaceModels(prevState);
|
||||||
await _spaceModelApi.listSpaceModels(page: 1);
|
|
||||||
emit(SpaceManagementLoaded(
|
emit(SpaceManagementLoaded(
|
||||||
communities: updatedCommunities,
|
communities: updatedCommunities,
|
||||||
products: _cachedProducts ?? [],
|
products: _cachedProducts ?? [],
|
||||||
spaceModels: spaceModels));
|
spaceModels: prevSpaceModels));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
||||||
}
|
}
|
||||||
@ -487,6 +492,8 @@ class SpaceManagementBloc
|
|||||||
SpaceModelLoadEvent event, Emitter<SpaceManagementState> emit) async {
|
SpaceModelLoadEvent event, Emitter<SpaceManagementState> emit) async {
|
||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
try {
|
try {
|
||||||
|
var prevState = state;
|
||||||
|
|
||||||
List<CommunityModel> communities = await _api.fetchCommunities();
|
List<CommunityModel> communities = await _api.fetchCommunities();
|
||||||
|
|
||||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||||
@ -505,12 +512,12 @@ class SpaceManagementBloc
|
|||||||
}).toList(),
|
}).toList(),
|
||||||
);
|
);
|
||||||
|
|
||||||
List<SpaceTemplateModel> spaceModels =
|
var prevSpaceModels = await fetchSpaceModels(prevState);
|
||||||
await _spaceModelApi.listSpaceModels(page: 1);
|
|
||||||
emit(SpaceModelLoaded(
|
emit(SpaceModelLoaded(
|
||||||
communities: updatedCommunities,
|
communities: updatedCommunities,
|
||||||
products: _cachedProducts ?? [],
|
products: _cachedProducts ?? [],
|
||||||
spaceModels: spaceModels));
|
spaceModels: prevSpaceModels));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@ import 'package:syncrow_web/utils/constants/temp_const.dart';
|
|||||||
|
|
||||||
class SpaceModelManagementApi {
|
class SpaceModelManagementApi {
|
||||||
Future<List<SpaceTemplateModel>> listSpaceModels({int page = 1}) async {
|
Future<List<SpaceTemplateModel>> listSpaceModels({int page = 1}) async {
|
||||||
try {
|
|
||||||
List<SpaceTemplateModel> spaceModels = [];
|
List<SpaceTemplateModel> spaceModels = [];
|
||||||
bool hasNext = true;
|
bool hasNext = true;
|
||||||
while (hasNext) {
|
while (hasNext) {
|
||||||
@ -30,15 +29,10 @@ class SpaceModelManagementApi {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return spaceModels;
|
return spaceModels;
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Error fetching space models: $e');
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<SpaceTemplateModel?> createSpaceModel(
|
Future<SpaceTemplateModel?> createSpaceModel(
|
||||||
CreateSpaceTemplateBodyModel spaceModel) async {
|
CreateSpaceTemplateBodyModel spaceModel) async {
|
||||||
try {
|
|
||||||
final response = await HTTPService().post(
|
final response = await HTTPService().post(
|
||||||
path: ApiEndpoints.createSpaceModel
|
path: ApiEndpoints.createSpaceModel
|
||||||
.replaceAll('{projectId}', TempConst.projectId),
|
.replaceAll('{projectId}', TempConst.projectId),
|
||||||
@ -49,29 +43,18 @@ class SpaceModelManagementApi {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Error creating space model: $e');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<SpaceTemplateModel?> getSpaceModel(String spaceModelUuid) async {
|
Future<SpaceTemplateModel?> getSpaceModel(String spaceModelUuid) async {
|
||||||
try {
|
|
||||||
final response = await HTTPService().get(
|
final response = await HTTPService().get(
|
||||||
path: ApiEndpoints.getSpaceModel
|
path: ApiEndpoints.getSpaceModel
|
||||||
.replaceAll('{projectId}', TempConst.projectId)
|
.replaceAll('{projectId}', TempConst.projectId)
|
||||||
.replaceAll('{spaceModelUuid}', spaceModelUuid),
|
.replaceAll('{spaceModelUuid}', spaceModelUuid),
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
debugPrint('Response JSON: $json');
|
|
||||||
|
|
||||||
return SpaceTemplateModel.fromJson(json['data']);
|
return SpaceTemplateModel.fromJson(json['data']);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
|
||||||
debugPrint('Error getting space model: $e');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user