From 424b1f3b470f528bd541235d60c9453e3f3c1b87 Mon Sep 17 00:00:00 2001 From: PGAN-MIS Date: Thu, 23 Feb 2023 13:51:53 +0800 Subject: [PATCH] resolve address issues --- lib/bloc/profile/profile_bloc.dart | 107 +--- lib/bloc/profile/profile_event.dart | 14 +- lib/bloc/profile/profile_state.dart | 59 +- .../components/eligibility/add_modal.dart | 605 ++++++++++-------- .../components/eligibility/edit_modal.dart | 328 +++++----- .../components/eligibility_screen.dart | 5 +- lib/sevices/login_service/auth_service.dart | 7 +- lib/utils/urls.dart | 7 +- linux/flutter/generated_plugin_registrant.cc | 4 + linux/flutter/generated_plugins.cmake | 1 + macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 8 + pubspec.yaml | 1 + .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 15 files changed, 575 insertions(+), 577 deletions(-) diff --git a/lib/bloc/profile/profile_bloc.dart b/lib/bloc/profile/profile_bloc.dart index 0b755a6..b7aace6 100644 --- a/lib/bloc/profile/profile_bloc.dart +++ b/lib/bloc/profile/profile_bloc.dart @@ -74,70 +74,12 @@ class ProfileBloc extends Bloc { bool? isOverseas = event.eligibityCert.overseas; - if (event.selectedRegion != null) { - if (event.selectedProvince == null) { - currentRegion = event.selectedRegion; - List provinces = await LocationUtils.instance - .getProvinces(regionCode: event.selectedRegion!.code.toString()); - _provinces = provinces; - currentProvince = null; - currentCity = null; - } - if (event.selectedProvince != null) { - currentRegion = event.selectedRegion; - List provinces = await LocationUtils.instance - .getProvinces(regionCode: event.selectedRegion!.code.toString()); - _provinces = provinces; - currentProvince = _provinces!.firstWhere( - (Province p) => event.selectedProvince!.code == p.code); - List 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 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 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( isOverseas: isOverseas!, - currentEligibility: currentEligibility, - currentCountry: currentCountry, - currentRegion: currentRegion, - currentCity: currentCity, - cityMuns: _cities, - provinces: _provinces, eligibityCert: event.eligibityCert, countries: _countries!, regions: _regions!, - currentProvince: currentProvince, eligibilities: _eligibilities!)); // }catch(e){ @@ -147,13 +89,9 @@ class ProfileBloc extends Bloc { ////==================================================================== }); on((event, emit) async { - Region? currentRegion; - Province? currentProvince; - CityMunicipality? currentCity; List? cities; List? provinces; Eligibility? currentEligibility; - final bool overseas = event.overseas; emit(ProfileLoading()); if (_regions == null) { List regions = await LocationUtils.instance.getRegions(); @@ -168,49 +106,8 @@ class ProfileBloc extends Bloc { List countries = await LocationUtils.instance.getCountries(); _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( - cities: cities, - provinces: provinces, - currentEligibility: currentEligibility, - currentRegion: overseas? null: currentRegion, - currentProvince: currentProvince, - overseas: overseas, eligibilities: _eligibilities!, regions: _regions!, countries: _countries!)); diff --git a/lib/bloc/profile/profile_event.dart b/lib/bloc/profile/profile_event.dart index ebb0beb..11bd0d3 100644 --- a/lib/bloc/profile/profile_event.dart +++ b/lib/bloc/profile/profile_event.dart @@ -30,15 +30,12 @@ class LoadEligibility extends ProfileEvent{ class EditEligibility extends ProfileEvent{ final EligibityCert eligibityCert; - final Region? selectedRegion; - final Province? selectedProvince; - const EditEligibility({required this.eligibityCert,this.selectedRegion, required this.selectedProvince}); + const EditEligibility({required this.eligibityCert}); @override List get props => []; } class DeleteEligibility extends ProfileEvent{ - final List eligibilities; final String profileId; final int eligibilityId; @@ -49,14 +46,7 @@ const DeleteEligibility({ required this.eligibilities, required this.eligibility } 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 get props => [overseas]; + } diff --git a/lib/bloc/profile/profile_state.dart b/lib/bloc/profile/profile_state.dart index f8ef628..52a2eb5 100644 --- a/lib/bloc/profile/profile_state.dart +++ b/lib/bloc/profile/profile_state.dart @@ -31,33 +31,22 @@ class EligibilityLoaded extends ProfileState { @override List get props => [eligibilities]; } - class EditEligibilityState extends ProfileState { final EligibityCert eligibityCert; final List eligibilities; final List countries; final List regions; - List? provinces; - List? cityMuns; - 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.cityMuns, - required this.provinces, - required this.eligibityCert, - required this.eligibilities, - required this.countries, - required this.regions, - required this.currentProvince, - required this.currentCity}); + final bool isOverseas; + const EditEligibilityState({ + required this.isOverseas, + required this.eligibityCert, + required this.eligibilities, + required this.countries, + required this.regions, + }); + @override + List get props => + [isOverseas, eligibityCert, eligibilities, regions, countries]; } class DeletedState extends ProfileState { @@ -69,26 +58,14 @@ class DeletedState extends ProfileState { } class AddEligibilityState extends ProfileState { - bool overseas; - Eligibility? currentEligibility; - Region? currentRegion; - Province? currentProvince; final List eligibilities; final List countries; final List regions; - final List? provinces; - final List? cities; - AddEligibilityState( - {required this.overseas, - required this.eligibilities, - required this.countries, - required this.regions, - required this.cities, - required this.provinces, - required this.currentEligibility, - required this.currentProvince, - required this.currentRegion, - }); - @override - List get props => [overseas]; + const AddEligibilityState({ + required this.eligibilities, + required this.countries, + required this.regions, + }); + @override + List get props => [eligibilities,countries,regions]; } diff --git a/lib/screens/profile/components/eligibility/add_modal.dart b/lib/screens/profile/components/eligibility/add_modal.dart index dc80a89..7a79eea 100644 --- a/lib/screens/profile/components/eligibility/add_modal.dart +++ b/lib/screens/profile/components/eligibility/add_modal.dart @@ -1,10 +1,10 @@ import 'package:date_time_picker/date_time_picker.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_form_builder/flutter_form_builder.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/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/form-style.dart'; import '../../../../utils/global.dart'; +import '../../../../utils/location_utilities.dart'; import '../../../../utils/text_container.dart'; class AddEligibilityScreen extends StatefulWidget { @@ -27,285 +28,355 @@ class AddEligibilityScreen extends StatefulWidget { } class _AddEligibilityScreenState extends State { + final formKey = GlobalKey(); + final provinceKey = GlobalKey(); + bool? overseas; + DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); + Region? selectedRegion; + Province? selectedProvince; + CityMunicipality? selectedMunicipality; + Country? selectedCountry; + Eligibility? selectedEligibility; + List? provinces; + List? citymuns; + bool provinceCall = false; + bool cityCall = false; @override Widget build(BuildContext context) { - bool? overseas; - final formKey = GlobalKey(); - final regionKey = GlobalKey(); - Region? selectedRegion; - Province? selectedProvince; - Country? selectedCountry; - CityMunicipality selectedCity; - Eligibility? selectedEligibility; + //USERBLOC return BlocBuilder( builder: (context, state) { + //LOGGED IN USER STATE if (state is UserLoggedIn) { + //PROFIILE BLOC return BlocBuilder( - builder: (context, state) { - if (state is AddEligibilityState) { - overseas = state.overseas; - selectedEligibility = state.currentEligibility; - return ProgressHUD( - child: Center( - child: Padding( - padding: const EdgeInsets.symmetric( - vertical: 25, horizontal: 18), - child: FormBuilder( - key: formKey, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - //ELIGIBILITIES DROPDOWN - FormBuilderDropdown( - initialValue: selectedEligibility, - items: state.eligibilities - .map>( - (Eligibility eligibility) { - return DropdownMenuItem( - value: eligibility, - child: Text(eligibility.title)); - }).toList(), - name: "eligibility", - decoration: normalTextFieldStyle( - "Eligibility*", "Eligibility"), - ), - const SizedBox( - height: 20, - ), - SizedBox( - width: screenWidth, - child: Row( - children: [ - //LICENSE NUMBER - Flexible( - flex: 1, - child: FormBuilderTextField( - name: 'license number', - initialValue: "", - decoration: normalTextFieldStyle( - "license number", "license number"), - ), + buildWhen: (previous, current) { + if (state is EditEligibilityState) {} + return false; + }, + builder: (context, state) { + //EDIT ELIGIBILITY STATE + if (state is AddEligibilityState) { + return ProgressHUD( + child: Center( + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 25, horizontal: 18), + child: FormBuilder( + key: formKey, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + //ELIGIBILITIES DROPDOWN + FormBuilderDropdown( + onChanged: (Eligibility? eligibility) { + selectedEligibility = eligibility; + }, + initialValue: state.eligibilities[0], + items: state.eligibilities + .map>( + (Eligibility eligibility) { + return DropdownMenuItem( + value: eligibility, + child: Text(eligibility.title)); + }).toList(), + name: "eligibility", + decoration: + normalTextFieldStyle("Eligibility", "") + .copyWith( + hintStyle: const TextStyle( + color: Colors.black, + ), + labelStyle: const TextStyle( + color: Colors.black)), + ), + const SizedBox( + height: 20, + ), + + 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, - ), - //RATING - Flexible( - flex: 1, - child: FormBuilderTextField( - name: 'rating', - initialValue: "", - decoration: normalTextFieldStyle( - 'rating', 'rating'), - ), - ), - ], - ), - ), - 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().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( - initialValue: null, - items: state.countries - .map>( - (Country country) { - return DropdownMenuItem( - 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( - onChanged: (Region? region) { - selectedRegion = region; - context.read().add( - AddEligibility( - selectedEligibility: selectedEligibility, - overseas: overseas!, - selectedProvince: - null, - selectedRegion: - selectedRegion)); - }, - initialValue: state.currentRegion, + ), + const SizedBox( + height: 20, + ), + SizedBox( + width: screenWidth, + child: Row( + children: [ + //EXAM DATE + Flexible( + flex: 1, + child: DateTimePicker( + // controller: examDateController, + firstDate: DateTime(2000), + lastDate: DateTime(2100), decoration: normalTextFieldStyle( - "Region*", "Region"), - name: 'region', - items: state.regions - .map>( - (Region region) { - return DropdownMenuItem( - value: region, - child: - Text(region.description!)); - }).toList(), - ), - const SizedBox( - height: 12, - ), - //PROVINCE DROPDOWN - FormBuilderDropdown( - initialValue: state.currentProvince, - name: 'province', - onChanged: (Province? province) { - selectedProvince = province; - context.read().add( - AddEligibility( - selectedEligibility: selectedEligibility, - overseas: overseas!, - selectedProvince: - selectedProvince, - selectedRegion: - state.currentRegion)); - }, - items: state.provinces == null - ? [] - : state.provinces!.map< - DropdownMenuItem< - Province>>( - (Province province) { - return DropdownMenuItem( - value: province, - child: Text(province - .description!)); - }).toList(), - - decoration: normalTextFieldStyle( - "Province*", "Province")), - const SizedBox( - height: 12, - ), - FormBuilderDropdown( - onChanged: - (CityMunicipality? city) { - selectedCity = city!; - }, - decoration: normalTextFieldStyle( - "Municipality*", - "Municipality"), - name: 'municipality', - items: state.cities == null - ? [] - : state.cities!.map< - DropdownMenuItem< - CityMunicipality>>( - (CityMunicipality c) { - return DropdownMenuItem( - value: c, - child: Text(c - .description!)); - }).toList(), - initialValue: null), - 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, - ), - ], + "Exam date", "Exam date"), + initialValue:null, + )), + const SizedBox( + width: 12, + ), + //VALIDITY DATE + Flexible( + flex: 1, + child: DateTimePicker( + // controller: validityDateController, + firstDate: DateTime(2000), + lastDate: DateTime(2100), + decoration: normalTextFieldStyle( + "Validity date", "Validity date"), + initialValue:null, + ), + ), + ], + ), + ), + const SizedBox( + height: 20, + ), + Text( + "Placement of Examination/Confinement", + style: Theme.of(context) + .textTheme + .displaySmall! + .copyWith(fontSize: blockSizeVertical * 2), + ), + const SizedBox( + height: 12, + ), + //OVERSEAS ADDRESS SWITCH + Column( + children: [ + FormBuilderSwitch( + initialValue: overseas, + activeColor: second, + onChanged: (value) { + setState(() { + overseas = value; + }); + }, + decoration: normalTextFieldStyle("", ''), + name: 'overseas', + title: const Text("Overseas Address?"), + ), + const SizedBox( + height: 20, + ), + //COUNTRY DROPDOWN + SizedBox( + child: overseas == true + ? FormBuilderDropdown( + 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( + onChanged: + (Region? region) async { + setState(() { + provinceCall = true; + }); + selectedRegion = region; + 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(); }, ); } + + Future getProvinces() async { + List _provinces = await LocationUtils.instance + .getProvinces(regionCode: selectedRegion!.code.toString()); + setState(() { + provinces = _provinces; + selectedProvince = provinces![0]; + getCities(); + provinceCall = false; + }); + } + Future getCities()async{ + List _cities = await LocationUtils.instance.getCities(code: selectedProvince!.code.toString()); + citymuns = _cities; + setState(() { + selectedMunicipality = _cities[0]; + cityCall = false; + }); + } } diff --git a/lib/screens/profile/components/eligibility/edit_modal.dart b/lib/screens/profile/components/eligibility/edit_modal.dart index ad6eb7e..2f3170a 100644 --- a/lib/screens/profile/components/eligibility/edit_modal.dart +++ b/lib/screens/profile/components/eligibility/edit_modal.dart @@ -4,6 +4,7 @@ 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: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/user/user_bloc.dart'; import 'package:unit2/model/location/city.dart'; @@ -30,17 +31,18 @@ class EditEligibilityScreen extends StatefulWidget { class _EditEligibilityScreenState extends State { final formKey = GlobalKey(); + final provinceKey = GlobalKey(); bool? overseas; DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); Region? selectedRegion; Province? selectedProvince; CityMunicipality? selectedMunicipality; - Region? regions; - Province? province; - CityMunicipality? city; Country? selectedCountry; Eligibility? selectedEligibility; List? provinces; + List? citymuns; + bool provinceCall = false; + bool cityCall = false; // final examDateController = TextEditingController(); // final validityDateController = TextEditingController(); @override @@ -52,10 +54,13 @@ class _EditEligibilityScreenState extends State { if (state is UserLoggedIn) { //PROFIILE BLOC return BlocBuilder( + buildWhen: (previous, current) { + if (state is EditEligibilityState) {} + return false; + }, builder: (context, state) { //EDIT ELIGIBILITY STATE if (state is EditEligibilityState) { - overseas = state.isOverseas; return ProgressHUD( child: Center( child: Padding( @@ -69,10 +74,10 @@ class _EditEligibilityScreenState extends State { children: [ //ELIGIBILITIES DROPDOWN FormBuilderDropdown( - onChanged: (Eligibility? eligibility){ + onChanged: (Eligibility? eligibility) { selectedEligibility = eligibility; }, - initialValue: state.currentEligibility, + initialValue: null, items: state.eligibilities .map>( (Eligibility eligibility) { @@ -117,11 +122,14 @@ class _EditEligibilityScreenState extends State { flex: 1, child: FormBuilderTextField( name: 'rating', - + // ignore: prefer_null_aware_operators - initialValue: widget - .eligibityCert.rating== null?null:widget.eligibityCert.rating.toString(), - + initialValue: + widget.eligibityCert.rating == null + ? null + : widget.eligibityCert.rating + .toString(), + decoration: normalTextFieldStyle( 'rating', 'rating'), ), @@ -190,143 +198,156 @@ class _EditEligibilityScreenState extends State { height: 12, ), //OVERSEAS ADDRESS SWITCH - FormBuilderSwitch( - initialValue: overseas, - activeColor: second, - onChanged: (value) { - EligibityCert newEligibility = - state.eligibityCert; - newEligibility.overseas = value!; - // formKey.currentState!.reset(); - context.read().add( - EditEligibility( - selectedRegion: null, - selectedProvince: null, - eligibityCert: newEligibility)); - }, - decoration: normalTextFieldStyle("", ''), - name: 'overseas', - title: const Text("Overseas Address?"), - ), - const SizedBox( - height: 20, - ), - //COUNTRY DROPDOWN - SizedBox( - child: overseas == true - ? FormBuilderDropdown( - initialValue: state.currentCountry, - - items: state.countries - .map>( + Column( + children: [ + FormBuilderSwitch( + initialValue: overseas, + activeColor: second, + onChanged: (value) { + setState(() { + overseas = value; + }); + }, + decoration: normalTextFieldStyle("", ''), + name: 'overseas', + title: const Text("Overseas Address?"), + ), + const SizedBox( + height: 20, + ), + //COUNTRY DROPDOWN + SizedBox( + child: overseas == true + ? FormBuilderDropdown( + initialValue: null, + items: state.countries.map< + DropdownMenuItem< + Country>>( (Country country) { - return DropdownMenuItem( - 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( - onChanged: (Region? region) { - selectedRegion = region; - - context.read().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) { - return DropdownMenuItem( - value: region, - child: Text( - region.description!)); + return DropdownMenuItem< + Country>( + value: country, + child: FittedBox( + child: Text( + country.name!))); }).toList(), - ), - const SizedBox( - height: 20, - ), - //PROVINCE DROPDOWN - FormBuilderDropdown( - initialValue:state.currentProvince, - name: 'province', - onChanged: - (Province? province) { - selectedProvince = province; - context - .read() - .add(EditEligibility( - eligibityCert: state - .eligibityCert, - selectedProvince: - selectedProvince, - selectedRegion: state - .currentRegion)); - }, - items: state.provinces == null - ? [] - : state.provinces!.map< - DropdownMenuItem< - Province>>( - (Province province) { - return DropdownMenuItem( - value: province, - child: Text(province - .description!)); - }).toList(), - decoration: - normalTextFieldStyle( - "Province*", - "Province")), - const SizedBox( - height: 20, - ), - FormBuilderDropdown< - CityMunicipality>( - onChanged: (CityMunicipality? city){ - selectedMunicipality = city; + name: 'country', + decoration: normalTextFieldStyle( + "Country*", "Country"), + onChanged: (Country? value) { + selectedCountry = value; + }, + ) + : Column( + children: [ + //REGION DROPDOWN + FormBuilderDropdown( + onChanged: + (Region? region) async { + setState(() { + provinceCall = true; + }); + selectedRegion = region; + 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"), - name: 'municipality', - items: state.cityMuns == null - ? [] - : state.cityMuns!.map< - DropdownMenuItem< - CityMunicipality>>( - (CityMunicipality c) { - return DropdownMenuItem( - value: c, - child: Text(c - .description!)); - }).toList(), - initialValue: - state.currentCity), - const SizedBox( - height: 20, - ), - ], - )), + 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(), ), @@ -357,4 +378,23 @@ class _EditEligibilityScreenState extends State { }, ); } + + Future getProvinces() async { + List _provinces = await LocationUtils.instance + .getProvinces(regionCode: selectedRegion!.code.toString()); + setState(() { + provinces = _provinces; + selectedProvince = provinces![0]; + getCities(); + provinceCall = false; + }); + } + Future getCities()async{ + List _cities = await LocationUtils.instance.getCities(code: selectedProvince!.code.toString()); + citymuns = _cities; + setState(() { + selectedMunicipality = _cities[0]; + cityCall = false; + }); + } } diff --git a/lib/screens/profile/components/eligibility_screen.dart b/lib/screens/profile/components/eligibility_screen.dart index 8544444..44d548d 100644 --- a/lib/screens/profile/components/eligibility_screen.dart +++ b/lib/screens/profile/components/eligibility_screen.dart @@ -29,7 +29,7 @@ class EligibiltyScreen extends StatelessWidget { centerTitle: true, backgroundColor: primary, actions: [AddLeading(onPressed: () { - context.read().add(const AddEligibility(overseas: false,selectedProvince: null,selectedRegion: null,selectedEligibility: null)); + context.read().add( AddEligibility()); })], ), body: BlocBuilder( @@ -172,8 +172,7 @@ class EligibiltyScreen extends StatelessWidget { .showWithText("Loading..."); context.read().add( EditEligibility( - selectedProvince: null, - selectedRegion: null, + eligibityCert: eligibityCert)); } diff --git a/lib/sevices/login_service/auth_service.dart b/lib/sevices/login_service/auth_service.dart index 885bd76..477abe8 100644 --- a/lib/sevices/login_service/auth_service.dart +++ b/lib/sevices/login_service/auth_service.dart @@ -20,10 +20,9 @@ class AuthService { 'X-User': "" }; try { - http.Response response = await http.get( - Uri.https('unitylb1.agusandelnorte.gov.ph', - '/unit2/api/sys/apk_version/latest/'), - headers: headers); + String path = Url.instance.latestApk(); + http.Response response = await Request.instance.getRequest(path: path,headers: headers,param: {}); + if (response.statusCode == 200) { Map data = jsonDecode(response.body); versionInfo = VersionInfo.fromJson(data['data']); diff --git a/lib/utils/urls.dart b/lib/utils/urls.dart index a954fda..d53cead 100644 --- a/lib/utils/urls.dart +++ b/lib/utils/urls.dart @@ -5,7 +5,8 @@ class Url { String host() { // return '192.168.10.221:3003'; // return 'agusandelnorte.gov.ph'; - return 'devweb.agusandelnorte.gov.ph'; + return "192.168.10.219:3000"; + // return 'devweb.agusandelnorte.gov.ph'; } String authentication() { @@ -16,6 +17,10 @@ class Url { return '/api/jobnet_app/profile/pds/'; } + String latestApk(){ + return "/api/system_app/apk_version/latest"; + } + String eligibilities(){ return "/api/jobnet_app/eligibilities/"; } diff --git a/linux/flutter/generated_plugin_registrant.cc b/linux/flutter/generated_plugin_registrant.cc index e71a16d..a124bbe 100644 --- a/linux/flutter/generated_plugin_registrant.cc +++ b/linux/flutter/generated_plugin_registrant.cc @@ -6,6 +6,10 @@ #include "generated_plugin_registrant.h" +#include 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); } diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 2e1de87..f6f1987 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + modal_progress_hud_nsn ) list(APPEND FLUTTER_FFI_PLUGIN_LIST diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 63c4df1..4567379 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,12 +5,14 @@ import FlutterMacOS import Foundation +import modal_progress_hud_nsn import package_info_plus import path_provider_foundation import shared_preferences_foundation import sqflite func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + ModalProgressHudNsnPlugin.register(with: registry.registrar(forPlugin: "ModalProgressHudNsnPlugin")) FLTPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FLTPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) diff --git a/pubspec.lock b/pubspec.lock index b06be86..5132e7a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -517,6 +517,14 @@ packages: url: "https://pub.dev" source: hosted 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: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 85eecab..acba4dd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -69,6 +69,7 @@ dependencies: expandable_group: ^0.0.8 badges: ^3.0.2 app_popup_menu: ^1.0.0 + modal_progress_hud_nsn: ^0.3.0 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 48de52b..c1aa7e0 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -6,9 +6,12 @@ #include "generated_plugin_registrant.h" +#include #include void RegisterPlugins(flutter::PluginRegistry* registry) { + ModalProgressHudNsnPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("ModalProgressHudNsnPlugin")); PermissionHandlerWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("PermissionHandlerWindowsPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 0e69e40..2446653 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -3,6 +3,7 @@ # list(APPEND FLUTTER_PLUGIN_LIST + modal_progress_hud_nsn permission_handler_windows )