Update
Logging data Try-catch function
This commit is contained in:
@@ -1,13 +1,10 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.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/date_time_utils.dart';
|
||||
|
||||
import '../product/utils/device_utils.dart';
|
||||
@@ -39,15 +36,12 @@ class DeviceLogsBloc extends BlocBase {
|
||||
void dispose() {}
|
||||
|
||||
void getAllDevices(BuildContext context) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
List<Device> originalDevices = await apiServices.getOwnerDevices();
|
||||
List<Device> devices =
|
||||
DeviceUtils.instance.sortDeviceByState(originalDevices);
|
||||
sinkAllDevices.add(devices);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void getDeviceLogByThingID(
|
||||
@@ -57,7 +51,7 @@ class DeviceLogsBloc extends BlocBase {
|
||||
DateTime fromDate,
|
||||
List<SensorLogs> sensors,
|
||||
) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
sinkmessage.add(ApplicationConstants.LOADING);
|
||||
String fromDateString =
|
||||
DateTimeUtils.instance.formatDateTimeToString(fromDate);
|
||||
@@ -85,9 +79,38 @@ class DeviceLogsBloc extends BlocBase {
|
||||
sinkmessage.add(ApplicationConstants.NO_DATA);
|
||||
}
|
||||
sinkSensors.add(sensors);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// sinkmessage.add(ApplicationConstants.LOADING);
|
||||
// String fromDateString =
|
||||
// DateTimeUtils.instance.formatDateTimeToString(fromDate);
|
||||
// String now =
|
||||
// DateTimeUtils.instance.formatDateTimeToString(DateTime.now());
|
||||
// Map<String, dynamic> params = {
|
||||
// 'thing_id': thingID,
|
||||
// 'from': fromDateString,
|
||||
// 'to': now,
|
||||
// 'limit': '30',
|
||||
// "offset": offset.toString(),
|
||||
// "asc": "true"
|
||||
// };
|
||||
// DeviceLog devicesListLog =
|
||||
// await apiServices.getLogsOfDevice(thingID, params);
|
||||
// if (devicesListLog.sensors!.isEmpty) {
|
||||
// bool hasMore = false;
|
||||
// sinkHasMore.add(hasMore);
|
||||
// }
|
||||
// if (devicesListLog.sensors!.isNotEmpty) {
|
||||
// for (var sensor in devicesListLog.sensors!) {
|
||||
// sensors.add(sensor);
|
||||
// }
|
||||
// } else {
|
||||
// sinkmessage.add(ApplicationConstants.NO_DATA);
|
||||
// }
|
||||
// sinkSensors.add(sensors);
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user