resolve address issues

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-02-23 13:51:53 +08:00
parent a7ee63627d
commit 424b1f3b47
15 changed files with 575 additions and 577 deletions

View File

@ -74,70 +74,12 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
bool? isOverseas = event.eligibityCert.overseas; bool? isOverseas = event.eligibityCert.overseas;
if (event.selectedRegion != null) {
if (event.selectedProvince == null) {
currentRegion = event.selectedRegion;
List<Province> provinces = await LocationUtils.instance
.getProvinces(regionCode: event.selectedRegion!.code.toString());
_provinces = provinces;
currentProvince = null;
currentCity = null;
}
if (event.selectedProvince != null) {
currentRegion = event.selectedRegion;
List<Province> provinces = await LocationUtils.instance
.getProvinces(regionCode: event.selectedRegion!.code.toString());
_provinces = provinces;
currentProvince = _provinces!.firstWhere(
(Province p) => event.selectedProvince!.code == p.code);
List<CityMunicipality> citymuns = await LocationUtils.instance
.getCities(code: currentProvince.code.toString());
_cities = citymuns;
currentCity = null;
}
} else {
// if exam address region is not equal to null get the region, provinces and citymunicipalities
if (event.eligibityCert.examAddress?.cityMunicipality?.province
?.region !=
null) {
currentRegion = _regions!.firstWhere((Region r) =>
event.eligibityCert.examAddress!.cityMunicipality!.province!
.region!.code ==
r.code);
List<Province> provinces = await LocationUtils.instance.getProvinces(
regionCode: event.eligibityCert.examAddress!.cityMunicipality!
.province!.region!.code!
.toString());
_provinces = provinces;
currentProvince = _provinces!.firstWhere((Province p) =>
event.eligibityCert.examAddress!.cityMunicipality!.province!
.code ==
p.code);
List<CityMunicipality> citymuns = await LocationUtils.instance
.getCities(
code: event.eligibityCert.examAddress!.cityMunicipality!
.province!.code!);
_cities = citymuns;
currentCity = _cities!.firstWhere((CityMunicipality c) =>
event.eligibityCert.examAddress!.cityMunicipality!.code ==
c.code);
}
}
emit(EditEligibilityState( emit(EditEligibilityState(
isOverseas: isOverseas!, isOverseas: isOverseas!,
currentEligibility: currentEligibility,
currentCountry: currentCountry,
currentRegion: currentRegion,
currentCity: currentCity,
cityMuns: _cities,
provinces: _provinces,
eligibityCert: event.eligibityCert, eligibityCert: event.eligibityCert,
countries: _countries!, countries: _countries!,
regions: _regions!, regions: _regions!,
currentProvince: currentProvince,
eligibilities: _eligibilities!)); eligibilities: _eligibilities!));
// }catch(e){ // }catch(e){
@ -147,13 +89,9 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
////==================================================================== ////====================================================================
}); });
on<AddEligibility>((event, emit) async { on<AddEligibility>((event, emit) async {
Region? currentRegion;
Province? currentProvince;
CityMunicipality? currentCity;
List<CityMunicipality>? cities; List<CityMunicipality>? cities;
List<Province>? provinces; List<Province>? provinces;
Eligibility? currentEligibility; Eligibility? currentEligibility;
final bool overseas = event.overseas;
emit(ProfileLoading()); emit(ProfileLoading());
if (_regions == null) { if (_regions == null) {
List<Region> regions = await LocationUtils.instance.getRegions(); List<Region> regions = await LocationUtils.instance.getRegions();
@ -168,49 +106,8 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
List<Country> countries = await LocationUtils.instance.getCountries(); List<Country> countries = await LocationUtils.instance.getCountries();
_countries = countries; _countries = countries;
} }
if(event.selectedEligibility != null){
currentEligibility = _eligibilities!.firstWhere((Eligibility element) => element.id == event.selectedEligibility!.id);
}else{
currentEligibility = null;
}
if (event.selectedRegion != null) {
if (event.selectedProvince == null) {
currentRegion = event.selectedRegion;
provinces = await LocationUtils.instance
.getProvinces(regionCode: event.selectedRegion!.code.toString());
_provinces = provinces;
currentProvince = null;
currentCity = null;
}
if (event.selectedProvince != null) {
currentRegion = event.selectedRegion;
provinces = await LocationUtils.instance
.getProvinces(regionCode: event.selectedRegion!.code.toString());
_provinces = provinces;
currentProvince = _provinces!.firstWhere(
(Province p) => event.selectedProvince!.code == p.code);
cities = await LocationUtils.instance
.getCities(code: currentProvince.code.toString());
_cities = cities;
currentCity = null;
}
}else{
print("executed");
currentRegion = null;
currentProvince = null;
currentCity = null;
_provinces = null;
_cities = null;
}
emit(AddEligibilityState( emit(AddEligibilityState(
cities: cities,
provinces: provinces,
currentEligibility: currentEligibility,
currentRegion: overseas? null: currentRegion,
currentProvince: currentProvince,
overseas: overseas,
eligibilities: _eligibilities!, eligibilities: _eligibilities!,
regions: _regions!, regions: _regions!,
countries: _countries!)); countries: _countries!));

View File

@ -30,15 +30,12 @@ class LoadEligibility extends ProfileEvent{
class EditEligibility extends ProfileEvent{ class EditEligibility extends ProfileEvent{
final EligibityCert eligibityCert; final EligibityCert eligibityCert;
final Region? selectedRegion; const EditEligibility({required this.eligibityCert});
final Province? selectedProvince;
const EditEligibility({required this.eligibityCert,this.selectedRegion, required this.selectedProvince});
@override @override
List<Object> get props => []; List<Object> get props => [];
} }
class DeleteEligibility extends ProfileEvent{ class DeleteEligibility extends ProfileEvent{
final List<EligibityCert> eligibilities; final List<EligibityCert> eligibilities;
final String profileId; final String profileId;
final int eligibilityId; final int eligibilityId;
@ -49,14 +46,7 @@ const DeleteEligibility({ required this.eligibilities, required this.eligibility
} }
class AddEligibility extends ProfileEvent{ class AddEligibility extends ProfileEvent{
final bool overseas;
final Eligibility? selectedEligibility;
final Region? selectedRegion;
final Province? selectedProvince;
const AddEligibility({required this.selectedEligibility, required this.overseas, required this.selectedProvince,this.selectedRegion});
@override
List<Object> get props => [overseas];
} }

View File

@ -31,33 +31,22 @@ class EligibilityLoaded extends ProfileState {
@override @override
List<Object> get props => [eligibilities]; List<Object> get props => [eligibilities];
} }
class EditEligibilityState extends ProfileState { class EditEligibilityState extends ProfileState {
final EligibityCert eligibityCert; final EligibityCert eligibityCert;
final List<Eligibility> eligibilities; final List<Eligibility> eligibilities;
final List<Country> countries; final List<Country> countries;
final List<Region> regions; final List<Region> regions;
List<Province>? provinces; final bool isOverseas;
List<CityMunicipality>? cityMuns; const EditEligibilityState({
Eligibility? currentEligibility; required this.isOverseas,
Country? currentCountry; required this.eligibityCert,
Region? currentRegion; required this.eligibilities,
Province? currentProvince; required this.countries,
CityMunicipality? currentCity; required this.regions,
bool isOverseas; });
EditEligibilityState( @override
{required this.currentEligibility, List<Object> get props =>
required this.currentCountry, [isOverseas, eligibityCert, eligibilities, regions, countries];
required this.currentRegion,
required this.isOverseas,
required this.cityMuns,
required this.provinces,
required this.eligibityCert,
required this.eligibilities,
required this.countries,
required this.regions,
required this.currentProvince,
required this.currentCity});
} }
class DeletedState extends ProfileState { class DeletedState extends ProfileState {
@ -69,26 +58,14 @@ class DeletedState extends ProfileState {
} }
class AddEligibilityState extends ProfileState { class AddEligibilityState extends ProfileState {
bool overseas;
Eligibility? currentEligibility;
Region? currentRegion;
Province? currentProvince;
final List<Eligibility> eligibilities; final List<Eligibility> eligibilities;
final List<Country> countries; final List<Country> countries;
final List<Region> regions; final List<Region> regions;
final List<Province>? provinces; const AddEligibilityState({
final List<CityMunicipality>? cities; required this.eligibilities,
AddEligibilityState( required this.countries,
{required this.overseas, required this.regions,
required this.eligibilities, });
required this.countries, @override
required this.regions, List<Object> get props => [eligibilities,countries,regions];
required this.cities,
required this.provinces,
required this.currentEligibility,
required this.currentProvince,
required this.currentRegion,
});
@override
List<Object> get props => [overseas];
} }

View File

@ -1,10 +1,10 @@
import 'package:date_time_picker/date_time_picker.dart'; import 'package:date_time_picker/date_time_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:intl/intl.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart';
@ -17,6 +17,7 @@ import '../../../../theme-data.dart/btn-style.dart';
import '../../../../theme-data.dart/colors.dart'; import '../../../../theme-data.dart/colors.dart';
import '../../../../theme-data.dart/form-style.dart'; import '../../../../theme-data.dart/form-style.dart';
import '../../../../utils/global.dart'; import '../../../../utils/global.dart';
import '../../../../utils/location_utilities.dart';
import '../../../../utils/text_container.dart'; import '../../../../utils/text_container.dart';
class AddEligibilityScreen extends StatefulWidget { class AddEligibilityScreen extends StatefulWidget {
@ -27,285 +28,355 @@ class AddEligibilityScreen extends StatefulWidget {
} }
class _AddEligibilityScreenState extends State<AddEligibilityScreen> { class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
final formKey = GlobalKey<FormBuilderState>();
final provinceKey = GlobalKey<FormBuilderState>();
bool? overseas;
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
Region? selectedRegion;
Province? selectedProvince;
CityMunicipality? selectedMunicipality;
Country? selectedCountry;
Eligibility? selectedEligibility;
List<Province>? provinces;
List<CityMunicipality>? citymuns;
bool provinceCall = false;
bool cityCall = false;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
bool? overseas; //USERBLOC
final formKey = GlobalKey<FormBuilderState>();
final regionKey = GlobalKey<FormBuilderState>();
Region? selectedRegion;
Province? selectedProvince;
Country? selectedCountry;
CityMunicipality selectedCity;
Eligibility? selectedEligibility;
return BlocBuilder<UserBloc, UserState>( return BlocBuilder<UserBloc, UserState>(
builder: (context, state) { builder: (context, state) {
//LOGGED IN USER STATE
if (state is UserLoggedIn) { if (state is UserLoggedIn) {
//PROFIILE BLOC
return BlocBuilder<ProfileBloc, ProfileState>( return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) { buildWhen: (previous, current) {
if (state is AddEligibilityState) { if (state is EditEligibilityState) {}
overseas = state.overseas; return false;
selectedEligibility = state.currentEligibility; },
return ProgressHUD( builder: (context, state) {
child: Center( //EDIT ELIGIBILITY STATE
child: Padding( if (state is AddEligibilityState) {
padding: const EdgeInsets.symmetric( return ProgressHUD(
vertical: 25, horizontal: 18), child: Center(
child: FormBuilder( child: Padding(
key: formKey, padding: const EdgeInsets.symmetric(
child: Column( vertical: 25, horizontal: 18),
mainAxisAlignment: MainAxisAlignment.center, child: FormBuilder(
crossAxisAlignment: CrossAxisAlignment.center, key: formKey,
children: [ child: Column(
//ELIGIBILITIES DROPDOWN mainAxisAlignment: MainAxisAlignment.center,
FormBuilderDropdown<Eligibility>( crossAxisAlignment: CrossAxisAlignment.center,
initialValue: selectedEligibility, children: [
items: state.eligibilities //ELIGIBILITIES DROPDOWN
.map<DropdownMenuItem<Eligibility>>( FormBuilderDropdown<Eligibility>(
(Eligibility eligibility) { onChanged: (Eligibility? eligibility) {
return DropdownMenuItem<Eligibility>( selectedEligibility = eligibility;
value: eligibility, },
child: Text(eligibility.title)); initialValue: state.eligibilities[0],
}).toList(), items: state.eligibilities
name: "eligibility", .map<DropdownMenuItem<Eligibility>>(
decoration: normalTextFieldStyle( (Eligibility eligibility) {
"Eligibility*", "Eligibility"), return DropdownMenuItem<Eligibility>(
), value: eligibility,
const SizedBox( child: Text(eligibility.title));
height: 20, }).toList(),
), name: "eligibility",
SizedBox( decoration:
width: screenWidth, normalTextFieldStyle("Eligibility", "")
child: Row( .copyWith(
children: [ hintStyle: const TextStyle(
//LICENSE NUMBER color: Colors.black,
Flexible( ),
flex: 1, labelStyle: const TextStyle(
child: FormBuilderTextField( color: Colors.black)),
name: 'license number', ),
initialValue: "", const SizedBox(
decoration: normalTextFieldStyle( height: 20,
"license number", "license number"), ),
),
SizedBox(
width: screenWidth,
child: Row(
children: [
//LICENSE NUMBER
Flexible(
flex: 1,
child: FormBuilderTextField(
name: 'license_number',
initialValue:null,
decoration: normalTextFieldStyle(
"license number", "license number"),
),
),
const SizedBox(
width: 12,
),
//RATING
Flexible(
flex: 1,
child: FormBuilderTextField(
name: 'rating',
// ignore: prefer_null_aware_operators
initialValue:null,
decoration: normalTextFieldStyle(
'rating', 'rating'),
),
),
],
), ),
const SizedBox( ),
width: 12, const SizedBox(
), height: 20,
//RATING ),
Flexible( SizedBox(
flex: 1, width: screenWidth,
child: FormBuilderTextField( child: Row(
name: 'rating', children: [
initialValue: "", //EXAM DATE
decoration: normalTextFieldStyle( Flexible(
'rating', 'rating'), flex: 1,
), child: DateTimePicker(
), // controller: examDateController,
], firstDate: DateTime(2000),
), lastDate: DateTime(2100),
),
const SizedBox(
height: 20,
),
SizedBox(
width: screenWidth,
child: Row(
children: [
//EXAM DATE
Flexible(
flex: 1,
child: DateTimePicker(
firstDate: DateTime(2000),
lastDate: DateTime(2100),
decoration: normalTextFieldStyle(
"Exam date", "Exam date"),
initialValue: "",
)),
const SizedBox(
width: 12,
),
//VALIDITY DATE
Flexible(
flex: 1,
child: DateTimePicker(
firstDate: DateTime(2000),
lastDate: DateTime(2100),
decoration: normalTextFieldStyle(
"Validity date", "Validity date"),
initialValue: "",
),
),
],
),
),
const SizedBox(
height: 20,
),
Text(
"Placement of Examination/Confinement",
style: Theme.of(context)
.textTheme
.displaySmall!
.copyWith(fontSize: blockSizeVertical * 2),
),
const SizedBox(
height: 12,
),
FormBuilderSwitch(
initialValue: overseas,
activeColor: second,
onChanged: (value) {
overseas = value;
regionKey.currentState?.fields['region']?.reset();
context.read<ProfileBloc>().add(AddEligibility(
selectedEligibility: selectedEligibility,
overseas: overseas!,
selectedProvince: null,
selectedRegion: null));
},
decoration: normalTextFieldStyle("", ''),
name: 'overseas',
title: const Text("Overseas Address?"),
),
const SizedBox(
height: 12,
),
SizedBox(
child: overseas == true
? FormBuilderDropdown<Country>(
initialValue: null,
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;
},
)
: Column(
children: [
//REGION DROPDOWN
FormBuilderDropdown<Region?>(
onChanged: (Region? region) {
selectedRegion = region;
context.read<ProfileBloc>().add(
AddEligibility(
selectedEligibility: selectedEligibility,
overseas: overseas!,
selectedProvince:
null,
selectedRegion:
selectedRegion));
},
initialValue: state.currentRegion,
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"Region*", "Region"), "Exam date", "Exam date"),
name: 'region', initialValue:null,
items: state.regions )),
.map<DropdownMenuItem<Region>>( const SizedBox(
(Region region) { width: 12,
return DropdownMenuItem<Region>( ),
value: region, //VALIDITY DATE
child: Flexible(
Text(region.description!)); flex: 1,
}).toList(), child: DateTimePicker(
), // controller: validityDateController,
const SizedBox( firstDate: DateTime(2000),
height: 12, lastDate: DateTime(2100),
), decoration: normalTextFieldStyle(
//PROVINCE DROPDOWN "Validity date", "Validity date"),
FormBuilderDropdown<Province?>( initialValue:null,
initialValue: state.currentProvince, ),
name: 'province', ),
onChanged: (Province? province) { ],
selectedProvince = province; ),
context.read<ProfileBloc>().add( ),
AddEligibility( const SizedBox(
selectedEligibility: selectedEligibility, height: 20,
overseas: overseas!, ),
selectedProvince: Text(
selectedProvince, "Placement of Examination/Confinement",
selectedRegion: style: Theme.of(context)
state.currentRegion)); .textTheme
}, .displaySmall!
items: state.provinces == null .copyWith(fontSize: blockSizeVertical * 2),
? [] ),
: state.provinces!.map< const SizedBox(
DropdownMenuItem< height: 12,
Province>>( ),
(Province province) { //OVERSEAS ADDRESS SWITCH
return DropdownMenuItem( Column(
value: province, children: [
child: Text(province FormBuilderSwitch(
.description!)); initialValue: overseas,
}).toList(), activeColor: second,
onChanged: (value) {
decoration: normalTextFieldStyle( setState(() {
"Province*", "Province")), overseas = value;
const SizedBox( });
height: 12, },
), decoration: normalTextFieldStyle("", ''),
FormBuilderDropdown<CityMunicipality>( name: 'overseas',
onChanged: title: const Text("Overseas Address?"),
(CityMunicipality? city) { ),
selectedCity = city!; const SizedBox(
}, height: 20,
decoration: normalTextFieldStyle( ),
"Municipality*", //COUNTRY DROPDOWN
"Municipality"), SizedBox(
name: 'municipality', child: overseas == true
items: state.cities == null ? FormBuilderDropdown<Country>(
? [] initialValue: null,
: state.cities!.map< items: state.countries.map<
DropdownMenuItem< DropdownMenuItem<
CityMunicipality>>( Country>>(
(CityMunicipality c) { (Country country) {
return DropdownMenuItem( return DropdownMenuItem<
value: c, Country>(
child: Text(c value: country,
.description!)); child: FittedBox(
}).toList(), child: Text(
initialValue: null), country.name!)));
const SizedBox( }).toList(),
height: 20, name: 'country',
), decoration: normalTextFieldStyle(
], "Country*", "Country"),
)), onChanged: (Country? value) {
const Expanded( selectedCountry = value;
child: SizedBox(), },
), )
SizedBox( : Column(
width: screenWidth, children: [
height: 60, //REGION DROPDOWN
child: ElevatedButton( FormBuilderDropdown<Region?>(
style: mainBtnStyle( onChanged:
primary, Colors.transparent, second), (Region? region) async {
onPressed: () {}, setState(() {
child: const Text(submit)), provinceCall = true;
), });
const SizedBox( selectedRegion = region;
height: 20, getProvinces();
), },
], initialValue: selectedRegion,
decoration:
normalTextFieldStyle(
"Region*", "Region"),
name: 'region',
items: state.regions.map<
DropdownMenuItem<
Region>>(
(Region region) {
return DropdownMenuItem<
Region>(
value: region,
child: Text(region
.description!));
}).toList(),
),
const SizedBox(
height: 20,
),
//PROVINCE DROPDOWN
SizedBox(
height: 50,
child: ModalProgressHUD(
inAsyncCall: cityCall,
child: DropdownButtonFormField<
Province?>(
isExpanded: true,
value: selectedProvince,
onChanged: (Province?
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")),
),
),
const SizedBox(
height: 20,
),
SizedBox(
height: 50,
child: DropdownButtonFormField<
CityMunicipality>(
onChanged:
(CityMunicipality?
city) {
selectedMunicipality =
city;
},
decoration:
normalTextFieldStyle(
"Municipality*",
"Municipality"),
value: selectedMunicipality,
items: citymuns == null
? []
: citymuns!.map<
DropdownMenuItem<
CityMunicipality>>(
(CityMunicipality
c) {
return DropdownMenuItem(
value: c,
child: Text(c
.description!));
}).toList(),
),
),
const SizedBox(
height: 20,
),
],
)),
],
),
const Expanded(
child: SizedBox(),
),
SizedBox(
width: screenWidth,
height: 60,
child: ElevatedButton(
style: mainBtnStyle(
primary, Colors.transparent, second),
onPressed: () {},
child: const Text(submit)),
),
const SizedBox(
height: 20,
),
]),
), ),
), ),
), ),
), );
); }
} return Container();
return Container(); },
}); );
} }
return Container(); return Container();
}, },
); );
} }
Future<void> getProvinces() async {
List<Province> _provinces = await LocationUtils.instance
.getProvinces(regionCode: selectedRegion!.code.toString());
setState(() {
provinces = _provinces;
selectedProvince = provinces![0];
getCities();
provinceCall = false;
});
}
Future<void> getCities()async{
List<CityMunicipality> _cities = await LocationUtils.instance.getCities(code: selectedProvince!.code.toString());
citymuns = _cities;
setState(() {
selectedMunicipality = _cities[0];
cityCall = false;
});
}
} }

View File

@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/model/location/city.dart'; import 'package:unit2/model/location/city.dart';
@ -30,17 +31,18 @@ class EditEligibilityScreen extends StatefulWidget {
class _EditEligibilityScreenState extends State<EditEligibilityScreen> { class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
final formKey = GlobalKey<FormBuilderState>(); final formKey = GlobalKey<FormBuilderState>();
final provinceKey = GlobalKey<FormBuilderState>();
bool? overseas; bool? overseas;
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
Region? selectedRegion; Region? selectedRegion;
Province? selectedProvince; Province? selectedProvince;
CityMunicipality? selectedMunicipality; CityMunicipality? selectedMunicipality;
Region? regions;
Province? province;
CityMunicipality? city;
Country? selectedCountry; Country? selectedCountry;
Eligibility? selectedEligibility; Eligibility? selectedEligibility;
List<Province>? provinces; List<Province>? provinces;
List<CityMunicipality>? citymuns;
bool provinceCall = false;
bool cityCall = false;
// final examDateController = TextEditingController(); // final examDateController = TextEditingController();
// final validityDateController = TextEditingController(); // final validityDateController = TextEditingController();
@override @override
@ -52,10 +54,13 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
if (state is UserLoggedIn) { if (state is UserLoggedIn) {
//PROFIILE BLOC //PROFIILE BLOC
return BlocBuilder<ProfileBloc, ProfileState>( return BlocBuilder<ProfileBloc, ProfileState>(
buildWhen: (previous, current) {
if (state is EditEligibilityState) {}
return false;
},
builder: (context, state) { builder: (context, state) {
//EDIT ELIGIBILITY STATE //EDIT ELIGIBILITY STATE
if (state is EditEligibilityState) { if (state is EditEligibilityState) {
overseas = state.isOverseas;
return ProgressHUD( return ProgressHUD(
child: Center( child: Center(
child: Padding( child: Padding(
@ -69,10 +74,10 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
children: [ children: [
//ELIGIBILITIES DROPDOWN //ELIGIBILITIES DROPDOWN
FormBuilderDropdown<Eligibility>( FormBuilderDropdown<Eligibility>(
onChanged: (Eligibility? eligibility){ onChanged: (Eligibility? eligibility) {
selectedEligibility = eligibility; selectedEligibility = eligibility;
}, },
initialValue: state.currentEligibility, initialValue: null,
items: state.eligibilities items: state.eligibilities
.map<DropdownMenuItem<Eligibility>>( .map<DropdownMenuItem<Eligibility>>(
(Eligibility eligibility) { (Eligibility eligibility) {
@ -117,11 +122,14 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
flex: 1, flex: 1,
child: FormBuilderTextField( child: FormBuilderTextField(
name: 'rating', name: 'rating',
// ignore: prefer_null_aware_operators // ignore: prefer_null_aware_operators
initialValue: widget initialValue:
.eligibityCert.rating== null?null:widget.eligibityCert.rating.toString(), widget.eligibityCert.rating == null
? null
: widget.eligibityCert.rating
.toString(),
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
'rating', 'rating'), 'rating', 'rating'),
), ),
@ -190,143 +198,156 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
height: 12, height: 12,
), ),
//OVERSEAS ADDRESS SWITCH //OVERSEAS ADDRESS SWITCH
FormBuilderSwitch( Column(
initialValue: overseas, children: [
activeColor: second, FormBuilderSwitch(
onChanged: (value) { initialValue: overseas,
EligibityCert newEligibility = activeColor: second,
state.eligibityCert; onChanged: (value) {
newEligibility.overseas = value!; setState(() {
// formKey.currentState!.reset(); overseas = value;
context.read<ProfileBloc>().add( });
EditEligibility( },
selectedRegion: null, decoration: normalTextFieldStyle("", ''),
selectedProvince: null, name: 'overseas',
eligibityCert: newEligibility)); title: const Text("Overseas Address?"),
}, ),
decoration: normalTextFieldStyle("", ''), const SizedBox(
name: 'overseas', height: 20,
title: const Text("Overseas Address?"), ),
), //COUNTRY DROPDOWN
const SizedBox( SizedBox(
height: 20, child: overseas == true
), ? FormBuilderDropdown<Country>(
//COUNTRY DROPDOWN initialValue: null,
SizedBox( items: state.countries.map<
child: overseas == true DropdownMenuItem<
? FormBuilderDropdown<Country>( Country>>(
initialValue: state.currentCountry,
items: state.countries
.map<DropdownMenuItem<Country>>(
(Country country) { (Country country) {
return DropdownMenuItem<Country>( return DropdownMenuItem<
value: country, Country>(
child: FittedBox( value: country,
child: child: FittedBox(
Text(country.name!))); child: Text(
}).toList(), country.name!)));
name: 'country',
decoration: normalTextFieldStyle(
"Country*", "Country"),
onChanged: (Country? value) {
selectedCountry = value;
},
)
: Column(
children: [
//REGION DROPDOWN
FormBuilderDropdown<Region?>(
onChanged: (Region? region) {
selectedRegion = region;
context.read<ProfileBloc>().add(
EditEligibility(
eligibityCert:
state.eligibityCert,
selectedProvince: null,
selectedRegion:
selectedRegion));
},
initialValue: state.currentRegion,
decoration: normalTextFieldStyle(
"Region*", "Region"),
name: 'region',
items: state.regions.map<
DropdownMenuItem<Region>>(
(Region region) {
return DropdownMenuItem<Region>(
value: region,
child: Text(
region.description!));
}).toList(), }).toList(),
), name: 'country',
const SizedBox( decoration: normalTextFieldStyle(
height: 20, "Country*", "Country"),
), onChanged: (Country? value) {
//PROVINCE DROPDOWN selectedCountry = value;
FormBuilderDropdown<Province?>( },
initialValue:state.currentProvince, )
name: 'province', : Column(
onChanged: children: [
(Province? province) { //REGION DROPDOWN
selectedProvince = province; FormBuilderDropdown<Region?>(
context onChanged:
.read<ProfileBloc>() (Region? region) async {
.add(EditEligibility( setState(() {
eligibityCert: state provinceCall = true;
.eligibityCert, });
selectedProvince: selectedRegion = region;
selectedProvince, getProvinces();
selectedRegion: state },
.currentRegion)); initialValue: selectedRegion,
}, decoration:
items: state.provinces == null normalTextFieldStyle(
? [] "Region*", "Region"),
: state.provinces!.map< name: 'region',
DropdownMenuItem< items: state.regions.map<
Province>>( DropdownMenuItem<
(Province province) { Region>>(
return DropdownMenuItem( (Region region) {
value: province, return DropdownMenuItem<
child: Text(province Region>(
.description!)); value: region,
}).toList(), child: Text(region
decoration: .description!));
normalTextFieldStyle( }).toList(),
"Province*", ),
"Province")), const SizedBox(
const SizedBox( height: 20,
height: 20, ),
), //PROVINCE DROPDOWN
FormBuilderDropdown< SizedBox(
CityMunicipality>( height: 50,
onChanged: (CityMunicipality? city){ child: ModalProgressHUD(
selectedMunicipality = city; inAsyncCall: cityCall,
child: DropdownButtonFormField<
Province?>(
isExpanded: true,
value: selectedProvince,
onChanged: (Province?
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")),
),
),
const SizedBox(
height: 20,
),
SizedBox(
height: 50,
child: DropdownButtonFormField<
CityMunicipality>(
onChanged:
(CityMunicipality?
city) {
selectedMunicipality =
city;
}, },
decoration: decoration:
normalTextFieldStyle( normalTextFieldStyle(
"Municipality*", "Municipality*",
"Municipality"), "Municipality"),
name: 'municipality', value: selectedMunicipality,
items: state.cityMuns == null items: citymuns == null
? [] ? []
: state.cityMuns!.map< : citymuns!.map<
DropdownMenuItem< DropdownMenuItem<
CityMunicipality>>( CityMunicipality>>(
(CityMunicipality c) { (CityMunicipality
return DropdownMenuItem( c) {
value: c, return DropdownMenuItem(
child: Text(c value: c,
.description!)); child: Text(c
}).toList(), .description!));
initialValue: }).toList(),
state.currentCity), ),
const SizedBox( ),
height: 20, const SizedBox(
), height: 20,
], ),
)), ],
)),
],
),
const Expanded( const Expanded(
child: SizedBox(), child: SizedBox(),
), ),
@ -357,4 +378,23 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
}, },
); );
} }
Future<void> getProvinces() async {
List<Province> _provinces = await LocationUtils.instance
.getProvinces(regionCode: selectedRegion!.code.toString());
setState(() {
provinces = _provinces;
selectedProvince = provinces![0];
getCities();
provinceCall = false;
});
}
Future<void> getCities()async{
List<CityMunicipality> _cities = await LocationUtils.instance.getCities(code: selectedProvince!.code.toString());
citymuns = _cities;
setState(() {
selectedMunicipality = _cities[0];
cityCall = false;
});
}
} }

View File

@ -29,7 +29,7 @@ class EligibiltyScreen extends StatelessWidget {
centerTitle: true, centerTitle: true,
backgroundColor: primary, backgroundColor: primary,
actions: [AddLeading(onPressed: () { actions: [AddLeading(onPressed: () {
context.read<ProfileBloc>().add(const AddEligibility(overseas: false,selectedProvince: null,selectedRegion: null,selectedEligibility: null)); context.read<ProfileBloc>().add( AddEligibility());
})], })],
), ),
body: BlocBuilder<UserBloc, UserState>( body: BlocBuilder<UserBloc, UserState>(
@ -172,8 +172,7 @@ class EligibiltyScreen extends StatelessWidget {
.showWithText("Loading..."); .showWithText("Loading...");
context.read<ProfileBloc>().add( context.read<ProfileBloc>().add(
EditEligibility( EditEligibility(
selectedProvince: null,
selectedRegion: null,
eligibityCert: eligibityCert:
eligibityCert)); eligibityCert));
} }

View File

@ -20,10 +20,9 @@ class AuthService {
'X-User': "" 'X-User': ""
}; };
try { try {
http.Response response = await http.get( String path = Url.instance.latestApk();
Uri.https('unitylb1.agusandelnorte.gov.ph', http.Response response = await Request.instance.getRequest(path: path,headers: headers,param: {});
'/unit2/api/sys/apk_version/latest/'),
headers: headers);
if (response.statusCode == 200) { if (response.statusCode == 200) {
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
versionInfo = VersionInfo.fromJson(data['data']); versionInfo = VersionInfo.fromJson(data['data']);

View File

@ -5,7 +5,8 @@ class Url {
String host() { String host() {
// return '192.168.10.221:3003'; // return '192.168.10.221:3003';
// return 'agusandelnorte.gov.ph'; // return 'agusandelnorte.gov.ph';
return 'devweb.agusandelnorte.gov.ph'; return "192.168.10.219:3000";
// return 'devweb.agusandelnorte.gov.ph';
} }
String authentication() { String authentication() {
@ -16,6 +17,10 @@ class Url {
return '/api/jobnet_app/profile/pds/'; return '/api/jobnet_app/profile/pds/';
} }
String latestApk(){
return "/api/system_app/apk_version/latest";
}
String eligibilities(){ String eligibilities(){
return "/api/jobnet_app/eligibilities/"; return "/api/jobnet_app/eligibilities/";
} }

View File

@ -6,6 +6,10 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <modal_progress_hud_nsn/modal_progress_hud_nsn_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) { void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) modal_progress_hud_nsn_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "ModalProgressHudNsnPlugin");
modal_progress_hud_nsn_plugin_register_with_registrar(modal_progress_hud_nsn_registrar);
} }

View File

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
modal_progress_hud_nsn
) )
list(APPEND FLUTTER_FFI_PLUGIN_LIST list(APPEND FLUTTER_FFI_PLUGIN_LIST

View File

@ -5,12 +5,14 @@
import FlutterMacOS import FlutterMacOS
import Foundation import Foundation
import modal_progress_hud_nsn
import package_info_plus import package_info_plus
import path_provider_foundation import path_provider_foundation
import shared_preferences_foundation import shared_preferences_foundation
import sqflite import sqflite
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
ModalProgressHudNsnPlugin.register(with: registry.registrar(forPlugin: "ModalProgressHudNsnPlugin"))
FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))

View File

@ -517,6 +517,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.8.0" version: "1.8.0"
modal_progress_hud_nsn:
dependency: "direct main"
description:
name: modal_progress_hud_nsn
sha256: "408b9bcce97567de94637de932260e50be48db1842edc761aeea61670e5ec30c"
url: "https://pub.dev"
source: hosted
version: "0.3.0"
nested: nested:
dependency: transitive dependency: transitive
description: description:

View File

@ -69,6 +69,7 @@ dependencies:
expandable_group: ^0.0.8 expandable_group: ^0.0.8
badges: ^3.0.2 badges: ^3.0.2
app_popup_menu: ^1.0.0 app_popup_menu: ^1.0.0
modal_progress_hud_nsn: ^0.3.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

View File

@ -6,9 +6,12 @@
#include "generated_plugin_registrant.h" #include "generated_plugin_registrant.h"
#include <modal_progress_hud_nsn/modal_progress_hud_nsn_plugin.h>
#include <permission_handler_windows/permission_handler_windows_plugin.h> #include <permission_handler_windows/permission_handler_windows_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) { void RegisterPlugins(flutter::PluginRegistry* registry) {
ModalProgressHudNsnPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ModalProgressHudNsnPlugin"));
PermissionHandlerWindowsPluginRegisterWithRegistrar( PermissionHandlerWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin"));
} }

View File

@ -3,6 +3,7 @@
# #
list(APPEND FLUTTER_PLUGIN_LIST list(APPEND FLUTTER_PLUGIN_LIST
modal_progress_hud_nsn
permission_handler_windows permission_handler_windows
) )