update
feat(api_service): Update try-catch funtion and handle exception update(loading_animation): Update loading animation using Lottie
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
import '../feature/devices/device_model.dart';
|
||||
import '../product/base/bloc/base_bloc.dart';
|
||||
import '../product/constant/app/app_constants.dart';
|
||||
import '../product/services/api_services.dart';
|
||||
|
||||
import '../product/shared/shared_snack_bar.dart';
|
||||
import '../product/utils/device_utils.dart';
|
||||
|
||||
class DevicesManagerBloc extends BlocBase {
|
||||
@@ -73,31 +76,27 @@ class DevicesManagerBloc extends BlocBase {
|
||||
// }
|
||||
// }
|
||||
|
||||
void getDeviceByState(int state) async {
|
||||
sinkTagStates.add([state]);
|
||||
void getDeviceByState(BuildContext context,int state) async {
|
||||
try {
|
||||
sinkTagStates.add([state]);
|
||||
|
||||
Map<String, List<Device>> deviceByState = {
|
||||
ApplicationConstants.OFFLINE_STATE: [],
|
||||
ApplicationConstants.NORMAL_STATE: [],
|
||||
ApplicationConstants.WARNING_STATE: [],
|
||||
ApplicationConstants.INPROGRESS_STATE: [],
|
||||
ApplicationConstants.ERROR_STATE: [],
|
||||
};
|
||||
Map<String, List<Device>> deviceByState = {
|
||||
ApplicationConstants.OFFLINE_STATE: [],
|
||||
ApplicationConstants.NORMAL_STATE: [],
|
||||
ApplicationConstants.WARNING_STATE: [],
|
||||
ApplicationConstants.INPROGRESS_STATE: [],
|
||||
ApplicationConstants.ERROR_STATE: [],
|
||||
};
|
||||
|
||||
List<Device> devices = [];
|
||||
String body;
|
||||
List<Device> devices = [];
|
||||
List<Device> originalDevices = [];
|
||||
if (state != -2) {
|
||||
originalDevices =
|
||||
await apiServices.getOwnerDeviceByState({"state": state.toString()});
|
||||
} else {
|
||||
originalDevices = await apiServices.getOwnerDevices();
|
||||
}
|
||||
|
||||
if (state != -2) {
|
||||
body =
|
||||
await apiServices.getOwnerDeviceByState({"state": state.toString()});
|
||||
} else {
|
||||
body = await apiServices.getOwnerDevices();
|
||||
}
|
||||
|
||||
if (body.isNotEmpty) {
|
||||
final data = jsonDecode(body);
|
||||
List<dynamic> items = data['items'];
|
||||
List<Device> originalDevices = Device.fromJsonDynamicList(items);
|
||||
List<Device> publicDevices = [];
|
||||
|
||||
for(var device in originalDevices){
|
||||
@@ -116,9 +115,14 @@ class DevicesManagerBloc extends BlocBase {
|
||||
}
|
||||
sinkDeviceByState.add(deviceByState);
|
||||
}
|
||||
|
||||
sinkAllDevices.add(devices);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
sinkAllDevices.add(devices);
|
||||
}
|
||||
|
||||
String _getStateKey(int state) {
|
||||
|
||||
Reference in New Issue
Block a user