feat(api_service): Update try-catch funtion and handle exception
update(loading_animation): Update loading animation using Lottie
This commit is contained in:
anhtunz
2025-06-09 14:29:43 +07:00
parent 477646ab9d
commit 3a8fa3633c
44 changed files with 1659 additions and 1065 deletions

View File

@@ -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!;

View File

@@ -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