2023-03-24 06:46:17 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
|
|
|
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
|
|
|
|
import 'package:form_builder_validators/form_builder_validators.dart';
|
|
|
|
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
|
|
|
|
import 'package:unit2/bloc/profile/references/references_bloc.dart';
|
|
|
|
import 'package:unit2/model/location/address_category.dart';
|
|
|
|
import 'package:unit2/model/location/barangay.dart';
|
|
|
|
import 'package:unit2/model/profile/references.dart';
|
|
|
|
import 'package:unit2/theme-data.dart/btn-style.dart';
|
|
|
|
import 'package:unit2/theme-data.dart/form-style.dart';
|
2023-04-11 01:27:53 +00:00
|
|
|
import 'package:unit2/utils/global.dart';
|
2023-03-24 06:46:17 +00:00
|
|
|
import '../../../../model/location/city.dart';
|
|
|
|
import '../../../../model/location/country.dart';
|
|
|
|
import '../../../../model/location/provinces.dart';
|
|
|
|
import '../../../../model/location/region.dart';
|
|
|
|
import '../../../../theme-data.dart/colors.dart';
|
|
|
|
import '../../../../utils/location_utilities.dart';
|
|
|
|
import '../../../../utils/text_container.dart';
|
|
|
|
|
|
|
|
class AddReferenceScreen extends StatefulWidget {
|
2023-04-11 01:27:53 +00:00
|
|
|
final int profileId;
|
|
|
|
final String token;
|
|
|
|
const AddReferenceScreen(
|
|
|
|
{super.key, required this.profileId, required this.token});
|
2023-03-24 06:46:17 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<AddReferenceScreen> createState() => _AddReferenceScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AddReferenceScreenState extends State<AddReferenceScreen> {
|
|
|
|
final formKey = GlobalKey<FormBuilderState>();
|
|
|
|
bool provinceCall = false;
|
|
|
|
bool cityCall = false;
|
|
|
|
bool barangayCall = false;
|
|
|
|
bool overseas = false;
|
|
|
|
List<Province>? provinces;
|
|
|
|
List<CityMunicipality>? citymuns;
|
|
|
|
List<Barangay>? barangays;
|
|
|
|
List<String> category = ['Permanent', "Residential", "Birthplace"];
|
|
|
|
////seletected
|
|
|
|
Region? selectedRegion;
|
|
|
|
Province? selectedProvince;
|
|
|
|
CityMunicipality? selectedMunicipality;
|
|
|
|
Barangay? selectedBarangay;
|
|
|
|
Country? selectedCountry;
|
|
|
|
AddressCategory? selectedCategory;
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-04-11 01:27:53 +00:00
|
|
|
return BlocBuilder<ReferencesBloc, ReferencesState>(
|
2023-03-24 06:46:17 +00:00
|
|
|
builder: (context, state) {
|
2023-04-11 01:27:53 +00:00
|
|
|
if (state is AddReferenceState) {
|
|
|
|
return SingleChildScrollView(
|
|
|
|
child: SizedBox(
|
|
|
|
height: screenHeight * .95,
|
|
|
|
child: ProgressHUD(
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 25, horizontal: 18),
|
|
|
|
child: FormBuilder(
|
|
|
|
key: formKey,
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
const SizedBox(height: 25),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
////LAST NAME
|
|
|
|
Flexible(
|
|
|
|
flex: 1,
|
|
|
|
child: FormBuilderTextField(
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Last name *", "Last name *"),
|
|
|
|
name: "lastname",
|
|
|
|
validator: FormBuilderValidators.required(
|
|
|
|
errorText: "This field is required"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 5,
|
|
|
|
),
|
|
|
|
////FIRST NAME
|
|
|
|
Flexible(
|
|
|
|
flex: 1,
|
|
|
|
child: FormBuilderTextField(
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"First name *", "First name *"),
|
|
|
|
name: "firstname",
|
|
|
|
validator: FormBuilderValidators.required(
|
|
|
|
errorText: "This field is required"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
flex: 1,
|
|
|
|
child: FormBuilderTextField(
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Middle name *", "Midlle name *"),
|
|
|
|
name: "middlename",
|
|
|
|
validator: FormBuilderValidators.required(
|
|
|
|
errorText: "This field is required"),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 5,
|
|
|
|
),
|
|
|
|
////CATEGORY
|
|
|
|
Flexible(
|
|
|
|
flex: 1,
|
|
|
|
child: FormBuilderDropdown<AddressCategory>(
|
|
|
|
name: 'category',
|
|
|
|
validator:
|
|
|
|
FormBuilderValidators.required(errorText: ""),
|
|
|
|
decoration:
|
|
|
|
normalTextFieldStyle("Category", "Category"),
|
|
|
|
items: state.categories
|
|
|
|
.map<DropdownMenuItem<AddressCategory>>(
|
|
|
|
(AddressCategory cat) {
|
|
|
|
return DropdownMenuItem<AddressCategory>(
|
|
|
|
value: cat,
|
|
|
|
child: Text(cat.name!),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
selectedCategory = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
|
|
|
|
|
|
|
////OVERSEAS ADDRESS
|
|
|
|
FormBuilderSwitch(
|
|
|
|
initialValue: overseas,
|
|
|
|
activeColor: second,
|
|
|
|
onChanged: (value) {
|
|
|
|
setState(() {
|
|
|
|
overseas = value!;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
decoration: normalTextFieldStyle("", ''),
|
|
|
|
name: 'overseas',
|
|
|
|
title: const Text("Overseas Address?"),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
height: overseas == true ? 8 : 0,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
child: overseas == false
|
|
|
|
? Column(
|
2023-03-24 06:46:17 +00:00
|
|
|
children: [
|
|
|
|
const SizedBox(
|
2023-04-11 01:27:53 +00:00
|
|
|
height: 12,
|
2023-03-24 06:46:17 +00:00
|
|
|
),
|
2023-04-11 01:27:53 +00:00
|
|
|
////REGION DROPDOWN
|
|
|
|
FormBuilderDropdown<Region?>(
|
|
|
|
autovalidateMode:
|
|
|
|
AutovalidateMode.onUserInteraction,
|
|
|
|
validator: FormBuilderValidators.required(
|
|
|
|
errorText: "This field is required"),
|
|
|
|
onChanged: (Region? region) async {
|
|
|
|
if(selectedRegion != region){
|
|
|
|
setState(() {
|
|
|
|
provinceCall = true;
|
|
|
|
});
|
|
|
|
selectedRegion = region;
|
|
|
|
getProvinces();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
initialValue: null,
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Region*", "Region"),
|
|
|
|
name: 'region',
|
|
|
|
items: state.regions
|
|
|
|
.map<DropdownMenuItem<Region>>(
|
|
|
|
(Region region) {
|
|
|
|
return DropdownMenuItem<Region>(
|
|
|
|
value: region,
|
|
|
|
child: Text(region.description!));
|
|
|
|
}).toList(),
|
2023-03-24 06:46:17 +00:00
|
|
|
),
|
|
|
|
const SizedBox(
|
2023-04-11 01:27:53 +00:00
|
|
|
height: 8,
|
2023-03-24 06:46:17 +00:00
|
|
|
),
|
2023-04-11 01:27:53 +00:00
|
|
|
//// PROVINCE DROPDOWN
|
|
|
|
SizedBox(
|
|
|
|
height: 60,
|
|
|
|
child: ModalProgressHUD(
|
|
|
|
color: Colors.transparent,
|
|
|
|
inAsyncCall: provinceCall,
|
|
|
|
child: DropdownButtonFormField<Province?>(
|
|
|
|
autovalidateMode: AutovalidateMode
|
|
|
|
.onUserInteraction,
|
|
|
|
validator: (value) =>
|
|
|
|
value == null ? 'required' : null,
|
|
|
|
isExpanded: true,
|
|
|
|
value: selectedProvince,
|
|
|
|
onChanged: (Province? province) {
|
|
|
|
if(selectedProvince != province){
|
|
|
|
setState(() {
|
|
|
|
cityCall = true;
|
|
|
|
});
|
|
|
|
selectedProvince = province;
|
|
|
|
getCities();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
items: provinces == null
|
|
|
|
? []
|
|
|
|
: provinces!.map<
|
|
|
|
DropdownMenuItem<
|
|
|
|
Province>>(
|
|
|
|
(Province province) {
|
|
|
|
return DropdownMenuItem(
|
|
|
|
value: province,
|
|
|
|
child: FittedBox(
|
|
|
|
child: Text(province
|
|
|
|
.description!),
|
|
|
|
));
|
|
|
|
}).toList(),
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Province*", "Province")),
|
2023-03-24 06:46:17 +00:00
|
|
|
),
|
|
|
|
),
|
2023-04-11 01:27:53 +00:00
|
|
|
////CITY MUNICIPALITY
|
|
|
|
SizedBox(
|
|
|
|
height: 60,
|
|
|
|
child: ModalProgressHUD(
|
|
|
|
color: Colors.white,
|
|
|
|
inAsyncCall: cityCall,
|
|
|
|
child: DropdownButtonFormField<
|
|
|
|
CityMunicipality>(
|
|
|
|
validator:
|
|
|
|
FormBuilderValidators.required(
|
|
|
|
errorText:
|
|
|
|
"This field is required"),
|
|
|
|
isExpanded: true,
|
|
|
|
onChanged: (CityMunicipality? city) {
|
|
|
|
if(selectedMunicipality != city){
|
|
|
|
setState(() {
|
|
|
|
barangayCall = true;
|
|
|
|
});
|
|
|
|
selectedMunicipality = city;
|
|
|
|
getBarangays();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Municipality*", "Municipality"),
|
|
|
|
value: selectedMunicipality,
|
|
|
|
items: citymuns == null
|
|
|
|
? []
|
|
|
|
: citymuns!.map<
|
2023-03-24 06:46:17 +00:00
|
|
|
DropdownMenuItem<
|
2023-04-11 01:27:53 +00:00
|
|
|
CityMunicipality>>(
|
|
|
|
(CityMunicipality c) {
|
|
|
|
return DropdownMenuItem(
|
|
|
|
value: c,
|
|
|
|
child:
|
|
|
|
Text(c.description!));
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
//// BARANGAY
|
|
|
|
SizedBox(
|
|
|
|
height: 60,
|
|
|
|
child: ModalProgressHUD(
|
|
|
|
color: Colors.white,
|
|
|
|
inAsyncCall: barangayCall,
|
|
|
|
child: DropdownButtonFormField<Barangay>(
|
|
|
|
|
|
|
|
isExpanded: true,
|
|
|
|
onChanged: (Barangay? baragay) {
|
|
|
|
selectedBarangay = baragay;
|
|
|
|
},
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Barangay*", "Barangay"),
|
|
|
|
value: selectedBarangay,
|
|
|
|
items: barangays == null
|
|
|
|
? []
|
|
|
|
: barangays!.map<
|
|
|
|
DropdownMenuItem<Barangay>>(
|
|
|
|
(Barangay barangay) {
|
|
|
|
return DropdownMenuItem(
|
|
|
|
value: barangay,
|
2023-03-24 06:46:17 +00:00
|
|
|
child: Text(
|
2023-04-11 01:27:53 +00:00
|
|
|
barangay.description!));
|
|
|
|
}).toList(),
|
2023-03-24 06:46:17 +00:00
|
|
|
),
|
2023-04-11 01:27:53 +00:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
//// COUNTRY DROPDOWN
|
|
|
|
: SizedBox(
|
2023-03-24 06:46:17 +00:00
|
|
|
height: 60,
|
2023-04-11 01:27:53 +00:00
|
|
|
child: FormBuilderDropdown<Country>(
|
|
|
|
initialValue: null,
|
|
|
|
validator: FormBuilderValidators.required(
|
|
|
|
errorText: "This field is required"),
|
|
|
|
items: state.countries
|
|
|
|
.map<DropdownMenuItem<Country>>(
|
|
|
|
(Country country) {
|
|
|
|
return DropdownMenuItem<Country>(
|
|
|
|
value: country,
|
|
|
|
child: FittedBox(
|
|
|
|
child: Text(country.name!)));
|
|
|
|
}).toList(),
|
|
|
|
name: 'country',
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Country*", "Country"),
|
|
|
|
onChanged: (Country? value) {
|
|
|
|
selectedCountry = value;
|
2023-03-24 06:46:17 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
2023-04-11 01:27:53 +00:00
|
|
|
),
|
|
|
|
|
|
|
|
FormBuilderTextField(
|
|
|
|
name: "mobile",
|
|
|
|
decoration: normalTextFieldStyle(
|
|
|
|
"Tel./Mobile *", "Tel./Mobile"),
|
|
|
|
validator: FormBuilderValidators.required(
|
|
|
|
errorText: "This field is required"),
|
|
|
|
),
|
|
|
|
const Expanded(
|
|
|
|
child: SizedBox(),
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
height: 60,
|
|
|
|
child: ElevatedButton(
|
|
|
|
style:
|
|
|
|
mainBtnStyle(primary, Colors.transparent, second),
|
|
|
|
child: const Text(submit),
|
|
|
|
onPressed: () {
|
|
|
|
PersonalReference? personalReference;
|
|
|
|
if (formKey.currentState!.saveAndValidate()) {
|
|
|
|
String lastname =
|
|
|
|
formKey.currentState!.value['lastname'];
|
|
|
|
String firstname =
|
|
|
|
formKey.currentState!.value['firstname'];
|
|
|
|
String middlename =
|
|
|
|
formKey.currentState!.value['middlename'];
|
|
|
|
String mobile =
|
|
|
|
formKey.currentState!.value['mobile'];
|
|
|
|
|
|
|
|
Region? region = selectedRegion;
|
|
|
|
Province? province = Province(
|
|
|
|
code: selectedProvince?.code,
|
|
|
|
description: selectedProvince?.description,
|
|
|
|
region: region,
|
|
|
|
psgcCode: selectedProvince?.psgcCode,
|
|
|
|
shortname: selectedProvince?.shortname);
|
|
|
|
CityMunicipality? city = CityMunicipality(
|
|
|
|
code: selectedMunicipality?.code,
|
|
|
|
description:
|
|
|
|
selectedMunicipality?.description,
|
|
|
|
province: province,
|
|
|
|
psgcCode: selectedMunicipality?.psgcCode,
|
|
|
|
zipcode: selectedMunicipality?.zipcode);
|
|
|
|
|
|
|
|
Address address = Address(
|
|
|
|
id: null,
|
|
|
|
addressCategory: selectedCategory,
|
|
|
|
country: selectedCountry,
|
|
|
|
barangay: selectedBarangay,
|
|
|
|
addressClass: null,
|
|
|
|
cityMunicipality: city);
|
|
|
|
|
|
|
|
if (selectedCountry != null) {
|
|
|
|
personalReference = PersonalReference(
|
|
|
|
id: null,
|
|
|
|
address: Address(
|
|
|
|
id: null,
|
|
|
|
addressCategory: selectedCategory,
|
|
|
|
country: selectedCountry,
|
|
|
|
barangay: null,
|
|
|
|
cityMunicipality: null,
|
|
|
|
addressClass: null),
|
|
|
|
lastName: lastname,
|
|
|
|
contactNo: mobile,
|
|
|
|
firstName: firstname,
|
|
|
|
middleName: middlename);
|
|
|
|
} else {
|
|
|
|
personalReference = PersonalReference(
|
|
|
|
id: null,
|
|
|
|
address: address,
|
|
|
|
lastName: lastname,
|
|
|
|
contactNo: mobile,
|
|
|
|
firstName: firstname,
|
|
|
|
middleName: middlename);
|
|
|
|
}
|
|
|
|
final progress = ProgressHUD.of(context);
|
|
|
|
progress!.showWithText("Please wait...");
|
|
|
|
context.read<ReferencesBloc>().add(AddReference(
|
|
|
|
profileId: widget.profileId,
|
|
|
|
reference: personalReference,
|
|
|
|
token: widget.token));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 20,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-03-24 06:46:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> getProvinces() async {
|
|
|
|
try {
|
|
|
|
List<Province> newProvinces = await LocationUtils.instance
|
|
|
|
.getProvinces(regionCode: selectedRegion!.code.toString());
|
|
|
|
setState(() {
|
|
|
|
provinces = newProvinces;
|
|
|
|
selectedProvince = provinces![0];
|
|
|
|
provinceCall = false;
|
|
|
|
cityCall = true;
|
|
|
|
getCities();
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
context.read<ReferencesBloc>().add(CallErrorState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> getCities() async {
|
|
|
|
try {
|
|
|
|
List<CityMunicipality> newCities = await LocationUtils.instance
|
|
|
|
.getCities(code: selectedProvince!.code.toString());
|
|
|
|
citymuns = newCities;
|
|
|
|
setState(() {
|
|
|
|
selectedMunicipality = newCities[0];
|
|
|
|
cityCall = false;
|
|
|
|
barangayCall = true;
|
|
|
|
getBarangays();
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
context.read<ReferencesBloc>().add(CallErrorState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> getBarangays() async {
|
|
|
|
try {
|
|
|
|
List<Barangay> newBarangays = await LocationUtils.instance
|
|
|
|
.getBarangay(code: selectedMunicipality!.code.toString());
|
|
|
|
barangays = newBarangays;
|
|
|
|
setState(() {
|
|
|
|
selectedBarangay = newBarangays[0];
|
|
|
|
barangayCall = false;
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
context.read<ReferencesBloc>().add(CallErrorState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|