diff --git a/lib/main.dart b/lib/main.dart index ecec407..d88fa6c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -36,7 +36,7 @@ class MyApp extends StatelessWidget { Widget build(BuildContext context) { _appRouter = AppRouter(); final mediaQueryData = - MediaQueryData.fromView(WidgetsBinding.instance.window); + MediaQueryData.fromWindow(WidgetsBinding.instance.window); screenWidth = mediaQueryData.size.width; screenHeight = mediaQueryData.size.height; blockSizeHorizontal = screenWidth / 100; diff --git a/lib/model/location/purok.dart b/lib/model/location/purok.dart index e69de29..d32dbf4 100644 --- a/lib/model/location/purok.dart +++ b/lib/model/location/purok.dart @@ -0,0 +1,36 @@ +// To parse this JSON data, do +// +// final purok = purokFromJson(jsonString); + +import 'package:meta/meta.dart'; +import 'dart:convert'; + +import 'package:unit2/model/location/barangay.dart'; + +Purok purokFromJson(String str) => Purok.fromJson(json.decode(str)); + +String purokToJson(Purok data) => json.encode(data.toJson()); + +class Purok { + final String code; + final String description; + final Barangay barangay; + + Purok({ + required this.code, + required this.description, + required this.barangay, + }); + + factory Purok.fromJson(Map json) => Purok( + code: json["code"], + description: json["description"], + barangay: Barangay.fromJson(json["barangay"]), + ); + + Map toJson() => { + "code": code, + "description": description, + "barangay": barangay.toJson(), + }; +} diff --git a/lib/model/roles/pass_check/purok_assign_area.dart b/lib/model/roles/pass_check/purok_assign_area.dart index 883086f..7839854 100644 --- a/lib/model/roles/pass_check/purok_assign_area.dart +++ b/lib/model/roles/pass_check/purok_assign_area.dart @@ -2,7 +2,7 @@ import 'barangay_assign_area.dart'; -class Purok { +class PassCheckPurok { final String? purokid; final String? purokdesc; final BaragayAssignArea? brgy; @@ -10,7 +10,7 @@ class Purok { final bool? writelock; final dynamic recordsignature; - Purok({ + PassCheckPurok({ required this.purokid, required this.purokdesc, required this.brgy, @@ -19,7 +19,7 @@ class Purok { required this.recordsignature, }); - factory Purok.fromJson(Map json) => Purok( + factory PassCheckPurok.fromJson(Map json) => PassCheckPurok( purokid: json["purokid"], purokdesc: json["purokdesc"], brgy: json["brgy"]==null?null:BaragayAssignArea.fromJson(json["brgy"]), diff --git a/lib/screens/superadmin/assign_area/assign_area_screen.dart b/lib/screens/superadmin/assign_area/assign_area_screen.dart index 9f210f4..c4a3247 100644 --- a/lib/screens/superadmin/assign_area/assign_area_screen.dart +++ b/lib/screens/superadmin/assign_area/assign_area_screen.dart @@ -16,12 +16,14 @@ import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/model/location/barangay.dart'; import 'package:unit2/model/location/city.dart'; import 'package:unit2/model/location/provinces.dart'; +import 'package:unit2/model/location/purok.dart'; import 'package:unit2/model/location/region.dart'; import 'package:unit2/model/login_data/user_info/assigned_area.dart'; import 'package:unit2/model/profile/assigned_area.dart'; import 'package:unit2/model/rbac/rbac.dart'; import 'package:unit2/model/rbac/rbac_station.dart'; import 'package:unit2/model/roles/pass_check/agency_area_type.dart'; +import 'package:unit2/model/roles/pass_check/purok_assign_area.dart'; import 'package:unit2/model/roles/pass_check/station_assign_area.dart'; import 'package:unit2/model/utils/agency.dart'; import 'package:unit2/model/utils/category.dart'; @@ -57,6 +59,7 @@ class _RbacAssignedAreaScreenState extends State { bool provinceAsyncCall = false; bool cityAsyncCall = false; bool barangayAsyncCall = false; + bool purokAsyncCall = false; List userAssignedAreas = []; final bloc = BlocProvider.of(context); int? areaTypeId; @@ -72,6 +75,7 @@ class _RbacAssignedAreaScreenState extends State { List provinces = []; List cities = []; List barangays = []; + List puroks = []; Province? selectedProvince; CityMunicipality? selectedMunicipality; Barangay? selectedBarangay; @@ -119,7 +123,7 @@ class _RbacAssignedAreaScreenState extends State { "health nurse") { try { areaType = "barangay"; - areaTypeId = 1; + areaTypeId = 1; setState(() { provinceAsyncCall = true; }); @@ -152,6 +156,44 @@ class _RbacAssignedAreaScreenState extends State { //// purok } else if (e.name!.toLowerCase() == "purok president") { + try { + areaType = "purok"; + areaTypeId = 2; + setState(() { + provinceAsyncCall = true; + }); + provinces = await LocationUtils + .instance + .getProvinces(regionCode: "16"); + setState(() { + provinceAsyncCall = false; + cityAsyncCall = true; + }); + cities = await LocationUtils.instance + .getCities( + code: provinces[0].code!); + setState(() { + cityAsyncCall = false; + barangayAsyncCall = true; + }); + barangays = await LocationUtils + .instance + .getBarangay( + code: cities[0].code!); + setState(() { + barangayAsyncCall = false; + purokAsyncCall = true; + }); + puroks = await LocationUtils.instance + .getPurok( + barangay: barangays[0].code!); + setState(() { + purokAsyncCall = false; + }); + } catch (e) { + bloc.add(CallErrorState( + message: e.toString())); + } //// station } else if (e.name!.toLowerCase() == "qr code scanner" || e.name!.toLowerCase() == @@ -164,7 +206,7 @@ class _RbacAssignedAreaScreenState extends State { "process server") { try { areaType = "station"; - areaId = "4"; + areaId = "4"; setState(() { agencyAsyncCall = true; }); @@ -185,7 +227,6 @@ class _RbacAssignedAreaScreenState extends State { bloc.add(CallErrorState( message: e.toString())); } - //// agency------------------------------- } else if (e.name!.toLowerCase() == "establishment point-person" || @@ -227,16 +268,13 @@ class _RbacAssignedAreaScreenState extends State { itemHeight: 100, suggestions: agencies .map((Agency agency) => - SearchFieldListItem( - agency.name!, + SearchFieldListItem(agency.name!, item: agency, child: ListTile( - title: - AutoSizeText( + title: AutoSizeText( agency.name! .toUpperCase(), - minFontSize: - 12, + minFontSize: 12, ), subtitle: Text(agency .privateEntity == @@ -248,18 +286,13 @@ class _RbacAssignedAreaScreenState extends State { : ""), ))) .toList(), - validator: FormBuilderValidators - .required( - errorText: - "This field is required"), + validator: FormBuilderValidators.required( + errorText: "This field is required"), searchInputDecoration: - normalTextFieldStyle( - "Agency *", "") + normalTextFieldStyle("Agency *", "") .copyWith( - suffixIcon: - GestureDetector( - onTap: () => agencyFocusNode - .unfocus(), + suffixIcon: GestureDetector( + onTap: () => agencyFocusNode.unfocus(), child: const Icon( Icons.arrow_drop_down, ), @@ -267,17 +300,16 @@ class _RbacAssignedAreaScreenState extends State { ////agency suggestion tap onSuggestionTap: (agency) { setState(() { - areaId = agency.item!.id - .toString(); + areaId = agency.item!.id.toString(); agencyFocusNode.unfocus(); }); }, - emptyWidget: const Text( - "No Result Found..")) + emptyWidget: + const Text("No Result Found..")) //// station ------------------------------------------------ : areaType == "station" ? SizedBox( - height: 200, + height: 200, child: Flexible( child: Column( children: [ @@ -285,7 +317,8 @@ class _RbacAssignedAreaScreenState extends State { child: SizedBox( height: 100, child: ModalProgressHUD( - inAsyncCall: agencyAsyncCall, + inAsyncCall: + agencyAsyncCall, child: SearchField( controller: agencyController, @@ -295,41 +328,48 @@ class _RbacAssignedAreaScreenState extends State { focusNode: agencyFocusNode, itemHeight: 100, - suggestions: - agencies - .map((Agency agency) => SearchFieldListItem( + suggestions: agencies + .map((Agency + agency) => + SearchFieldListItem( agency .name!, item: agency, child: ListTile( - title: AutoSizeText( - agency.name!.toUpperCase(), - minFontSize: 12, + title: + AutoSizeText( + agency + .name! + .toUpperCase(), + minFontSize: + 12, ), - subtitle: Text(agency.privateEntity == true + subtitle: Text(agency.privateEntity == + true ? "Private" : agency.privateEntity == false ? "Government" : ""), ))) - .toList(), - validator: FormBuilderValidators - .required( - errorText: - "This field is required"), - searchInputDecoration: normalTextFieldStyle( - "Agency *", - "") - .copyWith( - suffixIcon: - GestureDetector( + .toList(), + validator: + FormBuilderValidators + .required( + errorText: + "This field is required"), + searchInputDecoration: + normalTextFieldStyle( + "Agency *", + "") + .copyWith( + suffixIcon: + GestureDetector( onTap: () => agencyFocusNode .unfocus(), - child: - const Icon( + child: const Icon( Icons .arrow_drop_down, ), @@ -342,9 +382,8 @@ class _RbacAssignedAreaScreenState extends State { .unfocus(); }); }, - emptyWidget: - const Text( - "No Result Found..")), + emptyWidget: const Text( + "No Result Found..")), ), ), ), @@ -354,39 +393,34 @@ class _RbacAssignedAreaScreenState extends State { Expanded( child: SizedBox( height: 75, - child: - ModalProgressHUD( - color: Colors - .transparent, + child: ModalProgressHUD( + color: Colors.transparent, inAsyncCall: stationAsyncCall, - child: FormBuilderDropdown< - RbacStation>( - decoration: normalTextFieldStyle( - "Station", - "Station"), - name: - "parent-stations", - items: stations - .isEmpty + child: + FormBuilderDropdown< + RbacStation>( + decoration: + normalTextFieldStyle( + "Station", + "Station"), + name: "parent-stations", + items: stations.isEmpty ? [] - : stations - .map( - (e) { + : stations.map((e) { return DropdownMenuItem( - value: - e, - child: - Text(e.stationName!), + value: e, + child: Text(e + .stationName!), ); }).toList(), onChanged: - (RbacStation? - e) {}, - validator: FormBuilderValidators - .required( - errorText: - "This field is required"), + (RbacStation? e) {}, + validator: + FormBuilderValidators + .required( + errorText: + "This field is required"), ), ), ), @@ -398,179 +432,460 @@ class _RbacAssignedAreaScreenState extends State { //// barangay ------------------------------------------------------------ : areaType == 'barangay' ? SizedBox( - height: 300, + height: 300, child: Column( - children: [ - //// PROVINCE DROPDOWN - Expanded( - child: SizedBox( - height: 60, - child: - ModalProgressHUD( - color: Colors - .transparent, - inAsyncCall: - provinceAsyncCall, - child: DropdownButtonFormField< - Province?>( - autovalidateMode: - AutovalidateMode - .onUserInteraction, - validator: (value) => value == - null - ? 'required' - : null, - isExpanded: - true, - // value: selectedProvince, + children: [ + //// PROVINCE DROPDOWN + Expanded( + child: SizedBox( + height: 60, + child: ModalProgressHUD( + color: + Colors.transparent, + inAsyncCall: + provinceAsyncCall, + child: DropdownButtonFormField< + Province?>( + autovalidateMode: + AutovalidateMode + .onUserInteraction, + validator: (value) => + value == null + ? 'required' + : null, + isExpanded: true, + // value: selectedProvince, + onChanged: (Province? + province) async { + setState(() { + selectedProvince = + province; + cityAsyncCall = + true; + }); + cities = await LocationUtils + .instance + .getCities( + code: provinces[ + 0] + .code!); + setState(() { + cityAsyncCall = + false; + barangayAsyncCall = + true; + }); + barangays = await LocationUtils + .instance + .getBarangay( + code: cities[ + 0] + .code!); + setState(() { + barangayAsyncCall = + false; + }); + }, + items: provinces + .isEmpty + ? [] + : provinces.map< + DropdownMenuItem< + Province>>((Province + province) { + return DropdownMenuItem( + value: + province, + child: + FittedBox( + child: + Text(province.description!), + )); + }).toList(), + decoration: + normalTextFieldStyle( + "Province*", + "Province")), + ), + ), + ), + //// CITIES DROPDOWN + Expanded( + child: SizedBox( + height: 60, + child: ModalProgressHUD( + color: Colors.white, + inAsyncCall: + cityAsyncCall, + child: + DropdownButtonFormField< + CityMunicipality>( + validator: + FormBuilderValidators + .required( + errorText: + "This field is required"), + isExpanded: true, onChanged: - (Province? - province) async { - setState( - () { - selectedProvince = - province; - cityAsyncCall = - true; - }); - cities = await LocationUtils - .instance - .getCities(code: provinces[0].code!); - setState( - () { - cityAsyncCall = - false; + (CityMunicipality? + city) async { + setState(() { + selectedMunicipality = + city; barangayAsyncCall = true; }); barangays = await LocationUtils .instance - .getBarangay(code: cities[0].code!); - setState( - () { + .getBarangay( + code: selectedMunicipality! + .code!); + setState(() { barangayAsyncCall = false; }); }, - items: provinces + decoration: + normalTextFieldStyle( + "Municipality*", + "Municipality"), + // value: selectedMunicipality, + items: cities.isEmpty + ? [] + : cities.map< + DropdownMenuItem< + CityMunicipality>>( + (CityMunicipality + c) { + return DropdownMenuItem( + value: c, + child: Text( + c.description!)); + }).toList(), + ), + ), + ), + ), + ////Barangay + Expanded( + child: SizedBox( + height: 60, + child: ModalProgressHUD( + color: Colors.white, + inAsyncCall: + barangayAsyncCall, + child: + DropdownButtonFormField< + Barangay>( + isExpanded: true, + onChanged: (Barangay? + baragay) { + areaId = + baragay!.code; + }, + decoration: + normalTextFieldStyle( + "Barangay*", + "Barangay"), + // value: selectedBarangay, + validator: + FormBuilderValidators + .required( + errorText: + "This field is required"), + items: barangays .isEmpty ? [] - : provinces.map>((Province - province) { + : barangays.map< + DropdownMenuItem< + Barangay>>((Barangay + barangay) { return DropdownMenuItem( - value: province, - child: FittedBox( - child: Text(province.description!), - )); + value: + barangay, + child: Text( + barangay + .description!)); }).toList(), - decoration: normalTextFieldStyle( - "Province*", - "Province")), - ), - ), - ), - //// CITIES DROPDOWN - Expanded( - child: SizedBox( - height: 60, - child: - ModalProgressHUD( - color: Colors - .white, - inAsyncCall: - cityAsyncCall, - child: DropdownButtonFormField< - CityMunicipality>( - validator: FormBuilderValidators.required( - errorText: - "This field is required"), - isExpanded: - true, - onChanged: - (CityMunicipality? - city) async { - setState( - () { - selectedMunicipality = - city; - barangayAsyncCall = - true; - }); - barangays = await LocationUtils - .instance - .getBarangay( - code: selectedMunicipality!.code!); - setState( - () { - barangayAsyncCall = - false; - }); - }, - decoration: normalTextFieldStyle( - "Municipality*", - "Municipality"), - // value: selectedMunicipality, - items: cities - .isEmpty - ? [] - : cities.map< - DropdownMenuItem< - CityMunicipality>>((CityMunicipality - c) { - return DropdownMenuItem( - value: c, - child: Text(c.description!)); - }).toList(), + ), ), ), ), - ), - ////Barangay - Expanded( - child: SizedBox( - height: 60, - child: - ModalProgressHUD( - color: Colors - .white, - inAsyncCall: - barangayAsyncCall, - child: DropdownButtonFormField< - Barangay>( - isExpanded: - true, - onChanged: - (Barangay? - baragay) { - areaId = - baragay! - .code; - }, - decoration: normalTextFieldStyle( - "Barangay*", - "Barangay"), - // value: selectedBarangay, - validator: FormBuilderValidators.required( - errorText: - "This field is required"), - items: barangays - .isEmpty - ? [] - : barangays.map< - DropdownMenuItem< - Barangay>>((Barangay - barangay) { - return DropdownMenuItem( - value: barangay, - child: Text(barangay.description!)); - }).toList(), + ], + )) + : //// Purok ------------------------------------------------------------ + areaType == 'purok' + ? SizedBox( + height: 300, + child: Column( + children: [ + //// PROVINCE DROPDOWN + Expanded( + child: SizedBox( + height: 60, + child: + ModalProgressHUD( + color: Colors + .transparent, + inAsyncCall: + provinceAsyncCall, + child: DropdownButtonFormField< + Province?>( + autovalidateMode: + AutovalidateMode + .onUserInteraction, + validator: (value) => + value == null + ? 'required' + : null, + isExpanded: + true, + // value: selectedProvince, + onChanged: + (Province? + province) async { + setState(() { + selectedProvince = + province; + cityAsyncCall = + true; + }); + cities = await LocationUtils + .instance + .getCities( + code: + provinces[0].code!); + setState(() { + cityAsyncCall = + false; + barangayAsyncCall = + true; + }); + barangays = await LocationUtils + .instance + .getBarangay( + code: + cities[0].code!); + setState(() { + barangayAsyncCall = + false; + purokAsyncCall = + true; + }); + puroks = await LocationUtils + .instance + .getPurok( + barangay: + barangays[0].code!); + setState(() { + purokAsyncCall = + false; + }); + }, + items: provinces + .isEmpty + ? [] + : provinces.map< + DropdownMenuItem< + Province>>((Province + province) { + return DropdownMenuItem( + value: + province, + child: + FittedBox( + child: Text(province.description!), + )); + }).toList(), + decoration: normalTextFieldStyle( + "Province*", + "Province")), + ), + ), ), - ), - ), - ), - ], - )) - : Container(), + //// CITIES DROPDOWN + Expanded( + child: SizedBox( + height: 60, + child: + ModalProgressHUD( + color: Colors.white, + inAsyncCall: + cityAsyncCall, + child: DropdownButtonFormField< + CityMunicipality>( + validator: FormBuilderValidators + .required( + errorText: + "This field is required"), + isExpanded: true, + onChanged: + (CityMunicipality? + city) async { + setState(() { + selectedMunicipality = + city; + barangayAsyncCall = + true; + }); + barangays = await LocationUtils + .instance + .getBarangay( + code: selectedMunicipality! + .code!); + setState(() { + barangayAsyncCall = + false; + purokAsyncCall = true; + }); + puroks = await LocationUtils + .instance + .getPurok( + barangay: + barangays[0].code!); + + setState((){ + purokAsyncCall = false; + }); + }, + + decoration: normalTextFieldStyle( + "Municipality*", + "Municipality"), + // value: selectedMunicipality, + items: cities + .isEmpty + ? [] + : cities.map< + DropdownMenuItem< + CityMunicipality>>( + (CityMunicipality + c) { + return DropdownMenuItem( + value: + c, + child: + Text(c.description!)); + }).toList(), + ), + ), + ), + ), + ////Barangay + Expanded( + + child: SizedBox( + height: 60, + child: + ModalProgressHUD( + color: Colors.white, + inAsyncCall: + barangayAsyncCall, + child: + DropdownButtonFormField< + Barangay>( + + isExpanded: true, + onChanged: + (Barangay? + baragay)async { + areaId = + baragay! + .code; + + setState((){ + purokAsyncCall= true; + }); + puroks = await LocationUtils + .instance + .getPurok( + barangay: + barangays[0].code!); + setState((){ + purokAsyncCall = false; + }); + }, + decoration: + normalTextFieldStyle( + "Barangay*", + "Barangay"), + // value: selectedBarangay, + validator: FormBuilderValidators + .required( + errorText: + "This field is required"), + + + items: barangays + .isEmpty + ? [] + : barangays.map< + DropdownMenuItem< + Barangay>>((Barangay + barangay) { + return DropdownMenuItem( + value: + barangay, + child: + Text(barangay.description!)); + }).toList(), + + + ), + ), + ), + ), + const SizedBox( + height: 12, + ), + ////Purok + Expanded( + child: SizedBox( + height: 60, + child: + ModalProgressHUD( + color: Colors.white, + inAsyncCall: + purokAsyncCall, + child: + DropdownButtonFormField< + Purok>( + isExpanded: true, + onChanged: + (Purok? + purok) { + areaId = + purok!.code; + }, + decoration: + normalTextFieldStyle( + "Purok*", + "Parangay"), + // value: selectedBarangay, + validator: FormBuilderValidators + .required( + errorText: + "This field is required"), + items: puroks + .isEmpty + ? [] + : puroks.map< + DropdownMenuItem< + Purok>>((Purok + purok) { + return DropdownMenuItem( + value: + purok, + child: + Text(purok.description)); + }).toList(), + ), + ), + ), + ), + ], + )) + : Container(), const SizedBox( height: 25, ), diff --git a/lib/screens/unit2/login/login.dart b/lib/screens/unit2/login/login.dart index 69c96c2..a9cbcd2 100644 --- a/lib/screens/unit2/login/login.dart +++ b/lib/screens/unit2/login/login.dart @@ -109,7 +109,7 @@ class _UniT2LoginState extends State { }, builder: (context, state) { if (state is VersionLoaded) { return Builder(builder: (context) { - if (state.versionInfo!.version != state.apkVersion) { + if (state.versionInfo?.version != state.apkVersion) { return SizedBox( child: SingleChildScrollView( child: Stack( diff --git a/lib/sevices/roles/pass_check_services.dart b/lib/sevices/roles/pass_check_services.dart index 12cd2a2..063118a 100644 --- a/lib/sevices/roles/pass_check_services.dart +++ b/lib/sevices/roles/pass_check_services.dart @@ -116,9 +116,9 @@ class PassCheckServices { } ////PUROK if (assignRoleAreaType.areaTypeName.toLowerCase() == 'purok') { - List assignedArea = []; + List assignedArea = []; data['data'][0]['assigned_area'].forEach((var element) { - Purok purok = Purok.fromJson(element['area']); + PassCheckPurok purok = PassCheckPurok.fromJson(element['area']); assignedArea.add(purok); }); statusResponse = assignedArea; diff --git a/lib/utils/location_utilities.dart b/lib/utils/location_utilities.dart index 87fa959..98f1b4f 100644 --- a/lib/utils/location_utilities.dart +++ b/lib/utils/location_utilities.dart @@ -6,6 +6,7 @@ import 'package:unit2/model/location/city.dart'; import 'package:unit2/model/location/country.dart'; import 'package:http/http.dart' as http; import 'package:unit2/model/location/provinces.dart'; +import 'package:unit2/model/location/purok.dart'; import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/urls.dart'; @@ -23,20 +24,20 @@ class LocationUtils { List countries = []; String path = Url.instance.getCounties(); - try{ - http.Response response = await Request.instance - .getRequest(path: path, param: {}, headers: headers); - if (response.statusCode == 200) { - Map data = jsonDecode(response.body); - if (data['data'] != null) { - data['data'].forEach((var country) { - Country newCOuntry = Country.fromJson(country); - countries.add(newCOuntry); - }); + try { + http.Response response = await Request.instance + .getRequest(path: path, param: {}, headers: headers); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + if (data['data'] != null) { + data['data'].forEach((var country) { + Country newCOuntry = Country.fromJson(country); + countries.add(newCOuntry); + }); + } } - } - }catch(e){ - throw(e.toString()); + } catch (e) { + throw (e.toString()); } return countries; } @@ -45,20 +46,20 @@ class LocationUtils { List regions = []; String path = Url.instance.getRegions(); - try{ - http.Response response = await Request.instance - .getRequest(path: path, param: {}, headers: headers); - if (response.statusCode == 200) { - Map data = jsonDecode(response.body); - if (data['data'] != null) { - data['data'].forEach((var region) { - Region newRegion = Region.fromJson(region); - regions.add(newRegion); - }); + try { + http.Response response = await Request.instance + .getRequest(path: path, param: {}, headers: headers); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + if (data['data'] != null) { + data['data'].forEach((var region) { + Region newRegion = Region.fromJson(region); + regions.add(newRegion); + }); + } } - } - }catch(e){ - throw(e.toString()); + } catch (e) { + throw (e.toString()); } return regions; } @@ -70,15 +71,15 @@ class LocationUtils { try { http.Response response = await Request.instance .getRequest(path: path, param: {}, headers: headers); - if(response.statusCode == 200){ + if (response.statusCode == 200) { Map data = jsonDecode(response.body); - if (data['data'] != null) { - data['data'].forEach((var province) { - Province newProvince = Province.fromJson(province); - provinces.add(newProvince); - }); + if (data['data'] != null) { + data['data'].forEach((var province) { + Province newProvince = Province.fromJson(province); + provinces.add(newProvince); + }); + } } - } } catch (e) { throw (e.toString()); } @@ -91,12 +92,14 @@ class LocationUtils { try { http.Response response = await Request.instance .getRequest(path: path, param: {}, headers: headers); - Map data = jsonDecode(response.body); - if (data['data'] != null) { - data['data'].forEach((var city) { - CityMunicipality cityMun = CityMunicipality.fromJson(city); - cities.add(cityMun); - }); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + if (data['data'] != null) { + data['data'].forEach((var city) { + CityMunicipality cityMun = CityMunicipality.fromJson(city); + cities.add(cityMun); + }); + } } } catch (e) { throw (e.toString()); @@ -104,41 +107,64 @@ class LocationUtils { return cities; } - Future> getBarangay({required String code}) async { + Future> getBarangay({required String code}) async { List barangays = []; String path = Url.instance.getBarangays() + code; try { http.Response response = await Request.instance .getRequest(path: path, param: {}, headers: headers); - Map data = jsonDecode(response.body); - if (data['data'] != null) { - data['data'].forEach((var city) { - Barangay barangay = Barangay.fromJson(city); - barangays.add(barangay); - }); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + if (data['data'] != null) { + data['data'].forEach((var city) { + Barangay barangay = Barangay.fromJson(city); + barangays.add(barangay); + }); + } } } catch (e) { throw (e.toString()); } return barangays; } - Future>getAddressCategory()async{ + + Future> getPurok({required String barangay}) async { + List puroks = []; + String path = Url.instance.getPurok() + barangay; + try { + http.Response response = await Request.instance + .getRequest(path: path, param: {}, headers: headers); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + if (data['data'] != null) { + data['data'].forEach((var purok) { + Purok newPurok = Purok.fromJson(purok); + puroks.add(newPurok); + }); + } + } + } catch (e) { + throw (e.toString()); + } + return puroks; + } + + Future> getAddressCategory() async { List categories = []; String path = Url.instance.getAddressCategory(); - try{ - http.Response response = await Request.instance.getRequest(path: path,param: {},headers:headers ); + try { + http.Response response = await Request.instance + .getRequest(path: path, param: {}, headers: headers); Map data = jsonDecode(response.body); - if(data['data'] != null){ - data['data'].forEach((var cat){ + if (data['data'] != null) { + data['data'].forEach((var cat) { categories.add(AddressCategory.fromJson(cat)); }); } categories; return categories; - }catch(e){ + } catch (e) { throw e.toString(); } } - - } diff --git a/lib/utils/urls.dart b/lib/utils/urls.dart index 3cecbe6..6a88218 100644 --- a/lib/utils/urls.dart +++ b/lib/utils/urls.dart @@ -343,6 +343,9 @@ class Url { String getBarangays() { return "/api/web_app/location/barangay/"; } + String getPurok(){ + return "/api/web_app/location/purok/"; + } String getAddressCategory() { return "/api/jobnet_app/address_categories/";