assign area using purok

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-09-19 11:35:31 +08:00
parent f73f8a03e1
commit 6dd9216af7
8 changed files with 669 additions and 289 deletions

View File

@ -36,7 +36,7 @@ class MyApp extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
_appRouter = AppRouter(); _appRouter = AppRouter();
final mediaQueryData = final mediaQueryData =
MediaQueryData.fromView(WidgetsBinding.instance.window); MediaQueryData.fromWindow(WidgetsBinding.instance.window);
screenWidth = mediaQueryData.size.width; screenWidth = mediaQueryData.size.width;
screenHeight = mediaQueryData.size.height; screenHeight = mediaQueryData.size.height;
blockSizeHorizontal = screenWidth / 100; blockSizeHorizontal = screenWidth / 100;

View File

@ -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<String, dynamic> json) => Purok(
code: json["code"],
description: json["description"],
barangay: Barangay.fromJson(json["barangay"]),
);
Map<String, dynamic> toJson() => {
"code": code,
"description": description,
"barangay": barangay.toJson(),
};
}

View File

@ -2,7 +2,7 @@
import 'barangay_assign_area.dart'; import 'barangay_assign_area.dart';
class Purok { class PassCheckPurok {
final String? purokid; final String? purokid;
final String? purokdesc; final String? purokdesc;
final BaragayAssignArea? brgy; final BaragayAssignArea? brgy;
@ -10,7 +10,7 @@ class Purok {
final bool? writelock; final bool? writelock;
final dynamic recordsignature; final dynamic recordsignature;
Purok({ PassCheckPurok({
required this.purokid, required this.purokid,
required this.purokdesc, required this.purokdesc,
required this.brgy, required this.brgy,
@ -19,7 +19,7 @@ class Purok {
required this.recordsignature, required this.recordsignature,
}); });
factory Purok.fromJson(Map<String, dynamic> json) => Purok( factory PassCheckPurok.fromJson(Map<String, dynamic> json) => PassCheckPurok(
purokid: json["purokid"], purokid: json["purokid"],
purokdesc: json["purokdesc"], purokdesc: json["purokdesc"],
brgy: json["brgy"]==null?null:BaragayAssignArea.fromJson(json["brgy"]), brgy: json["brgy"]==null?null:BaragayAssignArea.fromJson(json["brgy"]),

View File

@ -16,12 +16,14 @@ import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/model/location/barangay.dart'; import 'package:unit2/model/location/barangay.dart';
import 'package:unit2/model/location/city.dart'; import 'package:unit2/model/location/city.dart';
import 'package:unit2/model/location/provinces.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/location/region.dart';
import 'package:unit2/model/login_data/user_info/assigned_area.dart'; import 'package:unit2/model/login_data/user_info/assigned_area.dart';
import 'package:unit2/model/profile/assigned_area.dart'; import 'package:unit2/model/profile/assigned_area.dart';
import 'package:unit2/model/rbac/rbac.dart'; import 'package:unit2/model/rbac/rbac.dart';
import 'package:unit2/model/rbac/rbac_station.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/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/roles/pass_check/station_assign_area.dart';
import 'package:unit2/model/utils/agency.dart'; import 'package:unit2/model/utils/agency.dart';
import 'package:unit2/model/utils/category.dart'; import 'package:unit2/model/utils/category.dart';
@ -57,6 +59,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
bool provinceAsyncCall = false; bool provinceAsyncCall = false;
bool cityAsyncCall = false; bool cityAsyncCall = false;
bool barangayAsyncCall = false; bool barangayAsyncCall = false;
bool purokAsyncCall = false;
List<UserAssignedArea> userAssignedAreas = []; List<UserAssignedArea> userAssignedAreas = [];
final bloc = BlocProvider.of<AssignAreaBloc>(context); final bloc = BlocProvider.of<AssignAreaBloc>(context);
int? areaTypeId; int? areaTypeId;
@ -72,6 +75,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
List<Province> provinces = []; List<Province> provinces = [];
List<CityMunicipality> cities = []; List<CityMunicipality> cities = [];
List<Barangay> barangays = []; List<Barangay> barangays = [];
List<Purok> puroks = [];
Province? selectedProvince; Province? selectedProvince;
CityMunicipality? selectedMunicipality; CityMunicipality? selectedMunicipality;
Barangay? selectedBarangay; Barangay? selectedBarangay;
@ -119,7 +123,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
"health nurse") { "health nurse") {
try { try {
areaType = "barangay"; areaType = "barangay";
areaTypeId = 1; areaTypeId = 1;
setState(() { setState(() {
provinceAsyncCall = true; provinceAsyncCall = true;
}); });
@ -152,6 +156,44 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
//// purok //// purok
} else if (e.name!.toLowerCase() == } else if (e.name!.toLowerCase() ==
"purok president") { "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 //// station
} else if (e.name!.toLowerCase() == "qr code scanner" || } else if (e.name!.toLowerCase() == "qr code scanner" ||
e.name!.toLowerCase() == e.name!.toLowerCase() ==
@ -164,7 +206,7 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
"process server") { "process server") {
try { try {
areaType = "station"; areaType = "station";
areaId = "4"; areaId = "4";
setState(() { setState(() {
agencyAsyncCall = true; agencyAsyncCall = true;
}); });
@ -185,7 +227,6 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
bloc.add(CallErrorState( bloc.add(CallErrorState(
message: e.toString())); message: e.toString()));
} }
//// agency------------------------------- //// agency-------------------------------
} else if (e.name!.toLowerCase() == } else if (e.name!.toLowerCase() ==
"establishment point-person" || "establishment point-person" ||
@ -227,16 +268,13 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
itemHeight: 100, itemHeight: 100,
suggestions: agencies suggestions: agencies
.map((Agency agency) => .map((Agency agency) =>
SearchFieldListItem( SearchFieldListItem(agency.name!,
agency.name!,
item: agency, item: agency,
child: ListTile( child: ListTile(
title: title: AutoSizeText(
AutoSizeText(
agency.name! agency.name!
.toUpperCase(), .toUpperCase(),
minFontSize: minFontSize: 12,
12,
), ),
subtitle: Text(agency subtitle: Text(agency
.privateEntity == .privateEntity ==
@ -248,18 +286,13 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
: ""), : ""),
))) )))
.toList(), .toList(),
validator: FormBuilderValidators validator: FormBuilderValidators.required(
.required( errorText: "This field is required"),
errorText:
"This field is required"),
searchInputDecoration: searchInputDecoration:
normalTextFieldStyle( normalTextFieldStyle("Agency *", "")
"Agency *", "")
.copyWith( .copyWith(
suffixIcon: suffixIcon: GestureDetector(
GestureDetector( onTap: () => agencyFocusNode.unfocus(),
onTap: () => agencyFocusNode
.unfocus(),
child: const Icon( child: const Icon(
Icons.arrow_drop_down, Icons.arrow_drop_down,
), ),
@ -267,17 +300,16 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
////agency suggestion tap ////agency suggestion tap
onSuggestionTap: (agency) { onSuggestionTap: (agency) {
setState(() { setState(() {
areaId = agency.item!.id areaId = agency.item!.id.toString();
.toString();
agencyFocusNode.unfocus(); agencyFocusNode.unfocus();
}); });
}, },
emptyWidget: const Text( emptyWidget:
"No Result Found..")) const Text("No Result Found.."))
//// station ------------------------------------------------ //// station ------------------------------------------------
: areaType == "station" : areaType == "station"
? SizedBox( ? SizedBox(
height: 200, height: 200,
child: Flexible( child: Flexible(
child: Column( child: Column(
children: [ children: [
@ -285,7 +317,8 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
child: SizedBox( child: SizedBox(
height: 100, height: 100,
child: ModalProgressHUD( child: ModalProgressHUD(
inAsyncCall: agencyAsyncCall, inAsyncCall:
agencyAsyncCall,
child: SearchField( child: SearchField(
controller: controller:
agencyController, agencyController,
@ -295,41 +328,48 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
focusNode: focusNode:
agencyFocusNode, agencyFocusNode,
itemHeight: 100, itemHeight: 100,
suggestions: suggestions: agencies
agencies .map((Agency
.map((Agency agency) => SearchFieldListItem( agency) =>
SearchFieldListItem(
agency agency
.name!, .name!,
item: item:
agency, agency,
child: child:
ListTile( ListTile(
title: AutoSizeText( title:
agency.name!.toUpperCase(), AutoSizeText(
minFontSize: 12, agency
.name!
.toUpperCase(),
minFontSize:
12,
), ),
subtitle: Text(agency.privateEntity == true subtitle: Text(agency.privateEntity ==
true
? "Private" ? "Private"
: agency.privateEntity == false : agency.privateEntity == false
? "Government" ? "Government"
: ""), : ""),
))) )))
.toList(), .toList(),
validator: FormBuilderValidators validator:
.required( FormBuilderValidators
errorText: .required(
"This field is required"), errorText:
searchInputDecoration: normalTextFieldStyle( "This field is required"),
"Agency *", searchInputDecoration:
"") normalTextFieldStyle(
.copyWith( "Agency *",
suffixIcon: "")
GestureDetector( .copyWith(
suffixIcon:
GestureDetector(
onTap: () => onTap: () =>
agencyFocusNode agencyFocusNode
.unfocus(), .unfocus(),
child: child: const Icon(
const Icon(
Icons Icons
.arrow_drop_down, .arrow_drop_down,
), ),
@ -342,9 +382,8 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
.unfocus(); .unfocus();
}); });
}, },
emptyWidget: emptyWidget: const Text(
const Text( "No Result Found..")),
"No Result Found..")),
), ),
), ),
), ),
@ -354,39 +393,34 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
Expanded( Expanded(
child: SizedBox( child: SizedBox(
height: 75, height: 75,
child: child: ModalProgressHUD(
ModalProgressHUD( color: Colors.transparent,
color: Colors
.transparent,
inAsyncCall: inAsyncCall:
stationAsyncCall, stationAsyncCall,
child: FormBuilderDropdown< child:
RbacStation>( FormBuilderDropdown<
decoration: normalTextFieldStyle( RbacStation>(
"Station", decoration:
"Station"), normalTextFieldStyle(
name: "Station",
"parent-stations", "Station"),
items: stations name: "parent-stations",
.isEmpty items: stations.isEmpty
? [] ? []
: stations : stations.map((e) {
.map(
(e) {
return DropdownMenuItem( return DropdownMenuItem(
value: value: e,
e, child: Text(e
child: .stationName!),
Text(e.stationName!),
); );
}).toList(), }).toList(),
onChanged: onChanged:
(RbacStation? (RbacStation? e) {},
e) {}, validator:
validator: FormBuilderValidators FormBuilderValidators
.required( .required(
errorText: errorText:
"This field is required"), "This field is required"),
), ),
), ),
), ),
@ -398,179 +432,460 @@ class _RbacAssignedAreaScreenState extends State<RbacAssignedAreaScreen> {
//// barangay ------------------------------------------------------------ //// barangay ------------------------------------------------------------
: areaType == 'barangay' : areaType == 'barangay'
? SizedBox( ? SizedBox(
height: 300, height: 300,
child: Column( child: Column(
children: [ children: [
//// PROVINCE DROPDOWN //// PROVINCE DROPDOWN
Expanded( Expanded(
child: SizedBox( child: SizedBox(
height: 60, height: 60,
child: child: ModalProgressHUD(
ModalProgressHUD( color:
color: Colors Colors.transparent,
.transparent, inAsyncCall:
inAsyncCall: provinceAsyncCall,
provinceAsyncCall, child: DropdownButtonFormField<
child: DropdownButtonFormField< Province?>(
Province?>( autovalidateMode:
autovalidateMode: AutovalidateMode
AutovalidateMode .onUserInteraction,
.onUserInteraction, validator: (value) =>
validator: (value) => value == value == null
null ? 'required'
? 'required' : null,
: null, isExpanded: true,
isExpanded: // value: selectedProvince,
true, onChanged: (Province?
// value: selectedProvince, 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: onChanged:
(Province? (CityMunicipality?
province) async { city) async {
setState( setState(() {
() { selectedMunicipality =
selectedProvince = city;
province;
cityAsyncCall =
true;
});
cities = await LocationUtils
.instance
.getCities(code: provinces[0].code!);
setState(
() {
cityAsyncCall =
false;
barangayAsyncCall = barangayAsyncCall =
true; true;
}); });
barangays = await LocationUtils barangays = await LocationUtils
.instance .instance
.getBarangay(code: cities[0].code!); .getBarangay(
setState( code: selectedMunicipality!
() { .code!);
setState(() {
barangayAsyncCall = barangayAsyncCall =
false; 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 .isEmpty
? [] ? []
: provinces.map<DropdownMenuItem<Province>>((Province : barangays.map<
province) { DropdownMenuItem<
Barangay>>((Barangay
barangay) {
return DropdownMenuItem( return DropdownMenuItem(
value: province, value:
child: FittedBox( barangay,
child: Text(province.description!), child: Text(
)); barangay
.description!));
}).toList(), }).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( : //// Purok ------------------------------------------------------------
child: SizedBox( areaType == 'purok'
height: 60, ? SizedBox(
child: height: 300,
ModalProgressHUD( child: Column(
color: Colors children: [
.white, //// PROVINCE DROPDOWN
inAsyncCall: Expanded(
barangayAsyncCall, child: SizedBox(
child: DropdownButtonFormField< height: 60,
Barangay>( child:
isExpanded: ModalProgressHUD(
true, color: Colors
onChanged: .transparent,
(Barangay? inAsyncCall:
baragay) { provinceAsyncCall,
areaId = child: DropdownButtonFormField<
baragay! Province?>(
.code; autovalidateMode:
}, AutovalidateMode
decoration: normalTextFieldStyle( .onUserInteraction,
"Barangay*", validator: (value) =>
"Barangay"), value == null
// value: selectedBarangay, ? 'required'
validator: FormBuilderValidators.required( : null,
errorText: isExpanded:
"This field is required"), true,
items: barangays // value: selectedProvince,
.isEmpty onChanged:
? [] (Province?
: barangays.map< province) async {
DropdownMenuItem< setState(() {
Barangay>>((Barangay selectedProvince =
barangay) { province;
return DropdownMenuItem( cityAsyncCall =
value: barangay, true;
child: Text(barangay.description!)); });
}).toList(), 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")),
),
),
), ),
), //// CITIES DROPDOWN
), Expanded(
), child: SizedBox(
], height: 60,
)) child:
: Container(), 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( const SizedBox(
height: 25, height: 25,
), ),

View File

@ -109,7 +109,7 @@ class _UniT2LoginState extends State<UniT2Login> {
}, builder: (context, state) { }, builder: (context, state) {
if (state is VersionLoaded) { if (state is VersionLoaded) {
return Builder(builder: (context) { return Builder(builder: (context) {
if (state.versionInfo!.version != state.apkVersion) { if (state.versionInfo?.version != state.apkVersion) {
return SizedBox( return SizedBox(
child: SingleChildScrollView( child: SingleChildScrollView(
child: Stack( child: Stack(

View File

@ -116,9 +116,9 @@ class PassCheckServices {
} }
////PUROK ////PUROK
if (assignRoleAreaType.areaTypeName.toLowerCase() == 'purok') { if (assignRoleAreaType.areaTypeName.toLowerCase() == 'purok') {
List<Purok> assignedArea = []; List<PassCheckPurok> assignedArea = [];
data['data'][0]['assigned_area'].forEach((var element) { data['data'][0]['assigned_area'].forEach((var element) {
Purok purok = Purok.fromJson(element['area']); PassCheckPurok purok = PassCheckPurok.fromJson(element['area']);
assignedArea.add(purok); assignedArea.add(purok);
}); });
statusResponse = assignedArea; statusResponse = assignedArea;

View File

@ -6,6 +6,7 @@ import 'package:unit2/model/location/city.dart';
import 'package:unit2/model/location/country.dart'; import 'package:unit2/model/location/country.dart';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:unit2/model/location/provinces.dart'; import 'package:unit2/model/location/provinces.dart';
import 'package:unit2/model/location/purok.dart';
import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/request.dart';
import 'package:unit2/utils/urls.dart'; import 'package:unit2/utils/urls.dart';
@ -23,20 +24,20 @@ class LocationUtils {
List<Country> countries = []; List<Country> countries = [];
String path = Url.instance.getCounties(); String path = Url.instance.getCounties();
try{ try {
http.Response response = await Request.instance http.Response response = await Request.instance
.getRequest(path: path, param: {}, headers: headers); .getRequest(path: path, param: {}, headers: headers);
if (response.statusCode == 200) { if (response.statusCode == 200) {
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
if (data['data'] != null) { if (data['data'] != null) {
data['data'].forEach((var country) { data['data'].forEach((var country) {
Country newCOuntry = Country.fromJson(country); Country newCOuntry = Country.fromJson(country);
countries.add(newCOuntry); countries.add(newCOuntry);
}); });
}
} }
} } catch (e) {
}catch(e){ throw (e.toString());
throw(e.toString());
} }
return countries; return countries;
} }
@ -45,20 +46,20 @@ class LocationUtils {
List<Region> regions = []; List<Region> regions = [];
String path = Url.instance.getRegions(); String path = Url.instance.getRegions();
try{ try {
http.Response response = await Request.instance http.Response response = await Request.instance
.getRequest(path: path, param: {}, headers: headers); .getRequest(path: path, param: {}, headers: headers);
if (response.statusCode == 200) { if (response.statusCode == 200) {
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
if (data['data'] != null) { if (data['data'] != null) {
data['data'].forEach((var region) { data['data'].forEach((var region) {
Region newRegion = Region.fromJson(region); Region newRegion = Region.fromJson(region);
regions.add(newRegion); regions.add(newRegion);
}); });
}
} }
} } catch (e) {
}catch(e){ throw (e.toString());
throw(e.toString());
} }
return regions; return regions;
} }
@ -70,15 +71,15 @@ class LocationUtils {
try { try {
http.Response response = await Request.instance http.Response response = await Request.instance
.getRequest(path: path, param: {}, headers: headers); .getRequest(path: path, param: {}, headers: headers);
if(response.statusCode == 200){ if (response.statusCode == 200) {
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
if (data['data'] != null) { if (data['data'] != null) {
data['data'].forEach((var province) { data['data'].forEach((var province) {
Province newProvince = Province.fromJson(province); Province newProvince = Province.fromJson(province);
provinces.add(newProvince); provinces.add(newProvince);
}); });
}
} }
}
} catch (e) { } catch (e) {
throw (e.toString()); throw (e.toString());
} }
@ -91,12 +92,14 @@ class LocationUtils {
try { try {
http.Response response = await Request.instance http.Response response = await Request.instance
.getRequest(path: path, param: {}, headers: headers); .getRequest(path: path, param: {}, headers: headers);
Map data = jsonDecode(response.body); if (response.statusCode == 200) {
if (data['data'] != null) { Map data = jsonDecode(response.body);
data['data'].forEach((var city) { if (data['data'] != null) {
CityMunicipality cityMun = CityMunicipality.fromJson(city); data['data'].forEach((var city) {
cities.add(cityMun); CityMunicipality cityMun = CityMunicipality.fromJson(city);
}); cities.add(cityMun);
});
}
} }
} catch (e) { } catch (e) {
throw (e.toString()); throw (e.toString());
@ -104,41 +107,64 @@ class LocationUtils {
return cities; return cities;
} }
Future<List<Barangay>> getBarangay({required String code}) async { Future<List<Barangay>> getBarangay({required String code}) async {
List<Barangay> barangays = []; List<Barangay> barangays = [];
String path = Url.instance.getBarangays() + code; String path = Url.instance.getBarangays() + code;
try { try {
http.Response response = await Request.instance http.Response response = await Request.instance
.getRequest(path: path, param: {}, headers: headers); .getRequest(path: path, param: {}, headers: headers);
Map data = jsonDecode(response.body); if (response.statusCode == 200) {
if (data['data'] != null) { Map data = jsonDecode(response.body);
data['data'].forEach((var city) { if (data['data'] != null) {
Barangay barangay = Barangay.fromJson(city); data['data'].forEach((var city) {
barangays.add(barangay); Barangay barangay = Barangay.fromJson(city);
}); barangays.add(barangay);
});
}
} }
} catch (e) { } catch (e) {
throw (e.toString()); throw (e.toString());
} }
return barangays; return barangays;
} }
Future<List<AddressCategory>>getAddressCategory()async{
Future<List<Purok>> getPurok({required String barangay}) async {
List<Purok> 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<List<AddressCategory>> getAddressCategory() async {
List<AddressCategory> categories = []; List<AddressCategory> categories = [];
String path = Url.instance.getAddressCategory(); String path = Url.instance.getAddressCategory();
try{ try {
http.Response response = await Request.instance.getRequest(path: path,param: {},headers:headers ); http.Response response = await Request.instance
.getRequest(path: path, param: {}, headers: headers);
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
if(data['data'] != null){ if (data['data'] != null) {
data['data'].forEach((var cat){ data['data'].forEach((var cat) {
categories.add(AddressCategory.fromJson(cat)); categories.add(AddressCategory.fromJson(cat));
}); });
} }
categories; categories;
return categories; return categories;
}catch(e){ } catch (e) {
throw e.toString(); throw e.toString();
} }
} }
} }

View File

@ -343,6 +343,9 @@ class Url {
String getBarangays() { String getBarangays() {
return "/api/web_app/location/barangay/"; return "/api/web_app/location/barangay/";
} }
String getPurok(){
return "/api/web_app/location/purok/";
}
String getAddressCategory() { String getAddressCategory() {
return "/api/jobnet_app/address_categories/"; return "/api/jobnet_app/address_categories/";