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();
@ -169,48 +107,7 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
_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;
@ -50,13 +47,6 @@ 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;
Country? currentCountry;
Region? currentRegion;
Province? currentProvince;
CityMunicipality? currentCity;
bool isOverseas;
EditEligibilityState(
{required this.currentEligibility,
required this.currentCountry,
required this.currentRegion,
required this.isOverseas, required this.isOverseas,
required this.cityMuns,
required this.provinces,
required this.eligibityCert, required this.eligibityCert,
required this.eligibilities, required this.eligibilities,
required this.countries, required this.countries,
required this.regions, required this.regions,
required this.currentProvince, });
required this.currentCity}); @override
List<Object> get props =>
[isOverseas, eligibityCert, eligibilities, regions, countries];
} }
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;
AddEligibilityState(
{required this.overseas,
required this.eligibilities, required this.eligibilities,
required this.countries, required this.countries,
required this.regions, required this.regions,
required this.cities,
required this.provinces,
required this.currentEligibility,
required this.currentProvince,
required this.currentRegion,
}); });
@override @override
List<Object> get props => [overseas]; List<Object> get props => [eligibilities,countries,regions];
} }

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,24 +28,35 @@ class AddEligibilityScreen extends StatefulWidget {
} }
class _AddEligibilityScreenState extends State<AddEligibilityScreen> { class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
@override
Widget build(BuildContext context) {
bool? overseas;
final formKey = GlobalKey<FormBuilderState>(); final formKey = GlobalKey<FormBuilderState>();
final regionKey = GlobalKey<FormBuilderState>(); final provinceKey = GlobalKey<FormBuilderState>();
bool? overseas;
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
Region? selectedRegion; Region? selectedRegion;
Province? selectedProvince; Province? selectedProvince;
CityMunicipality? selectedMunicipality;
Country? selectedCountry; Country? selectedCountry;
CityMunicipality selectedCity;
Eligibility? selectedEligibility; Eligibility? selectedEligibility;
List<Province>? provinces;
List<CityMunicipality>? citymuns;
bool provinceCall = false;
bool cityCall = false;
@override
Widget build(BuildContext context) {
//USERBLOC
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>(
buildWhen: (previous, current) {
if (state is EditEligibilityState) {}
return false;
},
builder: (context, state) { builder: (context, state) {
//EDIT ELIGIBILITY STATE
if (state is AddEligibilityState) { if (state is AddEligibilityState) {
overseas = state.overseas;
selectedEligibility = state.currentEligibility;
return ProgressHUD( return ProgressHUD(
child: Center( child: Center(
child: Padding( child: Padding(
@ -58,7 +70,10 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
children: [ children: [
//ELIGIBILITIES DROPDOWN //ELIGIBILITIES DROPDOWN
FormBuilderDropdown<Eligibility>( FormBuilderDropdown<Eligibility>(
initialValue: selectedEligibility, onChanged: (Eligibility? eligibility) {
selectedEligibility = eligibility;
},
initialValue: state.eligibilities[0],
items: state.eligibilities items: state.eligibilities
.map<DropdownMenuItem<Eligibility>>( .map<DropdownMenuItem<Eligibility>>(
(Eligibility eligibility) { (Eligibility eligibility) {
@ -67,12 +82,19 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
child: Text(eligibility.title)); child: Text(eligibility.title));
}).toList(), }).toList(),
name: "eligibility", name: "eligibility",
decoration: normalTextFieldStyle( decoration:
"Eligibility*", "Eligibility"), normalTextFieldStyle("Eligibility", "")
.copyWith(
hintStyle: const TextStyle(
color: Colors.black,
),
labelStyle: const TextStyle(
color: Colors.black)),
), ),
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
SizedBox( SizedBox(
width: screenWidth, width: screenWidth,
child: Row( child: Row(
@ -81,8 +103,9 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
Flexible( Flexible(
flex: 1, flex: 1,
child: FormBuilderTextField( child: FormBuilderTextField(
name: 'license number', name: 'license_number',
initialValue: "", initialValue:null,
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"license number", "license number"), "license number", "license number"),
), ),
@ -95,7 +118,11 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
flex: 1, flex: 1,
child: FormBuilderTextField( child: FormBuilderTextField(
name: 'rating', name: 'rating',
initialValue: "",
// ignore: prefer_null_aware_operators
initialValue:null,
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
'rating', 'rating'), 'rating', 'rating'),
), ),
@ -114,11 +141,12 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
Flexible( Flexible(
flex: 1, flex: 1,
child: DateTimePicker( child: DateTimePicker(
// controller: examDateController,
firstDate: DateTime(2000), firstDate: DateTime(2000),
lastDate: DateTime(2100), lastDate: DateTime(2100),
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"Exam date", "Exam date"), "Exam date", "Exam date"),
initialValue: "", initialValue:null,
)), )),
const SizedBox( const SizedBox(
width: 12, width: 12,
@ -127,11 +155,12 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
Flexible( Flexible(
flex: 1, flex: 1,
child: DateTimePicker( child: DateTimePicker(
// controller: validityDateController,
firstDate: DateTime(2000), firstDate: DateTime(2000),
lastDate: DateTime(2100), lastDate: DateTime(2100),
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"Validity date", "Validity date"), "Validity date", "Validity date"),
initialValue: "", initialValue:null,
), ),
), ),
], ],
@ -150,38 +179,39 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
const SizedBox( const SizedBox(
height: 12, height: 12,
), ),
//OVERSEAS ADDRESS SWITCH
Column(
children: [
FormBuilderSwitch( FormBuilderSwitch(
initialValue: overseas, initialValue: overseas,
activeColor: second, activeColor: second,
onChanged: (value) { onChanged: (value) {
setState(() {
overseas = value; overseas = value;
});
regionKey.currentState?.fields['region']?.reset();
context.read<ProfileBloc>().add(AddEligibility(
selectedEligibility: selectedEligibility,
overseas: overseas!,
selectedProvince: null,
selectedRegion: null));
}, },
decoration: normalTextFieldStyle("", ''), decoration: normalTextFieldStyle("", ''),
name: 'overseas', name: 'overseas',
title: const Text("Overseas Address?"), title: const Text("Overseas Address?"),
), ),
const SizedBox( const SizedBox(
height: 12, height: 20,
), ),
//COUNTRY DROPDOWN
SizedBox( SizedBox(
child: overseas == true child: overseas == true
? FormBuilderDropdown<Country>( ? FormBuilderDropdown<Country>(
initialValue: null, initialValue: null,
items: state.countries items: state.countries.map<
.map<DropdownMenuItem<Country>>( DropdownMenuItem<
Country>>(
(Country country) { (Country country) {
return DropdownMenuItem<Country>( return DropdownMenuItem<
Country>(
value: country, value: country,
child: FittedBox( child: FittedBox(
child: Text(country.name!))); child: Text(
country.name!)));
}).toList(), }).toList(),
name: 'country', name: 'country',
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
@ -194,94 +224,116 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
children: [ children: [
//REGION DROPDOWN //REGION DROPDOWN
FormBuilderDropdown<Region?>( FormBuilderDropdown<Region?>(
onChanged: (Region? region) { onChanged:
(Region? region) async {
setState(() {
provinceCall = true;
});
selectedRegion = region; selectedRegion = region;
context.read<ProfileBloc>().add( getProvinces();
AddEligibility(
selectedEligibility: selectedEligibility,
overseas: overseas!,
selectedProvince:
null,
selectedRegion:
selectedRegion));
}, },
initialValue: state.currentRegion, initialValue: selectedRegion,
decoration: normalTextFieldStyle( decoration:
normalTextFieldStyle(
"Region*", "Region"), "Region*", "Region"),
name: 'region', name: 'region',
items: state.regions items: state.regions.map<
.map<DropdownMenuItem<Region>>(
(Region region) {
return DropdownMenuItem<Region>(
value: region,
child:
Text(region.description!));
}).toList(),
),
const SizedBox(
height: 12,
),
//PROVINCE DROPDOWN
FormBuilderDropdown<Province?>(
initialValue: state.currentProvince,
name: 'province',
onChanged: (Province? province) {
selectedProvince = province;
context.read<ProfileBloc>().add(
AddEligibility(
selectedEligibility: selectedEligibility,
overseas: overseas!,
selectedProvince:
selectedProvince,
selectedRegion:
state.currentRegion));
},
items: state.provinces == null
? []
: state.provinces!.map<
DropdownMenuItem< DropdownMenuItem<
Province>>( Region>>(
(Province province) { (Region region) {
return DropdownMenuItem( return DropdownMenuItem<
value: province, Region>(
child: Text(province value: region,
child: Text(region
.description!)); .description!));
}).toList(), }).toList(),
decoration: normalTextFieldStyle(
"Province*", "Province")),
const SizedBox(
height: 12,
), ),
FormBuilderDropdown<CityMunicipality>( const SizedBox(
onChanged: height: 20,
(CityMunicipality? city) { ),
selectedCity = city!; //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();
}, },
decoration: normalTextFieldStyle( 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*",
"Municipality"), "Municipality"),
name: 'municipality', value: selectedMunicipality,
items: state.cities == null items: citymuns == null
? [] ? []
: state.cities!.map< : citymuns!.map<
DropdownMenuItem< DropdownMenuItem<
CityMunicipality>>( CityMunicipality>>(
(CityMunicipality c) { (CityMunicipality
c) {
return DropdownMenuItem( return DropdownMenuItem(
value: c, value: c,
child: Text(c child: Text(c
.description!)); .description!));
}).toList(), }).toList(),
initialValue: null), ),
),
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
], ],
)), )),
],
),
const Expanded( const Expanded(
child: SizedBox(), child: SizedBox(),
), ),
SizedBox( SizedBox(
width: screenWidth, width: screenWidth,
height: 60, height: 60,
@ -294,18 +346,37 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
const SizedBox( const SizedBox(
height: 20, 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(
@ -72,7 +77,7 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
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) {
@ -119,8 +124,11 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
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,19 +198,15 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
height: 12, height: 12,
), ),
//OVERSEAS ADDRESS SWITCH //OVERSEAS ADDRESS SWITCH
Column(
children: [
FormBuilderSwitch( FormBuilderSwitch(
initialValue: overseas, initialValue: overseas,
activeColor: second, activeColor: second,
onChanged: (value) { onChanged: (value) {
EligibityCert newEligibility = setState(() {
state.eligibityCert; overseas = value;
newEligibility.overseas = value!; });
// formKey.currentState!.reset();
context.read<ProfileBloc>().add(
EditEligibility(
selectedRegion: null,
selectedProvince: null,
eligibityCert: newEligibility));
}, },
decoration: normalTextFieldStyle("", ''), decoration: normalTextFieldStyle("", ''),
name: 'overseas', name: 'overseas',
@ -215,16 +219,17 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
SizedBox( SizedBox(
child: overseas == true child: overseas == true
? FormBuilderDropdown<Country>( ? FormBuilderDropdown<Country>(
initialValue: state.currentCountry, initialValue: null,
items: state.countries.map<
items: state.countries DropdownMenuItem<
.map<DropdownMenuItem<Country>>( Country>>(
(Country country) { (Country country) {
return DropdownMenuItem<Country>( return DropdownMenuItem<
Country>(
value: country, value: country,
child: FittedBox( child: FittedBox(
child: child: Text(
Text(country.name!))); country.name!)));
}).toList(), }).toList(),
name: 'country', name: 'country',
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
@ -237,96 +242,112 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
children: [ children: [
//REGION DROPDOWN //REGION DROPDOWN
FormBuilderDropdown<Region?>( FormBuilderDropdown<Region?>(
onChanged: (Region? region) { onChanged:
(Region? region) async {
setState(() {
provinceCall = true;
});
selectedRegion = region; selectedRegion = region;
getProvinces();
context.read<ProfileBloc>().add(
EditEligibility(
eligibityCert:
state.eligibityCert,
selectedProvince: null,
selectedRegion:
selectedRegion));
}, },
initialValue: state.currentRegion, initialValue: selectedRegion,
decoration: normalTextFieldStyle( decoration:
normalTextFieldStyle(
"Region*", "Region"), "Region*", "Region"),
name: 'region', name: 'region',
items: state.regions.map< items: state.regions.map<
DropdownMenuItem<Region>>( DropdownMenuItem<
Region>>(
(Region region) { (Region region) {
return DropdownMenuItem<Region>( return DropdownMenuItem<
Region>(
value: region, value: region,
child: Text( child: Text(region
region.description!)); .description!));
}).toList(), }).toList(),
), ),
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
//PROVINCE DROPDOWN //PROVINCE DROPDOWN
FormBuilderDropdown<Province?>( SizedBox(
initialValue:state.currentProvince, height: 50,
name: 'province', child: ModalProgressHUD(
onChanged: inAsyncCall: cityCall,
(Province? province) { child: DropdownButtonFormField<
Province?>(
isExpanded: true,
value: selectedProvince,
onChanged: (Province?
province) {
setState(() {
cityCall = true;
});
selectedProvince = province; selectedProvince = province;
context getCities();
.read<ProfileBloc>()
.add(EditEligibility(
eligibityCert: state
.eligibityCert,
selectedProvince:
selectedProvince,
selectedRegion: state
.currentRegion));
}, },
items: state.provinces == null items: provinces == null
? [] ? []
: state.provinces!.map< : provinces!.map<
DropdownMenuItem< DropdownMenuItem<
Province>>( Province>>(
(Province province) { (Province
province) {
return DropdownMenuItem( return DropdownMenuItem(
value: province, value:
child: Text(province province,
.description!)); child: FittedBox(
child: Text(
province
.description!),
));
}).toList(), }).toList(),
decoration: decoration:
normalTextFieldStyle( normalTextFieldStyle(
"Province*", "Province*",
"Province")), "Province")),
),
),
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
FormBuilderDropdown< SizedBox(
height: 50,
child: DropdownButtonFormField<
CityMunicipality>( CityMunicipality>(
onChanged: (CityMunicipality? city){ onChanged:
selectedMunicipality = city; (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
c) {
return DropdownMenuItem( return DropdownMenuItem(
value: c, value: c,
child: Text(c child: Text(c
.description!)); .description!));
}).toList(), }).toList(),
initialValue: ),
state.currentCity), ),
const SizedBox( const SizedBox(
height: 20, 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
) )