update
feat(api_service): Update try-catch funtion and handle exception update(loading_animation): Update loading animation using Lottie
This commit is contained in:
@@ -95,23 +95,36 @@ void addDevices(
|
||||
APIServices apiServices = APIServices();
|
||||
Map<String, dynamic> body = {};
|
||||
if (role == RoleEnums.ADMIN.name) {
|
||||
body = {"ext_id": extID, "name": deviceName};
|
||||
int statusCode = await apiServices.createDeviceByAdmin(body);
|
||||
showSnackBarResponseByStatusCode(
|
||||
context,
|
||||
statusCode,
|
||||
appLocalization(context).notification_create_device_success,
|
||||
appLocalization(context).notification_create_device_failed);
|
||||
deviceManagerBloc.getDeviceByState(-2);
|
||||
try {
|
||||
body = {"ext_id": extID, "name": deviceName};
|
||||
int statusCode = await apiServices.createDeviceByAdmin(body);
|
||||
showSnackBarResponseByStatusCode(
|
||||
context,
|
||||
statusCode,
|
||||
appLocalization(context).notification_create_device_success,
|
||||
appLocalization(context).notification_create_device_failed);
|
||||
deviceManagerBloc.getDeviceByState(context,-2);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
} else {
|
||||
body = {"ext_id": extID};
|
||||
int statusCode = await apiServices.registerDevice(body);
|
||||
showSnackBarResponseByStatusCode(
|
||||
context,
|
||||
statusCode,
|
||||
appLocalization(context).notification_add_device_success,
|
||||
appLocalization(context).notification_device_not_exist);
|
||||
deviceManagerBloc.getDeviceByState(-2);
|
||||
try {
|
||||
body = {"ext_id": extID};
|
||||
int statusCode = await apiServices.registerDevice(body);
|
||||
showSnackBarResponseByStatusCode(
|
||||
context,
|
||||
statusCode,
|
||||
appLocalization(context).notification_add_device_success,
|
||||
appLocalization(context).notification_device_not_exist);
|
||||
deviceManagerBloc.getDeviceByState(context,-2);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import '../../bloc/devices_manager_bloc.dart';
|
||||
import '../../product/constant/enums/role_enums.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';
|
||||
|
||||
handleDeleteDevice(BuildContext context, DevicesManagerBloc devicesManagerBloc,
|
||||
@@ -53,14 +54,21 @@ deleteOrUnregisterDevice(BuildContext context, DevicesManagerBloc devicesBloc,
|
||||
statusCode,
|
||||
appLocalization(context).notification_delete_device_success,
|
||||
appLocalization(context).notification_delete_device_failed);
|
||||
devicesBloc.getDeviceByState(-2);
|
||||
devicesBloc.getDeviceByState(context,-2);
|
||||
} else {
|
||||
int statusCode = await apiServices.deleteDeviceByAdmin(extID);
|
||||
showSnackBarResponseByStatusCode(
|
||||
context,
|
||||
statusCode,
|
||||
appLocalization(context).notification_delete_device_success,
|
||||
appLocalization(context).notification_delete_device_failed);
|
||||
devicesBloc.getDeviceByState(-2);
|
||||
try {
|
||||
int statusCode = await apiServices.deleteDeviceByAdmin(extID);
|
||||
showSnackBarResponseByStatusCode(
|
||||
context,
|
||||
statusCode,
|
||||
appLocalization(context).notification_delete_device_success,
|
||||
appLocalization(context).notification_delete_device_failed);
|
||||
devicesBloc.getDeviceByState(context,-2);
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
showErrorTopSnackBarCustom(
|
||||
context, e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,11 +2,13 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:google_maps_flutter/google_maps_flutter.dart';
|
||||
import 'package:sfm_app/product/shared/shared_component_loading_animation.dart';
|
||||
import 'package:simple_ripple_animation/simple_ripple_animation.dart';
|
||||
|
||||
import '../../../product/constant/image/image_constants.dart';
|
||||
import '../../../product/shared/shared_line_chart.dart';
|
||||
import '../../../product/shared/shared_curve.dart';
|
||||
import '../../../product/shared/shared_loading_animation.dart';
|
||||
import '../../device_log/device_logs_model.dart';
|
||||
import '../device_model.dart';
|
||||
import '../../../product/base/bloc/base_bloc.dart';
|
||||
@@ -92,8 +94,11 @@ class _DetailDeviceScreenState extends State<DetailDeviceScreen> {
|
||||
widget.thingID,
|
||||
controller,
|
||||
);
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: Text(appLocalization(context).no_data_message),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return StreamBuilder<Map<String, dynamic>>(
|
||||
@@ -125,28 +130,6 @@ class _DetailDeviceScreenState extends State<DetailDeviceScreen> {
|
||||
fit: BoxFit.fill,
|
||||
),
|
||||
),
|
||||
// Center(
|
||||
// child: Container(
|
||||
// height: 50,
|
||||
// width: 400,
|
||||
// // color: Colors.blueAccent,
|
||||
// alignment: Alignment.centerRight,
|
||||
// margin: const EdgeInsets.fromLTRB(0, 0, 0, 50),
|
||||
// child: Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
// children: [
|
||||
// const SizedBox(),
|
||||
// Text(
|
||||
// deviceSnapshot.data?.name ?? "",
|
||||
// style: const TextStyle(
|
||||
// fontSize: 25,
|
||||
// fontWeight: FontWeight.w600,
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -541,12 +524,10 @@ class _DetailDeviceScreenState extends State<DetailDeviceScreen> {
|
||||
builder: (context, sensorTempsSnapshot) {
|
||||
if (sensorTempsSnapshot.data == null) {
|
||||
detailDeviceBloc
|
||||
.getNearerSensorValue(widget.thingID);
|
||||
.getNearerSensorValue(context,widget.thingID);
|
||||
return const AspectRatio(
|
||||
aspectRatio: 3,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
child: SharedComponentLoadingAnimation(),
|
||||
);
|
||||
} else if (sensorTempsSnapshot.data!.isEmpty) {
|
||||
return Center(
|
||||
@@ -657,12 +638,7 @@ class _DetailDeviceScreenState extends State<DetailDeviceScreen> {
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
return const SharedLoadingAnimation();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:search_choices/search_choices.dart';
|
||||
|
||||
import '../../../product/shared/shared_loading_animation.dart';
|
||||
import '../device_model.dart';
|
||||
import '../../../bloc/device_update_bloc.dart';
|
||||
import 'map_dialog.dart';
|
||||
@@ -47,7 +48,7 @@ class _DeviceUpdateScreenState extends State<DeviceUpdateScreen> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
deviceUpdateBloc = BlocProvider.of(context);
|
||||
deviceUpdateBloc.getAllProvinces();
|
||||
deviceUpdateBloc.getAllProvinces(context);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -72,16 +73,16 @@ class _DeviceUpdateScreenState extends State<DeviceUpdateScreen> {
|
||||
initialData: device,
|
||||
builder: (context, deviceInfoSnapshot) {
|
||||
if (deviceInfoSnapshot.data!.thingId == null) {
|
||||
deviceUpdateBloc.getDeviceInfomation(
|
||||
deviceUpdateBloc.getDeviceInformation(
|
||||
context,
|
||||
widget.thingID,
|
||||
districtsData,
|
||||
wardsData,
|
||||
// provincesData,
|
||||
// districtsData,
|
||||
// wardsData,
|
||||
deviceNameController,
|
||||
deviceLatitudeController,
|
||||
deviceLongitudeController);
|
||||
return const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
);
|
||||
return const SharedLoadingAnimation();
|
||||
} else {
|
||||
return StreamBuilder<bool>(
|
||||
stream: deviceUpdateBloc.streamIsChanged,
|
||||
@@ -245,7 +246,7 @@ class _DeviceUpdateScreenState extends State<DeviceUpdateScreen> {
|
||||
.sinkProvinceData
|
||||
.add(provinceData);
|
||||
deviceUpdateBloc
|
||||
.getAllDistricts(
|
||||
.getAllDistricts(context,
|
||||
value.code);
|
||||
selectedDistrict = "";
|
||||
districtData['name'] =
|
||||
@@ -318,7 +319,7 @@ class _DeviceUpdateScreenState extends State<DeviceUpdateScreen> {
|
||||
.sinkDistrictData
|
||||
.add(districtData);
|
||||
deviceUpdateBloc
|
||||
.getAllWards(value.code);
|
||||
.getAllWards(context,value.code);
|
||||
selectedWard = "";
|
||||
wardData['name'] =
|
||||
selectedWard!;
|
||||
|
||||
@@ -64,7 +64,7 @@ showMapDialog(
|
||||
String latitude = mapDialogLatitudeController.text;
|
||||
String longitude = mapDialogLongitudeController.text;
|
||||
log("Finish -- Latitude: $latitude, longitude: $longitude --");
|
||||
getDataFromApi(latitude, longitude, deviceUpdateBloc);
|
||||
getDataFromApi(context,latitude, longitude, deviceUpdateBloc);
|
||||
latitudeController.text =
|
||||
mapDialogLatitudeController.text;
|
||||
longitudeController.text =
|
||||
@@ -184,7 +184,7 @@ addMarker(
|
||||
updateCameraPosition(position, 14, mapController);
|
||||
}
|
||||
|
||||
void getDataFromApi(String latitude, String longitude,
|
||||
void getDataFromApi(BuildContext context,String latitude, String longitude,
|
||||
DeviceUpdateBloc deviceUpdateBloc) async {
|
||||
String path =
|
||||
"maps/api/geocode/json?latlng=$latitude,$longitude&language=vi&result_type=political&key=${ApplicationConstants.MAP_KEY}";
|
||||
@@ -215,7 +215,7 @@ void getDataFromApi(String latitude, String longitude,
|
||||
log("$key: $value");
|
||||
});
|
||||
|
||||
await _processLocations(locations, deviceUpdateBloc);
|
||||
await _processLocations(context,locations, deviceUpdateBloc);
|
||||
}
|
||||
|
||||
Map<String, String> _extractLocationComponents(
|
||||
@@ -241,31 +241,31 @@ Map<String, String> _extractLocationComponents(
|
||||
return locations;
|
||||
}
|
||||
|
||||
Future<void> _processLocations(
|
||||
Future<void> _processLocations(BuildContext context,
|
||||
Map<String, String> locations, DeviceUpdateBloc deviceUpdateBloc) async {
|
||||
String provinceNameFromAPI = locations['provincekey'] ?? "";
|
||||
String districtNameFromAPI = locations['districtkey'] ?? "";
|
||||
String wardNameFromAPI = locations['wardkey'] ?? "";
|
||||
|
||||
final province =
|
||||
await deviceUpdateBloc.getProvinceByName(provinceNameFromAPI);
|
||||
await deviceUpdateBloc.getProvinceByName(context,provinceNameFromAPI);
|
||||
if (province.name != "null") {
|
||||
log("Province: ${province.fullName}, ProvinceCode: ${province.code}");
|
||||
deviceUpdateBloc.sinkProvinceData
|
||||
.add({"code": province.code!, "name": province.fullName!});
|
||||
deviceUpdateBloc.getAllProvinces();
|
||||
deviceUpdateBloc.getAllProvinces(context);
|
||||
|
||||
final district = await deviceUpdateBloc.getDistrictByName(
|
||||
final district = await deviceUpdateBloc.getDistrictByName(context,
|
||||
districtNameFromAPI, province.code!);
|
||||
log("Districtname: ${district.fullName}, districtCode: ${district.code}");
|
||||
deviceUpdateBloc.getAllDistricts(province.code!);
|
||||
deviceUpdateBloc.getAllDistricts(context,province.code!);
|
||||
if (district.name != "null") {
|
||||
deviceUpdateBloc.sinkDistrictData
|
||||
.add({"code": district.code!, "name": district.fullName!});
|
||||
final ward =
|
||||
await deviceUpdateBloc.getWardByName(wardNameFromAPI, district.code!);
|
||||
await deviceUpdateBloc.getWardByName(context,wardNameFromAPI, district.code!);
|
||||
log("Wardname: ${ward.fullName}, WardCode: ${ward.code}");
|
||||
deviceUpdateBloc.getAllWards(district.code!);
|
||||
deviceUpdateBloc.getAllWards(context,district.code!);
|
||||
if (ward.name != "null") {
|
||||
log("Xac dinh duoc het thong tin tu toa do");
|
||||
deviceUpdateBloc.sinkWardData
|
||||
|
||||
@@ -4,6 +4,8 @@ import 'package:data_table_2/data_table_2.dart';
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../product/shared/shared_component_loading_animation.dart';
|
||||
import '../../product/shared/shared_loading_animation.dart';
|
||||
import 'add_new_device_widget.dart';
|
||||
import 'delete_device_widget.dart';
|
||||
import 'device_model.dart';
|
||||
@@ -41,7 +43,7 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
|
||||
const duration = Duration(seconds: 10);
|
||||
getAllDevicesTimer = Timer.periodic(
|
||||
duration,
|
||||
(Timer t) => devicesManagerBloc.getDeviceByState(tagIndex),
|
||||
(Timer t) => devicesManagerBloc.getDeviceByState(context,tagIndex),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -68,8 +70,8 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
|
||||
builder: (context, allDeviceSnapshot) {
|
||||
if(allDeviceSnapshot.data == null){
|
||||
devicesManagerBloc
|
||||
.getDeviceByState(tagSnapshot.data?[0] ?? -2);
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
.getDeviceByState(context,tagSnapshot.data?[0] ?? -2);
|
||||
return const SharedLoadingAnimation();
|
||||
}
|
||||
if (allDeviceSnapshot.data!.isEmpty) {
|
||||
return Center(
|
||||
@@ -219,10 +221,9 @@ class _DevicesManagerScreenState extends State<DevicesManagerScreen> {
|
||||
stream: devicesManagerBloc.streamDeviceByState,
|
||||
builder: (context, devicesByStateSnapshot) {
|
||||
if (devicesByStateSnapshot.data == null) {
|
||||
devicesManagerBloc.getDeviceByState(
|
||||
devicesManagerBloc.getDeviceByState(context,
|
||||
tagSnapshot.data?[0] ?? -2);
|
||||
return const Center(
|
||||
child: CircularProgressIndicator());
|
||||
return const SharedComponentLoadingAnimation();
|
||||
} else {
|
||||
return SharedPieChart(
|
||||
deviceByState:
|
||||
@@ -392,7 +393,7 @@ class TagState extends StatelessWidget {
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
devicesManagerBloc.getDeviceByState(-2);
|
||||
devicesManagerBloc.getDeviceByState(context,-2);
|
||||
},
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
|
||||
Reference in New Issue
Block a user