Update
Logging data Try-catch function
This commit is contained in:
@@ -4,7 +4,6 @@ import '../product/base/bloc/base_bloc.dart';
|
||||
import '../feature/bell/bell_model.dart';
|
||||
|
||||
class BellBloc extends BlocBase {
|
||||
|
||||
final bellItems = StreamController<List<BellItems>>.broadcast();
|
||||
StreamSink<List<BellItems>> get sinkBellItems => bellItems.sink;
|
||||
Stream<List<BellItems>> get streamBellItems => bellItems.stream;
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:sfm_app/product/services/api_services.dart';
|
||||
import 'package:sfm_app/product/utils/device_utils.dart';
|
||||
|
||||
import '../product/shared/shared_snack_bar.dart';
|
||||
import '../product/services/api_services.dart';
|
||||
import '../product/utils/date_time_utils.dart';
|
||||
import '../feature/device_log/device_logs_model.dart';
|
||||
import '../feature/devices/device_model.dart';
|
||||
|
||||
import '../product/base/bloc/base_bloc.dart';
|
||||
import '../product/utils/device_utils.dart';
|
||||
|
||||
class DetailDeviceBloc extends BlocBase {
|
||||
APIServices apiServices = APIServices();
|
||||
@@ -43,7 +40,7 @@ class DetailDeviceBloc extends BlocBase {
|
||||
String thingID,
|
||||
Completer<GoogleMapController> controller,
|
||||
) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
Device device = await apiServices.getDeviceInformation(thingID);
|
||||
sinkDeviceInfo.add(device);
|
||||
if (device.areaPath != null) {
|
||||
@@ -73,10 +70,41 @@ class DetailDeviceBloc extends BlocBase {
|
||||
mapController
|
||||
.animateCamera(CameraUpdate.newCameraPosition(cameraPosition));
|
||||
}
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// Device device = await apiServices.getDeviceInformation(thingID);
|
||||
// sinkDeviceInfo.add(device);
|
||||
// if (device.areaPath != null) {
|
||||
// String fullLocation = await DeviceUtils.instance
|
||||
// .getFullDeviceLocation(context, device.areaPath!, "");
|
||||
// log("Location: $fullLocation");
|
||||
// sinkDeviceLocation.add(fullLocation);
|
||||
// }
|
||||
// Map<String, dynamic> sensorMap = {};
|
||||
// if (device.status!.sensors != null) {
|
||||
// sensorMap = DeviceUtils.instance
|
||||
// .getDeviceSensors(context, device.status!.sensors!);
|
||||
// } else {
|
||||
// sensorMap = DeviceUtils.instance.getDeviceSensors(context, []);
|
||||
// }
|
||||
// sinkDeviceSensor.add(sensorMap);
|
||||
// if (device.settings!.latitude! != "" &&
|
||||
// device.settings!.longitude! != "") {
|
||||
// final CameraPosition cameraPosition = CameraPosition(
|
||||
// target: LatLng(
|
||||
// double.parse(device.settings!.latitude!),
|
||||
// double.parse(device.settings!.longitude!),
|
||||
// ),
|
||||
// zoom: 13,
|
||||
// );
|
||||
// final GoogleMapController mapController = await controller.future;
|
||||
// mapController
|
||||
// .animateCamera(CameraUpdate.newCameraPosition(cameraPosition));
|
||||
// }
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
}
|
||||
|
||||
void findLocation(BuildContext context, String areaPath) async {
|
||||
@@ -85,12 +113,13 @@ class DetailDeviceBloc extends BlocBase {
|
||||
sinkDeviceLocation.add(fullLocation);
|
||||
}
|
||||
|
||||
void getNearerSensorValue(BuildContext context,String thingID) async {
|
||||
try {
|
||||
void getNearerSensorValue(BuildContext context, String thingID) async {
|
||||
apiServices.execute(context, () async {
|
||||
List<SensorLogs> sensorTemps = [];
|
||||
DateTime twoDaysAgo = DateTime.now().subtract(const Duration(days: 2));
|
||||
String from = DateTimeUtils.instance.formatDateTimeToString(twoDaysAgo);
|
||||
String now = DateTimeUtils.instance.formatDateTimeToString(DateTime.now());
|
||||
String now =
|
||||
DateTimeUtils.instance.formatDateTimeToString(DateTime.now());
|
||||
Map<String, dynamic> params = {
|
||||
'thing_id': thingID,
|
||||
'from': from,
|
||||
@@ -98,7 +127,8 @@ class DetailDeviceBloc extends BlocBase {
|
||||
'limit': '100',
|
||||
'n': '7',
|
||||
};
|
||||
DeviceLog devicesListLog = await apiServices.getLogsOfDevice(thingID, params);
|
||||
DeviceLog devicesListLog =
|
||||
await apiServices.getLogsOfDevice(thingID, params);
|
||||
if (devicesListLog.sensors!.isNotEmpty) {
|
||||
for (var sensor in devicesListLog.sensors!) {
|
||||
sensorTemps.add(sensor);
|
||||
@@ -108,11 +138,35 @@ class DetailDeviceBloc extends BlocBase {
|
||||
} else {
|
||||
sinkSensorTemps.add([]);
|
||||
}
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
sinkSensorTemps.add([]);
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// List<SensorLogs> sensorTemps = [];
|
||||
// DateTime twoDaysAgo = DateTime.now().subtract(const Duration(days: 2));
|
||||
// String from = DateTimeUtils.instance.formatDateTimeToString(twoDaysAgo);
|
||||
// String now =
|
||||
// DateTimeUtils.instance.formatDateTimeToString(DateTime.now());
|
||||
// Map<String, dynamic> params = {
|
||||
// 'thing_id': thingID,
|
||||
// 'from': from,
|
||||
// 'to': now,
|
||||
// 'limit': '100',
|
||||
// 'n': '7',
|
||||
// };
|
||||
// DeviceLog devicesListLog =
|
||||
// await apiServices.getLogsOfDevice(thingID, params);
|
||||
// if (devicesListLog.sensors!.isNotEmpty) {
|
||||
// for (var sensor in devicesListLog.sensors!) {
|
||||
// sensorTemps.add(sensor);
|
||||
// }
|
||||
// sensorTemps = sensorTemps.reversed.toList();
|
||||
// sinkSensorTemps.add(sensorTemps);
|
||||
// } else {
|
||||
// sinkSensorTemps.add([]);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// sinkSensorTemps.add([]);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ class DeviceNotificationSettingsBloc extends BlocBase {
|
||||
StreamSink<String> get sinkMessageChange => messageChange.sink;
|
||||
Stream<String> get streaMmessageChange => messageChange.stream;
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../product/services/api_services.dart';
|
||||
import '../product/services/language_services.dart';
|
||||
import '../product/shared/model/ward_model.dart';
|
||||
import '../product/shared/shared_snack_bar.dart';
|
||||
import '../product/utils/response_status_utils.dart';
|
||||
|
||||
import '../product/shared/model/district_model.dart';
|
||||
import '../product/shared/model/province_model.dart';
|
||||
import '../feature/devices/device_model.dart';
|
||||
@@ -80,56 +80,42 @@ class DeviceUpdateBloc extends BlocBase {
|
||||
List<DropdownMenuItem<Province>> provincesData = [];
|
||||
provincesData.clear();
|
||||
sinkListProvinces.add(provincesData);
|
||||
try {
|
||||
List<Province> provinces = await apiServices.getAllProvinces();
|
||||
await apiServices.execute(context, () async {
|
||||
List<Province> provinces = await apiServices.getAllProvinces();
|
||||
for (var province in provinces) {
|
||||
provincesData.add(
|
||||
DropdownMenuItem(value: province, child: Text(province.fullName!)));
|
||||
}
|
||||
sinkListProvinces.add(provincesData);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getAllDistricts(BuildContext context, String provinceID) async {
|
||||
List<DropdownMenuItem<District>> districtsData = [];
|
||||
districtsData.clear();
|
||||
sinkListDistricts.add(districtsData);
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
final districts = await apiServices.getAllDistricts(provinceID);
|
||||
for (var district in districts) {
|
||||
districtsData.add(
|
||||
DropdownMenuItem(value: district, child: Text(district.fullName!)));
|
||||
}
|
||||
sinkListDistricts.add(districtsData);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getAllWards(BuildContext context, String districtID) async {
|
||||
List<DropdownMenuItem<Ward>> wardsData = [];
|
||||
wardsData.clear();
|
||||
sinkListWards.add(wardsData);
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
final wards = await apiServices.getAllWards(districtID);
|
||||
for (var ward in wards) {
|
||||
wardsData.add(DropdownMenuItem(value: ward, child: Text(ward.fullName!)));
|
||||
wardsData
|
||||
.add(DropdownMenuItem(value: ward, child: Text(ward.fullName!)));
|
||||
}
|
||||
sinkListWards.add(wardsData);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> getDeviceInformation(
|
||||
@@ -138,7 +124,7 @@ class DeviceUpdateBloc extends BlocBase {
|
||||
TextEditingController deviceNameController,
|
||||
TextEditingController latitudeController,
|
||||
TextEditingController longitudeController) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
Device device = await apiServices.getDeviceInformation(thingID);
|
||||
sinkDeviceInfo.add(device);
|
||||
deviceNameController.text = device.name ?? "";
|
||||
@@ -155,23 +141,24 @@ class DeviceUpdateBloc extends BlocBase {
|
||||
String wardCode = areaPath[2];
|
||||
|
||||
// Kiểm tra các mã có hợp lệ không (không rỗng)
|
||||
if (provinceCode.isNotEmpty && districtCode.isNotEmpty && wardCode.isNotEmpty) {
|
||||
if (provinceCode.isNotEmpty &&
|
||||
districtCode.isNotEmpty &&
|
||||
wardCode.isNotEmpty) {
|
||||
try {
|
||||
// Lấy danh sách districts và wards
|
||||
await getAllDistricts(context,provinceCode);
|
||||
await getAllWards(context,districtCode);
|
||||
await getAllDistricts(context, provinceCode);
|
||||
await getAllWards(context, districtCode);
|
||||
|
||||
// Xử lý Province
|
||||
try {
|
||||
Province province = await apiServices.getProvinceByID(provinceCode);
|
||||
Map<String, String> provinceData = {
|
||||
"name": province.fullName ?? "Unknown Province",
|
||||
"code": province.code ?? provinceCode
|
||||
};
|
||||
sinkProvinceData.add(provinceData);
|
||||
|
||||
Province province =
|
||||
await apiServices.getProvinceByID(provinceCode);
|
||||
Map<String, String> provinceData = {
|
||||
"name": province.fullName ?? "Unknown Province",
|
||||
"code": province.code ?? provinceCode
|
||||
};
|
||||
sinkProvinceData.add(provinceData);
|
||||
} catch (e) {
|
||||
|
||||
// Thêm dữ liệu mặc định khi lỗi
|
||||
Map<String, String> provinceData = {
|
||||
"name": "Error Loading Province",
|
||||
@@ -179,20 +166,20 @@ class DeviceUpdateBloc extends BlocBase {
|
||||
};
|
||||
sinkProvinceData.add(provinceData);
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
|
||||
// Xử lý District
|
||||
try {
|
||||
District district = await apiServices.getDistrictByID(districtCode);
|
||||
Map<String, String> districData = {
|
||||
"name": district.fullName ?? "Unknown District",
|
||||
"code": district.code ?? districtCode,
|
||||
};
|
||||
sinkDistrictData.add(districData);
|
||||
District district =
|
||||
await apiServices.getDistrictByID(districtCode);
|
||||
Map<String, String> districData = {
|
||||
"name": district.fullName ?? "Unknown District",
|
||||
"code": district.code ?? districtCode,
|
||||
};
|
||||
sinkDistrictData.add(districData);
|
||||
} catch (e) {
|
||||
print("Lỗi khi lấy thông tin district ($districtCode): $e");
|
||||
log("Lỗi khi lấy thông tin district ($districtCode): $e");
|
||||
Map<String, String> districData = {
|
||||
"name": "Error Loading District",
|
||||
"code": districtCode,
|
||||
@@ -202,84 +189,168 @@ class DeviceUpdateBloc extends BlocBase {
|
||||
|
||||
// Xử lý Ward
|
||||
try {
|
||||
Ward ward = await apiServices.getWardByID(wardCode);
|
||||
Map<String, String> wardMap = {
|
||||
"name": ward.fullName ?? "Unknown Ward",
|
||||
"code": ward.code ?? wardCode,
|
||||
};
|
||||
sinkWardData.add(wardMap);
|
||||
Ward ward = await apiServices.getWardByID(wardCode);
|
||||
Map<String, String> wardMap = {
|
||||
"name": ward.fullName ?? "Unknown Ward",
|
||||
"code": ward.code ?? wardCode,
|
||||
};
|
||||
sinkWardData.add(wardMap);
|
||||
} catch (e) {
|
||||
print("Lỗi khi lấy thông tin ward ($wardCode): $e");
|
||||
log("Lỗi khi lấy thông tin ward ($wardCode): $e");
|
||||
Map<String, String> wardMap = {
|
||||
"name": "Error Loading Ward",
|
||||
"code": wardCode,
|
||||
};
|
||||
sinkWardData.add(wardMap);
|
||||
}
|
||||
|
||||
} catch (e) {
|
||||
print("Lỗi khi gọi getAllDistricts hoặc getAllWards: $e");
|
||||
log("Lỗi khi gọi getAllDistricts hoặc getAllWards: $e");
|
||||
}
|
||||
} else {
|
||||
await getAllProvinces(context);
|
||||
print("Một hoặc nhiều mã địa phương trống: Province: $provinceCode, District: $districtCode, Ward: $wardCode");
|
||||
log("Một hoặc nhiều mã địa phương trống: Province: $provinceCode, District: $districtCode, Ward: $wardCode");
|
||||
}
|
||||
} else {
|
||||
showNoIconTopSnackBar(context,"AreaPath không đủ thông tin: ${device.areaPath}",Colors.orangeAccent, Colors.white);
|
||||
showNoIconTopSnackBar(
|
||||
context,
|
||||
"AreaPath không đủ thông tin: ${device.areaPath}",
|
||||
Colors.orangeAccent,
|
||||
Colors.white);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
showNoIconTopSnackBar(context,"Lỗi trong getDeviceInfomation: $e",Colors.orangeAccent, Colors.white);
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// Device device = await apiServices.getDeviceInformation(thingID);
|
||||
// sinkDeviceInfo.add(device);
|
||||
// deviceNameController.text = device.name ?? "";
|
||||
// latitudeController.text = device.settings!.latitude ?? "";
|
||||
// longitudeController.text = device.settings!.longitude ?? "";
|
||||
|
||||
// if (device.areaPath != null && device.areaPath!.isNotEmpty) {
|
||||
// List<String> areaPath = device.areaPath!.split('_');
|
||||
|
||||
// // Kiểm tra độ dài của areaPath
|
||||
// if (areaPath.length >= 3) {
|
||||
// String provinceCode = areaPath[0];
|
||||
// String districtCode = areaPath[1];
|
||||
// String wardCode = areaPath[2];
|
||||
|
||||
// // Kiểm tra các mã có hợp lệ không (không rỗng)
|
||||
// if (provinceCode.isNotEmpty &&
|
||||
// districtCode.isNotEmpty &&
|
||||
// wardCode.isNotEmpty) {
|
||||
// try {
|
||||
// // Lấy danh sách districts và wards
|
||||
// await getAllDistricts(context, provinceCode);
|
||||
// await getAllWards(context, districtCode);
|
||||
|
||||
// // Xử lý Province
|
||||
// try {
|
||||
// Province province =
|
||||
// await apiServices.getProvinceByID(provinceCode);
|
||||
// Map<String, String> provinceData = {
|
||||
// "name": province.fullName ?? "Unknown Province",
|
||||
// "code": province.code ?? provinceCode
|
||||
// };
|
||||
// sinkProvinceData.add(provinceData);
|
||||
// } catch (e) {
|
||||
// // Thêm dữ liệu mặc định khi lỗi
|
||||
// Map<String, String> provinceData = {
|
||||
// "name": "Error Loading Province",
|
||||
// "code": provinceCode
|
||||
// };
|
||||
// sinkProvinceData.add(provinceData);
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
|
||||
// // Xử lý District
|
||||
// try {
|
||||
// District district =
|
||||
// await apiServices.getDistrictByID(districtCode);
|
||||
// Map<String, String> districData = {
|
||||
// "name": district.fullName ?? "Unknown District",
|
||||
// "code": district.code ?? districtCode,
|
||||
// };
|
||||
// sinkDistrictData.add(districData);
|
||||
// } catch (e) {
|
||||
// log("Lỗi khi lấy thông tin district ($districtCode): $e");
|
||||
// Map<String, String> districData = {
|
||||
// "name": "Error Loading District",
|
||||
// "code": districtCode,
|
||||
// };
|
||||
// sinkDistrictData.add(districData);
|
||||
// }
|
||||
|
||||
// // Xử lý Ward
|
||||
// try {
|
||||
// Ward ward = await apiServices.getWardByID(wardCode);
|
||||
// Map<String, String> wardMap = {
|
||||
// "name": ward.fullName ?? "Unknown Ward",
|
||||
// "code": ward.code ?? wardCode,
|
||||
// };
|
||||
// sinkWardData.add(wardMap);
|
||||
// } catch (e) {
|
||||
// print("Lỗi khi lấy thông tin ward ($wardCode): $e");
|
||||
// Map<String, String> wardMap = {
|
||||
// "name": "Error Loading Ward",
|
||||
// "code": wardCode,
|
||||
// };
|
||||
// sinkWardData.add(wardMap);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// print("Lỗi khi gọi getAllDistricts hoặc getAllWards: $e");
|
||||
// }
|
||||
// } else {
|
||||
// await getAllProvinces(context);
|
||||
// print(
|
||||
// "Một hoặc nhiều mã địa phương trống: Province: $provinceCode, District: $districtCode, Ward: $wardCode");
|
||||
// }
|
||||
// } else {
|
||||
// showNoIconTopSnackBar(
|
||||
// context,
|
||||
// "AreaPath không đủ thông tin: ${device.areaPath}",
|
||||
// Colors.orangeAccent,
|
||||
// Colors.white);
|
||||
// }
|
||||
// }
|
||||
// } catch (e) {
|
||||
// showNoIconTopSnackBar(context, "Lỗi trong getDeviceInfomation: $e",
|
||||
// Colors.orangeAccent, Colors.white);
|
||||
// }
|
||||
}
|
||||
|
||||
Future<Province> getProvinceByName(BuildContext context, String name) async {
|
||||
try {
|
||||
return await apiServices.execute(context, () async {
|
||||
List<Province> provinces = await apiServices.getProvincesByName(name);
|
||||
if (provinces.isNotEmpty) {
|
||||
return provinces[0];
|
||||
} else {
|
||||
return Province(name: "null");
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
return Province(name: "null");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Future<District> getDistrictByName(
|
||||
BuildContext context, String name, String provinceCode) async {
|
||||
try {
|
||||
return apiServices.execute(context, () async {
|
||||
final districts = await apiServices.getDistrictsByName(name);
|
||||
return districts.firstWhere(
|
||||
(district) => district.provinceCode == provinceCode,
|
||||
(district) => district.provinceCode == provinceCode,
|
||||
orElse: () => District(name: "null"),
|
||||
);
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
return District(name: "null");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<Ward> getWardByName(
|
||||
BuildContext context, String name, String districtCode) async {
|
||||
try {
|
||||
return apiServices.execute(context, () async {
|
||||
final wards = await apiServices.getWardsByName(name);
|
||||
return wards.firstWhere(
|
||||
(ward) => ward.districtCode == districtCode,
|
||||
(ward) => ward.districtCode == districtCode,
|
||||
orElse: () => Ward(name: "null"),
|
||||
);
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
return Ward(name: "null");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> updateDevice(
|
||||
@@ -292,10 +363,10 @@ class DeviceUpdateBloc extends BlocBase {
|
||||
String districtCode,
|
||||
String wardCode,
|
||||
) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
DateTime dateTime = DateTime.now();
|
||||
String formattedDateTime =
|
||||
DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime);
|
||||
DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime);
|
||||
Map<String, dynamic> body = {
|
||||
"name": name,
|
||||
"area_province": provinceCode,
|
||||
@@ -312,11 +383,30 @@ class DeviceUpdateBloc extends BlocBase {
|
||||
appLocalization(context).notification_update_device_success,
|
||||
appLocalization(context).notification_update_device_failed,
|
||||
);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
});
|
||||
// try {
|
||||
// DateTime dateTime = DateTime.now();
|
||||
// String formattedDateTime =
|
||||
// DateFormat('yyyy-MM-dd HH:mm:ss').format(dateTime);
|
||||
// Map<String, dynamic> body = {
|
||||
// "name": name,
|
||||
// "area_province": provinceCode,
|
||||
// "area_district": districtCode,
|
||||
// "area_ward": wardCode,
|
||||
// "latitude": latitude,
|
||||
// "longitude": longitude,
|
||||
// "note": "User updated device infomation at $formattedDateTime",
|
||||
// };
|
||||
// int statusCode = await apiServices.updateOwnerDevice(thingID, body);
|
||||
// showSnackBarResponseByStatusCodeNoIcon(
|
||||
// context,
|
||||
// statusCode,
|
||||
// appLocalization(context).notification_update_device_success,
|
||||
// appLocalization(context).notification_update_device_failed,
|
||||
// );
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
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';
|
||||
|
||||
@@ -76,7 +73,7 @@ class DevicesManagerBloc extends BlocBase {
|
||||
// }
|
||||
// }
|
||||
|
||||
void getDeviceByState(BuildContext context,int state) async {
|
||||
void getDeviceByState(BuildContext context, int state) async {
|
||||
try {
|
||||
sinkTagStates.add([state]);
|
||||
|
||||
@@ -91,16 +88,16 @@ class DevicesManagerBloc extends BlocBase {
|
||||
List<Device> devices = [];
|
||||
List<Device> originalDevices = [];
|
||||
if (state != -2) {
|
||||
originalDevices =
|
||||
await apiServices.getOwnerDeviceByState({"state": state.toString()});
|
||||
originalDevices = await apiServices
|
||||
.getOwnerDeviceByState({"state": state.toString()});
|
||||
} else {
|
||||
originalDevices = await apiServices.getOwnerDevices();
|
||||
}
|
||||
|
||||
List<Device> publicDevices = [];
|
||||
|
||||
for(var device in originalDevices){
|
||||
if(device.visibility == "PUBLIC"){
|
||||
for (var device in originalDevices) {
|
||||
if (device.visibility == "PUBLIC") {
|
||||
publicDevices.add(device);
|
||||
}
|
||||
}
|
||||
@@ -119,10 +116,8 @@ class DevicesManagerBloc extends BlocBase {
|
||||
sinkAllDevices.add(devices);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String _getStateKey(int state) {
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
import '../feature/devices/device_model.dart';
|
||||
import '../product/base/bloc/base_bloc.dart';
|
||||
import '../product/services/api_services.dart';
|
||||
import '../product/services/language_services.dart';
|
||||
import '../product/shared/shared_snack_bar.dart';
|
||||
import '../product/utils/response_status_utils.dart';
|
||||
|
||||
import '../feature/inter_family/group_detail/group_detail_model.dart';
|
||||
|
||||
class DetailGroupBloc extends BlocBase {
|
||||
@@ -30,86 +27,117 @@ class DetailGroupBloc extends BlocBase {
|
||||
@override
|
||||
void dispose() {}
|
||||
|
||||
Future<void> getGroupDetail(BuildContext context,String groupID) async {
|
||||
try {
|
||||
Future<void> getGroupDetail(BuildContext context, String groupID) async {
|
||||
await apiServices.execute(context, () async {
|
||||
List<DeviceOfGroup> warningDevices = [];
|
||||
GroupDetail group = await apiServices.getGroupDetail(groupID);
|
||||
sinkDetailGroup.add(group);
|
||||
if (group.devices != null) {
|
||||
for (var device in group.devices!) {
|
||||
if (device.state == 1) {
|
||||
warningDevices.add(device);
|
||||
}
|
||||
GroupDetail group = await apiServices.getGroupDetail(groupID);
|
||||
sinkDetailGroup.add(group);
|
||||
if (group.devices != null) {
|
||||
for (var device in group.devices!) {
|
||||
if (device.state == 1) {
|
||||
warningDevices.add(device);
|
||||
}
|
||||
sinkWarningDevice.add(warningDevices);
|
||||
}
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
sinkWarningDevice.add(warningDevices);
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// List<DeviceOfGroup> warningDevices = [];
|
||||
// GroupDetail group = await apiServices.getGroupDetail(groupID);
|
||||
// sinkDetailGroup.add(group);
|
||||
// if (group.devices != null) {
|
||||
// for (var device in group.devices!) {
|
||||
// if (device.state == 1) {
|
||||
// warningDevices.add(device);
|
||||
// }
|
||||
// }
|
||||
// sinkWarningDevice.add(warningDevices);
|
||||
// }
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> approveUserToGroup(BuildContext context, String groupID,
|
||||
String userID, String userName) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
Map<String, dynamic> body = {"group_id": groupID, "user_id": userID};
|
||||
int statusCode = await apiServices.approveGroup(body);
|
||||
showSnackBarResponseByStatusCode(context, statusCode,
|
||||
"Đã duyệt $userName vào nhóm!", "Duyệt $userName thất bại!");
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// Map<String, dynamic> body = {"group_id": groupID, "user_id": userID};
|
||||
// int statusCode = await apiServices.approveGroup(body);
|
||||
// showSnackBarResponseByStatusCode(context, statusCode,
|
||||
// "Đã duyệt $userName vào nhóm!", "Duyệt $userName thất bại!");
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> deleteOrUnapproveUser(BuildContext context, String groupID,
|
||||
String userID, String userName) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
int statusCode = await apiServices.deleteUserInGroup(groupID, userID);
|
||||
showSnackBarResponseByStatusCode(context, statusCode,
|
||||
"Đã xóa người dùng $userName", "Xóa người dùng $userName thất bại");
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// int statusCode = await apiServices.deleteUserInGroup(groupID, userID);
|
||||
// showSnackBarResponseByStatusCode(context, statusCode,
|
||||
// "Đã xóa người dùng $userName", "Xóa người dùng $userName thất bại");
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> deleteDevice(BuildContext context, String groupID,
|
||||
String thingID, String deviceName) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
int statusCode = await apiServices.deleteDeviceInGroup(groupID, thingID);
|
||||
showSnackBarResponseByStatusCode(context, statusCode,
|
||||
"Đã xóa thiết bị $deviceName", "Xóa thiết bị $deviceName thất bại");
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// int statusCode = await apiServices.deleteDeviceInGroup(groupID, thingID);
|
||||
// showSnackBarResponseByStatusCode(context, statusCode,
|
||||
// "Đã xóa thiết bị $deviceName", "Xóa thiết bị $deviceName thất bại");
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> leaveGroup(
|
||||
BuildContext context, String groupID, String userID) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
int statusCode = await apiServices.deleteUserInGroup(groupID, userID);
|
||||
showSnackBarResponseByStatusCode(
|
||||
context,
|
||||
statusCode,
|
||||
appLocalization(context).notification_leave_group_success,
|
||||
appLocalization(context).notification_leave_group_failed);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// int statusCode = await apiServices.deleteUserInGroup(groupID, userID);
|
||||
// showSnackBarResponseByStatusCode(
|
||||
// context,
|
||||
// statusCode,
|
||||
// appLocalization(context).notification_leave_group_success,
|
||||
// appLocalization(context).notification_leave_group_failed);
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
}
|
||||
|
||||
Future<void> updateDeviceNameInGroup(
|
||||
BuildContext context, String thingID, String newAlias) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
Map<String, dynamic> body = {"thing_id": thingID, "alias": newAlias};
|
||||
int statusCode = await apiServices.updateDeviceAlias(body);
|
||||
showSnackBarResponseByStatusCode(
|
||||
@@ -118,26 +146,29 @@ class DetailGroupBloc extends BlocBase {
|
||||
appLocalization(context).notification_update_device_success,
|
||||
appLocalization(context).notification_update_device_failed,
|
||||
);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// Map<String, dynamic> body = {"thing_id": thingID, "alias": newAlias};
|
||||
// int statusCode = await apiServices.updateDeviceAlias(body);
|
||||
// showSnackBarResponseByStatusCode(
|
||||
// context,
|
||||
// statusCode,
|
||||
// appLocalization(context).notification_update_device_success,
|
||||
// appLocalization(context).notification_update_device_failed,
|
||||
// );
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
}
|
||||
|
||||
Future<List<Device>> getOwnerDevices(BuildContext context) async {
|
||||
List<Device> allDevices = [];
|
||||
try {
|
||||
Future<List<Device>> getOwnerDevices(BuildContext context) {
|
||||
return apiServices.execute(context, () async {
|
||||
final originalDevices = await apiServices.getOwnerDevices();
|
||||
allDevices = originalDevices.where((device) => device.visibility == "PUBLIC").toList();
|
||||
|
||||
return allDevices;
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
showErrorTopSnackBarCustom(context, e.toString());
|
||||
}
|
||||
return allDevices;
|
||||
}
|
||||
return originalDevices
|
||||
.where((device) => device.visibility == "PUBLIC")
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> addDeviceToGroup(
|
||||
@@ -145,7 +176,7 @@ class DetailGroupBloc extends BlocBase {
|
||||
Map<String, dynamic> body = {
|
||||
"thing_id": thingID,
|
||||
};
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
int statusCode = await apiServices.addDeviceToGroup(groupID, body);
|
||||
showSnackBarResponseByStatusCode(
|
||||
context,
|
||||
@@ -153,10 +184,18 @@ class DetailGroupBloc extends BlocBase {
|
||||
appLocalization(context).notification_add_device_success,
|
||||
appLocalization(context).notification_add_device_failed,
|
||||
);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// int statusCode = await apiServices.addDeviceToGroup(groupID, body);
|
||||
// showSnackBarResponseByStatusCode(
|
||||
// context,
|
||||
// statusCode,
|
||||
// appLocalization(context).notification_add_device_success,
|
||||
// appLocalization(context).notification_add_device_failed,
|
||||
// );
|
||||
// } catch (e) {
|
||||
// if (!context.mounted) return;
|
||||
// showErrorTopSnackBarCustom(context, e.toString());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,18 +5,19 @@ import '../feature/home/device_alias_model.dart';
|
||||
import '../product/base/bloc/base_bloc.dart';
|
||||
|
||||
class HomeBloc extends BlocBase {
|
||||
|
||||
final allDevicesAliasMap = StreamController<Map<String,List<DeviceWithAlias>>>.broadcast();
|
||||
StreamSink<Map<String,List<DeviceWithAlias>>> get sinkAllDevicesAliasMap =>
|
||||
final allDevicesAliasMap =
|
||||
StreamController<Map<String, List<DeviceWithAlias>>>.broadcast();
|
||||
StreamSink<Map<String, List<DeviceWithAlias>>> get sinkAllDevicesAliasMap =>
|
||||
allDevicesAliasMap.sink;
|
||||
Stream<Map<String,List<DeviceWithAlias>>> get streamAllDevicesAliasMap =>
|
||||
Stream<Map<String, List<DeviceWithAlias>>> get streamAllDevicesAliasMap =>
|
||||
allDevicesAliasMap.stream;
|
||||
|
||||
final allDevicesAliasJoinedMap = StreamController<Map<String,List<DeviceWithAlias>>>.broadcast();
|
||||
StreamSink<Map<String,List<DeviceWithAlias>>> get sinkAllDevicesAliasJoinedMap =>
|
||||
allDevicesAliasJoinedMap.sink;
|
||||
Stream<Map<String,List<DeviceWithAlias>>> get streamAllDevicesAliasJoinedMap =>
|
||||
allDevicesAliasJoinedMap.stream;
|
||||
final allDevicesAliasJoinedMap =
|
||||
StreamController<Map<String, List<DeviceWithAlias>>>.broadcast();
|
||||
StreamSink<Map<String, List<DeviceWithAlias>>>
|
||||
get sinkAllDevicesAliasJoinedMap => allDevicesAliasJoinedMap.sink;
|
||||
Stream<Map<String, List<DeviceWithAlias>>>
|
||||
get streamAllDevicesAliasJoinedMap => allDevicesAliasJoinedMap.stream;
|
||||
|
||||
final countNotification = StreamController<int>.broadcast();
|
||||
StreamSink<int> get sinkCountNotification => countNotification.sink;
|
||||
@@ -26,13 +27,19 @@ class HomeBloc extends BlocBase {
|
||||
StreamSink<bool?> get sinkHasJoinedDevice => hasJoinedDevice.sink;
|
||||
Stream<bool?> get streamHasJoinedDevice => hasJoinedDevice.stream;
|
||||
|
||||
final ownerDevicesStatus =
|
||||
final ownerDevicesStatus =
|
||||
StreamController<Map<String, List<DeviceWithAlias>>>.broadcast();
|
||||
StreamSink<Map<String, List<DeviceWithAlias>>>
|
||||
get sinkOwnerDevicesStatus => ownerDevicesStatus.sink;
|
||||
StreamSink<Map<String, List<DeviceWithAlias>>> get sinkOwnerDevicesStatus =>
|
||||
ownerDevicesStatus.sink;
|
||||
Stream<Map<String, List<DeviceWithAlias>>> get streamOwnerDevicesStatus =>
|
||||
ownerDevicesStatus.stream;
|
||||
|
||||
@override
|
||||
void dispose() {}
|
||||
void dispose() {
|
||||
allDevicesAliasMap.close();
|
||||
allDevicesAliasJoinedMap.close();
|
||||
countNotification.close();
|
||||
hasJoinedDevice.close();
|
||||
ownerDevicesStatus.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import '../product/constant/app/app_constants.dart';
|
||||
|
||||
import '../product/constant/app/app_constants.dart';
|
||||
import '../product/services/api_services.dart';
|
||||
import '../product/base/bloc/base_bloc.dart';
|
||||
import '../product/services/language_services.dart';
|
||||
import '../product/shared/shared_snack_bar.dart';
|
||||
import '../product/utils/response_status_utils.dart';
|
||||
import '../feature/inter_family/groups/groups_model.dart';
|
||||
|
||||
@@ -36,10 +33,10 @@ class InterFamilyBloc extends BlocBase {
|
||||
@override
|
||||
void dispose() {}
|
||||
|
||||
void getAllGroup(String role) async {
|
||||
void getAllGroup(BuildContext context, String role) async {
|
||||
List<Group> groups = [];
|
||||
sinkCurrentGroups.add(groups);
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
groups = await apiServices.getAllGroups();
|
||||
groups = sortGroupByName(groups);
|
||||
|
||||
@@ -55,19 +52,13 @@ class InterFamilyBloc extends BlocBase {
|
||||
return false;
|
||||
},
|
||||
).toList();
|
||||
|
||||
sinkCurrentGroups.add(currentGroups);
|
||||
} catch (e) {
|
||||
// Xử lý lỗi khi jsonDecode thất bại
|
||||
log("Error decoding JSON: $e");
|
||||
sinkCurrentGroups.add([]);
|
||||
}
|
||||
log("Inter Family Role: $role");
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> createGroup(
|
||||
BuildContext context, String name, String description) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
Map<String, dynamic> body = {"name": name, "description": description};
|
||||
int? statusCode = await apiServices.createGroup(body);
|
||||
showSnackBarResponseByStatusCode(
|
||||
@@ -75,17 +66,12 @@ class InterFamilyBloc extends BlocBase {
|
||||
statusCode,
|
||||
appLocalization(context).notification_add_group_success,
|
||||
appLocalization(context).notification_add_group_failed);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> changeGroupInformation(BuildContext context, String groupID,
|
||||
String name, String description) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
Map<String, dynamic> body = {"name": name, "description": description};
|
||||
int statusCode = await apiServices.updateGroup(body, groupID);
|
||||
showSnackBarResponseByStatusCode(
|
||||
@@ -93,44 +79,32 @@ class InterFamilyBloc extends BlocBase {
|
||||
statusCode,
|
||||
appLocalization(context).notification_update_group_success,
|
||||
appLocalization(context).notification_update_group_failed);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> joinGroup(BuildContext context, String groupID) async {
|
||||
try {
|
||||
Map<String, dynamic> body = {
|
||||
"group_id": groupID,
|
||||
};
|
||||
Map<String, dynamic> body = {
|
||||
"group_id": groupID,
|
||||
};
|
||||
await apiServices.execute(context, () async {
|
||||
int statusCode = await apiServices.joinGroup(groupID, body);
|
||||
showSnackBarResponseByStatusCode(
|
||||
context,
|
||||
statusCode,
|
||||
appLocalization(context).notification_join_request_group_success,
|
||||
appLocalization(context).notification_join_request_group_failed);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> deleteGroup(BuildContext context, String groupID) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
int statusCode = await apiServices.deleteGroup(groupID);
|
||||
showSnackBarResponseByStatusCode(
|
||||
context,
|
||||
statusCode,
|
||||
appLocalization(context).notification_delete_group_success,
|
||||
appLocalization(context).notification_delete_group_failed);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
List<Group> sortGroupByName(List<Group> groups) {
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
import 'dart:async';
|
||||
import '../product/base/bloc/base_bloc.dart';
|
||||
|
||||
class LoginBloc extends BlocBase{
|
||||
|
||||
final loginRequest = StreamController<Map<String,dynamic>>.broadcast();
|
||||
StreamSink<Map<String,dynamic>> get sinkLoginRequest => loginRequest.sink;
|
||||
Stream<Map<String,dynamic>> get streamLoginRequest => loginRequest.stream;
|
||||
|
||||
class LoginBloc extends BlocBase {
|
||||
final loginRequest = StreamController<Map<String, dynamic>>.broadcast();
|
||||
StreamSink<Map<String, dynamic>> get sinkLoginRequest => loginRequest.sink;
|
||||
Stream<Map<String, dynamic>> get streamLoginRequest => loginRequest.stream;
|
||||
|
||||
final isShowPassword = StreamController<bool>.broadcast();
|
||||
StreamSink<bool> get sinkIsShowPassword => isShowPassword.sink;
|
||||
Stream<bool> get streamIsShowPassword => isShowPassword.stream;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
}
|
||||
|
||||
}
|
||||
void dispose() {}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:developer';
|
||||
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sfm_app/product/cache/local_manager.dart';
|
||||
import 'package:sfm_app/product/constant/app/api_path_constant.dart';
|
||||
import 'package:sfm_app/product/constant/enums/local_keys_enums.dart';
|
||||
import 'package:sfm_app/product/network/network_manager.dart';
|
||||
|
||||
import '../product/cache/local_manager.dart';
|
||||
import '../product/constant/app/api_path_constant.dart';
|
||||
import '../product/constant/enums/local_keys_enums.dart';
|
||||
import '../product/network/network_manager.dart';
|
||||
import '../product/base/bloc/base_bloc.dart';
|
||||
import '../product/services/api_services.dart';
|
||||
import '../feature/bell/bell_model.dart';
|
||||
import '../feature/settings/profile/profile_model.dart';
|
||||
import '../product/shared/shared_snack_bar.dart';
|
||||
|
||||
class MainBloc extends BlocBase {
|
||||
APIServices apiServices = APIServices();
|
||||
@@ -44,19 +42,13 @@ class MainBloc extends BlocBase {
|
||||
void dispose() {}
|
||||
|
||||
void getUserProfile(BuildContext context) async {
|
||||
try {
|
||||
await apiServices.execute(context, () async {
|
||||
User user = await apiServices.getUserDetail();
|
||||
sinkUserProfile.add(user);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
getFCMTokenAndPresentations() async {
|
||||
|
||||
String? firebaseAppToken = await FirebaseMessaging.instance.getToken();
|
||||
|
||||
if (firebaseAppToken != null) {
|
||||
@@ -67,14 +59,11 @@ class MainBloc extends BlocBase {
|
||||
}
|
||||
}
|
||||
|
||||
Future<int> sendNotificationToken(String token) async{
|
||||
Future<int> sendNotificationToken(String token) async {
|
||||
String uid = await getUID();
|
||||
Map<String,dynamic> body = {
|
||||
"user_id": uid,
|
||||
"app_token": token
|
||||
};
|
||||
int statusCode = await NetworkManager.instance!.updateDataInServer(
|
||||
APIPathConstants.NOTIFICATION_TOKEN_PATH, body);
|
||||
Map<String, dynamic> body = {"user_id": uid, "app_token": token};
|
||||
int statusCode = await NetworkManager.instance!
|
||||
.updateDataInServer(APIPathConstants.NOTIFICATION_TOKEN_PATH, body);
|
||||
return statusCode;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
|
||||
import '../product/services/map_services.dart';
|
||||
import '../product/shared/shared_snack_bar.dart';
|
||||
import '../feature/devices/device_model.dart';
|
||||
@@ -75,6 +75,4 @@ class MapBloc extends BlocBase {
|
||||
context, "Không tìm thấy đường", Colors.orange, Colors.white);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:sfm_app/product/services/api_services.dart';
|
||||
|
||||
import '../product/services/api_services.dart';
|
||||
import '../feature/settings/profile/profile_model.dart';
|
||||
import '../product/base/bloc/base_bloc.dart';
|
||||
import '../product/shared/shared_snack_bar.dart';
|
||||
|
||||
class SettingsBloc extends BlocBase {
|
||||
class SettingsBloc extends BlocBase {
|
||||
// Settings Screen
|
||||
APIServices apiServices = APIServices();
|
||||
final userProfile = StreamController<User>.broadcast();
|
||||
StreamSink<User> get sinkUserProfile => userProfile.sink;
|
||||
Stream<User> get streamUserProfile => userProfile.stream;
|
||||
|
||||
|
||||
// Profile Screen
|
||||
final isChangeProfileInfomation = StreamController<bool>.broadcast();
|
||||
StreamSink<bool> get sinkIsChangeProfileInfomation =>
|
||||
@@ -22,20 +19,13 @@ class SettingsBloc extends BlocBase {
|
||||
Stream<bool> get streamIsChangeProfileInfomation =>
|
||||
isChangeProfileInfomation.stream;
|
||||
|
||||
|
||||
void getUserProfile(BuildContext context) async {
|
||||
try {
|
||||
void getUserProfile(BuildContext context) async {
|
||||
await apiServices.execute(context, () async {
|
||||
User user = await apiServices.getUserDetail();
|
||||
sinkUserProfile.add(user);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
}
|
||||
void dispose() {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user