commit before stateful builder
parent
fb1ec643cd
commit
a7ee63627d
|
@ -5,7 +5,9 @@ import 'package:unit2/model/profile/basic_information/primary-information.dart';
|
|||
import 'package:unit2/model/profile/eligibility.dart';
|
||||
import 'package:unit2/model/profile/profileInfomation.dart';
|
||||
import 'package:unit2/model/utils/eligibility.dart';
|
||||
import 'package:unit2/sevices/profile/eligibility_services.dart';
|
||||
import 'package:unit2/sevices/profile/profile_service.dart';
|
||||
import 'package:unit2/test_data.dart';
|
||||
import 'package:unit2/utils/location_utilities.dart';
|
||||
import 'package:unit2/utils/profile_utilities.dart';
|
||||
import '../../model/location/country.dart';
|
||||
|
@ -19,6 +21,12 @@ part 'profile_state.dart';
|
|||
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
ProfileBloc() : super(ProfileInitial()) {
|
||||
ProfileInformation? _profileInformation;
|
||||
List<Country>? _countries;
|
||||
List<Region>? _regions;
|
||||
List<Eligibility>? _eligibilities;
|
||||
List<Province>? _provinces;
|
||||
List<CityMunicipality>? _cities;
|
||||
////=========================================================================
|
||||
on<LoadProfile>((event, emit) async {
|
||||
// try {
|
||||
emit(ProfileLoading());
|
||||
|
@ -30,58 +38,203 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
|||
// emit(ProfileErrorState(mesage: e.toString()));
|
||||
// }
|
||||
});
|
||||
|
||||
////=====================================================================
|
||||
on<LoadEligibility>((event, emit) {
|
||||
emit(ProfileLoading());
|
||||
emit(EligibilityLoaded(eligibilities: event.eligibilities));
|
||||
});
|
||||
|
||||
on<EditEligibilityNotOverseas>((event, emit) async {
|
||||
////====================================================================
|
||||
on<EditEligibility>((event, emit) async {
|
||||
Region? currentRegion;
|
||||
Province? currentProvince;
|
||||
CityMunicipality? currentCity;
|
||||
// try{
|
||||
emit(ProfileLoading());
|
||||
if (_countries == null) {
|
||||
List<Country> countries = await LocationUtils.instance.getCountries();
|
||||
_countries = countries;
|
||||
}
|
||||
if (_regions == null) {
|
||||
List<Region> regions = await LocationUtils.instance.getRegions();
|
||||
_regions = regions;
|
||||
}
|
||||
if (_eligibilities == null) {
|
||||
List<Eligibility> eligibilities =
|
||||
await ProfileUtilities.instance.getEligibilities();
|
||||
_eligibilities = eligibilities;
|
||||
}
|
||||
|
||||
// get current country
|
||||
Country? currentCountry = _countries!.firstWhere((Country country) =>
|
||||
country.code == event.eligibityCert.examAddress?.country!.code);
|
||||
// get current eligibility
|
||||
Eligibility currentEligibility = _eligibilities!.firstWhere(
|
||||
(Eligibility eligibility) =>
|
||||
event.eligibityCert.eligibility!.id == eligibility.id);
|
||||
|
||||
bool? isOverseas = event.eligibityCert.overseas;
|
||||
List<Province> provinces =
|
||||
event.eligibityCert.examAddress?.cityMunicipality?.province?.region != null
|
||||
? await LocationUtils.instance.getProvinces(
|
||||
|
||||
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())
|
||||
: [];
|
||||
List<CityMunicipality> citymuns =
|
||||
event.eligibityCert.examAddress?.cityMunicipality != null
|
||||
? await LocationUtils.instance.getCities(
|
||||
.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!)
|
||||
: [];
|
||||
emit(EditNotOverseasEligibilityState(
|
||||
currentEligibility: null,
|
||||
currentRegion: null,
|
||||
.province!.code!);
|
||||
_cities = citymuns;
|
||||
|
||||
currentCity = _cities!.firstWhere((CityMunicipality c) =>
|
||||
event.eligibityCert.examAddress!.cityMunicipality!.code ==
|
||||
c.code);
|
||||
}
|
||||
}
|
||||
emit(EditEligibilityState(
|
||||
isOverseas: isOverseas!,
|
||||
cityMuns: citymuns,
|
||||
provinces: provinces,
|
||||
currentEligibility: currentEligibility,
|
||||
currentCountry: currentCountry,
|
||||
currentRegion: currentRegion,
|
||||
currentCity: currentCity,
|
||||
cityMuns: _cities,
|
||||
provinces: _provinces,
|
||||
eligibityCert: event.eligibityCert,
|
||||
regions: regions,
|
||||
eligibilities: eligibilities));
|
||||
countries: _countries!,
|
||||
regions: _regions!,
|
||||
currentProvince: currentProvince,
|
||||
eligibilities: _eligibilities!));
|
||||
|
||||
// }catch(e){
|
||||
// emit(ProfileErrorState(mesage: e.toString()));
|
||||
// }
|
||||
});on<EditEligibilityOverseas>((event,emit)async{
|
||||
|
||||
////====================================================================
|
||||
});
|
||||
on<AddEligibility>((event, emit) async {
|
||||
Region? currentRegion;
|
||||
Province? currentProvince;
|
||||
CityMunicipality? currentCity;
|
||||
List<CityMunicipality>? cities;
|
||||
List<Province>? provinces;
|
||||
Eligibility? currentEligibility;
|
||||
final bool overseas = event.overseas;
|
||||
emit(ProfileLoading());
|
||||
List<Country> countries = await LocationUtils.instance.getCountries();
|
||||
if (_regions == null) {
|
||||
List<Region> regions = await LocationUtils.instance.getRegions();
|
||||
_regions = regions;
|
||||
}
|
||||
if (_eligibilities == null) {
|
||||
List<Eligibility> eligibilities =
|
||||
await ProfileUtilities.instance.getEligibilities();
|
||||
bool? isOverseas = event.eligibityCert.overseas;
|
||||
emit(EditOverseasEligibilityState(
|
||||
countries: countries,
|
||||
currentCOuntry: null,
|
||||
currentEligibility: null,
|
||||
isOverseas: isOverseas!,
|
||||
eligibityCert: event.eligibityCert,
|
||||
eligibilities: eligibilities));
|
||||
_eligibilities = eligibilities;
|
||||
}
|
||||
if (_countries == null) {
|
||||
List<Country> 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!));
|
||||
});
|
||||
////====================================================================
|
||||
on<DeleteEligibility>((event, emit) async {
|
||||
emit(ProfileLoading());
|
||||
try {
|
||||
final bool success = await EligibilityService.instance.delete(
|
||||
eligibilityId: event.eligibilityId,
|
||||
profileId: int.parse(event.profileId),
|
||||
token: event.token);
|
||||
if (success) {
|
||||
event.eligibilities.removeWhere(
|
||||
((EligibityCert element) => element.id == event.eligibilityId));
|
||||
List<EligibityCert> eligibilities = event.eligibilities;
|
||||
emit(DeletedState(success: success, eligibilities: eligibilities));
|
||||
} else {
|
||||
emit(DeletedState(
|
||||
success: success, eligibilities: event.eligibilities));
|
||||
}
|
||||
} catch (e) {
|
||||
emit(ProfileErrorState(mesage: e.toString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,18 +28,35 @@ class LoadEligibility extends ProfileEvent{
|
|||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class EditEligibilityOverseas extends ProfileEvent{
|
||||
class EditEligibility extends ProfileEvent{
|
||||
final EligibityCert eligibityCert;
|
||||
const EditEligibilityOverseas({required this.eligibityCert});
|
||||
final Region? selectedRegion;
|
||||
final Province? selectedProvince;
|
||||
const EditEligibility({required this.eligibityCert,this.selectedRegion, required this.selectedProvince});
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class EditEligibilityNotOverseas extends ProfileEvent{
|
||||
final EligibityCert eligibityCert;
|
||||
const EditEligibilityNotOverseas({required this.eligibityCert});
|
||||
class DeleteEligibility extends ProfileEvent{
|
||||
|
||||
final List<EligibityCert> eligibilities;
|
||||
final String profileId;
|
||||
final int eligibilityId;
|
||||
final String token;
|
||||
const DeleteEligibility({ required this.eligibilities, required this.eligibilityId, required this.profileId, required this.token});
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
List<Object> get props => [eligibilities,profileId,eligibilityId,token];
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -32,44 +32,63 @@ class EligibilityLoaded extends ProfileState {
|
|||
List<Object> get props => [eligibilities];
|
||||
}
|
||||
|
||||
class EditNotOverseasEligibilityState extends ProfileState {
|
||||
class EditEligibilityState extends ProfileState {
|
||||
final EligibityCert eligibityCert;
|
||||
final List<Eligibility> eligibilities;
|
||||
|
||||
final List<Country> countries;
|
||||
final List<Region> regions;
|
||||
List<Province> provinces;
|
||||
List<CityMunicipality> cityMuns;
|
||||
List<Province>? provinces;
|
||||
List<CityMunicipality>? cityMuns;
|
||||
Eligibility? currentEligibility;
|
||||
Country? currentCountry;
|
||||
Region? currentRegion;
|
||||
Province? currentProvince;
|
||||
bool? isOverseas;
|
||||
EditNotOverseasEligibilityState(
|
||||
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.regions});
|
||||
|
||||
|
||||
}
|
||||
|
||||
class EditOverseasEligibilityState extends ProfileState {
|
||||
final List<Eligibility> eligibilities;
|
||||
final EligibityCert eligibityCert;
|
||||
final Eligibility? currentEligibility;
|
||||
final List<Country> countries;
|
||||
final Country? currentCOuntry;
|
||||
bool? isOverseas;
|
||||
|
||||
EditOverseasEligibilityState(
|
||||
{required this.currentEligibility,
|
||||
required this.eligibilities,
|
||||
required this.isOverseas,
|
||||
required this.eligibityCert,
|
||||
required this.countries,
|
||||
required this.currentCOuntry});
|
||||
|
||||
required this.regions,
|
||||
required this.currentProvince,
|
||||
required this.currentCity});
|
||||
}
|
||||
|
||||
class DeletedState extends ProfileState {
|
||||
final List<EligibityCert> eligibilities;
|
||||
final bool success;
|
||||
const DeletedState({required this.eligibilities, required this.success});
|
||||
@override
|
||||
List<Object> get props => [success, eligibilities];
|
||||
}
|
||||
|
||||
class AddEligibilityState extends ProfileState {
|
||||
bool overseas;
|
||||
Eligibility? currentEligibility;
|
||||
Region? currentRegion;
|
||||
Province? currentProvince;
|
||||
final List<Eligibility> eligibilities;
|
||||
final List<Country> countries;
|
||||
final List<Region> regions;
|
||||
final List<Province>? provinces;
|
||||
final List<CityMunicipality>? 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<Object> get props => [overseas];
|
||||
}
|
||||
|
|
|
@ -0,0 +1,311 @@
|
|||
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:unit2/bloc/profile/profile_bloc.dart';
|
||||
import 'package:unit2/bloc/user/user_bloc.dart';
|
||||
|
||||
import '../../../../model/location/city.dart';
|
||||
import '../../../../model/location/country.dart';
|
||||
import '../../../../model/location/provinces.dart';
|
||||
import '../../../../model/location/region.dart';
|
||||
import '../../../../model/utils/eligibility.dart';
|
||||
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/text_container.dart';
|
||||
|
||||
class AddEligibilityScreen extends StatefulWidget {
|
||||
const AddEligibilityScreen({super.key});
|
||||
|
||||
@override
|
||||
State<AddEligibilityScreen> createState() => _AddEligibilityScreenState();
|
||||
}
|
||||
|
||||
class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool? overseas;
|
||||
final formKey = GlobalKey<FormBuilderState>();
|
||||
final regionKey = GlobalKey<FormBuilderState>();
|
||||
Region? selectedRegion;
|
||||
Province? selectedProvince;
|
||||
Country? selectedCountry;
|
||||
CityMunicipality selectedCity;
|
||||
Eligibility? selectedEligibility;
|
||||
return BlocBuilder<UserBloc, UserState>(
|
||||
builder: (context, state) {
|
||||
if (state is UserLoggedIn) {
|
||||
return BlocBuilder<ProfileBloc, ProfileState>(
|
||||
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<Eligibility>(
|
||||
initialValue: selectedEligibility,
|
||||
items: state.eligibilities
|
||||
.map<DropdownMenuItem<Eligibility>>(
|
||||
(Eligibility eligibility) {
|
||||
return DropdownMenuItem<Eligibility>(
|
||||
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"),
|
||||
),
|
||||
),
|
||||
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<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(
|
||||
"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: 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<
|
||||
Province>>(
|
||||
(Province province) {
|
||||
return DropdownMenuItem(
|
||||
value: province,
|
||||
child: Text(province
|
||||
.description!));
|
||||
}).toList(),
|
||||
|
||||
decoration: normalTextFieldStyle(
|
||||
"Province*", "Province")),
|
||||
const SizedBox(
|
||||
height: 12,
|
||||
),
|
||||
FormBuilderDropdown<CityMunicipality>(
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
});
|
||||
}
|
||||
return Container();
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,7 @@ import 'package:date_time_picker/date_time_picker.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:unit2/bloc/profile/profile_bloc.dart';
|
||||
import 'package:unit2/bloc/user/user_bloc.dart';
|
||||
|
@ -9,6 +10,7 @@ import 'package:unit2/model/location/city.dart';
|
|||
import 'package:unit2/model/login_data/employee_info/employee_info.dart';
|
||||
import 'package:unit2/model/profile/eligibility.dart';
|
||||
import 'package:unit2/model/utils/eligibility.dart';
|
||||
import 'package:unit2/utils/location_utilities.dart';
|
||||
import '../../../../model/location/country.dart';
|
||||
import '../../../../model/location/region.dart';
|
||||
import '../../../../model/location/provinces.dart';
|
||||
|
@ -28,10 +30,19 @@ class EditEligibilityScreen extends StatefulWidget {
|
|||
|
||||
class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
||||
final formKey = GlobalKey<FormBuilderState>();
|
||||
final countryKey = GlobalKey<FormBuilderState>();
|
||||
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<Province>? provinces;
|
||||
// final examDateController = TextEditingController();
|
||||
// final validityDateController = TextEditingController();
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
//USERBLOC
|
||||
|
@ -43,9 +54,10 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
return BlocBuilder<ProfileBloc, ProfileState>(
|
||||
builder: (context, state) {
|
||||
//EDIT ELIGIBILITY STATE
|
||||
if (state is EditNotOverseasEligibilityState) {
|
||||
if (state is EditEligibilityState) {
|
||||
overseas = state.isOverseas;
|
||||
return Center(
|
||||
return ProgressHUD(
|
||||
child: Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 25, horizontal: 18),
|
||||
|
@ -57,7 +69,10 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
children: [
|
||||
//ELIGIBILITIES DROPDOWN
|
||||
FormBuilderDropdown<Eligibility>(
|
||||
initialValue: null,
|
||||
onChanged: (Eligibility? eligibility){
|
||||
selectedEligibility = eligibility;
|
||||
},
|
||||
initialValue: state.currentEligibility,
|
||||
items: state.eligibilities
|
||||
.map<DropdownMenuItem<Eligibility>>(
|
||||
(Eligibility eligibility) {
|
||||
|
@ -66,14 +81,14 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
child: Text(eligibility.title));
|
||||
}).toList(),
|
||||
name: "eligibility",
|
||||
decoration: normalTextFieldStyle(
|
||||
"Eligibility", "")
|
||||
decoration:
|
||||
normalTextFieldStyle("Eligibility", "")
|
||||
.copyWith(
|
||||
hintStyle: const TextStyle(
|
||||
color: Colors.black,
|
||||
),
|
||||
labelStyle:
|
||||
const TextStyle(color: Colors.black)),
|
||||
labelStyle: const TextStyle(
|
||||
color: Colors.black)),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
|
@ -87,7 +102,7 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
Flexible(
|
||||
flex: 1,
|
||||
child: FormBuilderTextField(
|
||||
name: 'license number',
|
||||
name: 'license_number',
|
||||
initialValue:
|
||||
widget.eligibityCert.licenseNumber,
|
||||
decoration: normalTextFieldStyle(
|
||||
|
@ -102,8 +117,11 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
flex: 1,
|
||||
child: FormBuilderTextField(
|
||||
name: 'rating',
|
||||
initialValue: widget.eligibityCert.rating
|
||||
.toString(),
|
||||
|
||||
// ignore: prefer_null_aware_operators
|
||||
initialValue: widget
|
||||
.eligibityCert.rating== null?null:widget.eligibityCert.rating.toString(),
|
||||
|
||||
decoration: normalTextFieldStyle(
|
||||
'rating', 'rating'),
|
||||
),
|
||||
|
@ -122,16 +140,17 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
Flexible(
|
||||
flex: 1,
|
||||
child: DateTimePicker(
|
||||
// controller: examDateController,
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(2100),
|
||||
decoration: normalTextFieldStyle(
|
||||
"Exam date", "Exam date"),
|
||||
initialValue: widget
|
||||
.eligibityCert.examDate ==
|
||||
initialValue:
|
||||
widget.eligibityCert.examDate ==
|
||||
null
|
||||
? ''
|
||||
: dteFormat2.format(
|
||||
widget.eligibityCert.examDate!),
|
||||
: dteFormat2.format(widget
|
||||
.eligibityCert.examDate!),
|
||||
)),
|
||||
const SizedBox(
|
||||
width: 12,
|
||||
|
@ -140,6 +159,7 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
Flexible(
|
||||
flex: 1,
|
||||
child: DateTimePicker(
|
||||
// controller: validityDateController,
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(2100),
|
||||
decoration: normalTextFieldStyle(
|
||||
|
@ -149,7 +169,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
null
|
||||
? ''
|
||||
: dteFormat2.format(widget
|
||||
.eligibityCert.validityDate!),
|
||||
.eligibityCert
|
||||
.validityDate!),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -176,8 +197,11 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
EligibityCert newEligibility =
|
||||
state.eligibityCert;
|
||||
newEligibility.overseas = value!;
|
||||
// formKey.currentState!.reset();
|
||||
context.read<ProfileBloc>().add(
|
||||
EditEligibilityOverseas(
|
||||
EditEligibility(
|
||||
selectedRegion: null,
|
||||
selectedProvince: null,
|
||||
eligibityCert: newEligibility));
|
||||
},
|
||||
decoration: normalTextFieldStyle("", ''),
|
||||
|
@ -187,23 +211,54 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
Column(
|
||||
//COUNTRY DROPDOWN
|
||||
SizedBox(
|
||||
child: overseas == true
|
||||
? FormBuilderDropdown<Country>(
|
||||
initialValue: state.currentCountry,
|
||||
|
||||
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) {},
|
||||
// initialValue:state.eligibityCert.examAddress!.cityMunicipality!.province!.description!,
|
||||
|
||||
decoration:
|
||||
normalTextFieldStyle("Region*", "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>>(
|
||||
items: state.regions.map<
|
||||
DropdownMenuItem<Region>>(
|
||||
(Region region) {
|
||||
return DropdownMenuItem<Region>(
|
||||
value: region,
|
||||
child: Text(region.description!));
|
||||
child: Text(
|
||||
region.description!));
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(
|
||||
|
@ -211,231 +266,70 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
),
|
||||
//PROVINCE DROPDOWN
|
||||
FormBuilderDropdown<Province?>(
|
||||
initialValue: null,
|
||||
initialValue:state.currentProvince,
|
||||
name: 'province',
|
||||
items: state.provinces.isEmpty
|
||||
onChanged:
|
||||
(Province? province) {
|
||||
selectedProvince = province;
|
||||
context
|
||||
.read<ProfileBloc>()
|
||||
.add(EditEligibility(
|
||||
eligibityCert: state
|
||||
.eligibityCert,
|
||||
selectedProvince:
|
||||
selectedProvince,
|
||||
selectedRegion: state
|
||||
.currentRegion));
|
||||
},
|
||||
items: state.provinces == null
|
||||
? []
|
||||
: state.provinces
|
||||
.map<DropdownMenuItem<Province>>(
|
||||
: state.provinces!.map<
|
||||
DropdownMenuItem<
|
||||
Province>>(
|
||||
(Province province) {
|
||||
return DropdownMenuItem(
|
||||
value: province,
|
||||
child: Text(
|
||||
province.description!));
|
||||
child: Text(province
|
||||
.description!));
|
||||
}).toList(),
|
||||
decoration: normalTextFieldStyle(
|
||||
"Province*", "Province")),
|
||||
decoration:
|
||||
normalTextFieldStyle(
|
||||
"Province*",
|
||||
"Province")),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
FormBuilderDropdown<CityMunicipality>(
|
||||
decoration: normalTextFieldStyle(
|
||||
"Municipality*", "Municipality"),
|
||||
FormBuilderDropdown<
|
||||
CityMunicipality>(
|
||||
onChanged: (CityMunicipality? city){
|
||||
selectedMunicipality = city;
|
||||
},
|
||||
decoration:
|
||||
normalTextFieldStyle(
|
||||
"Municipality*",
|
||||
"Municipality"),
|
||||
name: 'municipality',
|
||||
items: state.cityMuns.isEmpty
|
||||
items: state.cityMuns == null
|
||||
? []
|
||||
: state.cityMuns.map<
|
||||
: state.cityMuns!.map<
|
||||
DropdownMenuItem<
|
||||
CityMunicipality>>(
|
||||
(CityMunicipality c) {
|
||||
return DropdownMenuItem(
|
||||
value: c,
|
||||
child: Text(c.description!));
|
||||
child: Text(c
|
||||
.description!));
|
||||
}).toList(),
|
||||
initialValue: null),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
SizedBox(
|
||||
width: screenWidth,
|
||||
height: 60,
|
||||
child: ElevatedButton(
|
||||
style: mainBtnStyle(
|
||||
primary, Colors.transparent, second),
|
||||
onPressed: () {},
|
||||
child: const Text(submit)),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
//===========================================================================
|
||||
if (state is EditOverseasEligibilityState) {
|
||||
overseas = state.isOverseas;
|
||||
return 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<Eligibility>(
|
||||
initialValue: null,
|
||||
items: state.eligibilities
|
||||
.map<DropdownMenuItem<Eligibility>>(
|
||||
(Eligibility eligibility) {
|
||||
return DropdownMenuItem<Eligibility>(
|
||||
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:
|
||||
widget.eligibityCert.licenseNumber,
|
||||
decoration: normalTextFieldStyle(
|
||||
"license number", "license number"),
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 12,
|
||||
),
|
||||
//RATING
|
||||
Flexible(
|
||||
flex: 1,
|
||||
child: FormBuilderTextField(
|
||||
name: 'rating',
|
||||
initialValue: widget.eligibityCert.rating
|
||||
.toString(),
|
||||
decoration: normalTextFieldStyle(
|
||||
'rating', 'rating'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
state.currentCity),
|
||||
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: widget
|
||||
.eligibityCert.examDate ==
|
||||
null
|
||||
? ''
|
||||
: dteFormat2.format(
|
||||
widget.eligibityCert.examDate!),
|
||||
],
|
||||
)),
|
||||
const SizedBox(
|
||||
width: 12,
|
||||
const Expanded(
|
||||
child: SizedBox(),
|
||||
),
|
||||
//VALIDITY DATE
|
||||
Flexible(
|
||||
flex: 1,
|
||||
child: DateTimePicker(
|
||||
firstDate: DateTime(2000),
|
||||
lastDate: DateTime(2100),
|
||||
decoration: normalTextFieldStyle(
|
||||
"Validity date", "Validity date"),
|
||||
initialValue:
|
||||
widget.eligibityCert.validityDate ==
|
||||
null
|
||||
? ''
|
||||
: dteFormat2.format(widget
|
||||
.eligibityCert.validityDate!),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
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
|
||||
FormBuilderSwitch(
|
||||
initialValue: overseas,
|
||||
activeColor: second,
|
||||
onChanged: (value) {
|
||||
EligibityCert newEligibility =
|
||||
state.eligibityCert;
|
||||
newEligibility.overseas = value!;
|
||||
// countryKey.currentState?.fields['country']
|
||||
// ?.reset();
|
||||
|
||||
|
||||
context.read<ProfileBloc>().add(
|
||||
EditEligibilityNotOverseas(
|
||||
eligibityCert: newEligibility));
|
||||
},
|
||||
decoration: normalTextFieldStyle("", ''),
|
||||
name: 'overseas',
|
||||
title: const Text("Overseas Address?"),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 20,
|
||||
),
|
||||
|
||||
FormBuilderDropdown<Country>(
|
||||
key: countryKey,
|
||||
onChanged: (Country? country) {
|
||||
|
||||
selectedCountry = country;
|
||||
},
|
||||
// initialValue:state.eligibityCert.examAddress!.cityMunicipality!.province!.description!,
|
||||
initialValue:selectedCountry,
|
||||
decoration:
|
||||
normalTextFieldStyle("Country*", "country"),
|
||||
name: 'country',
|
||||
items: state.countries.isNotEmpty
|
||||
? state.countries
|
||||
.map<DropdownMenuItem<Country>>(
|
||||
(Country country) {
|
||||
return DropdownMenuItem<Country>(
|
||||
value: country,
|
||||
child: Text(country.name!));
|
||||
}).toList()
|
||||
: []),
|
||||
|
||||
SizedBox(
|
||||
width: screenWidth,
|
||||
|
@ -452,9 +346,9 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
|
|||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Container();
|
||||
},
|
||||
);
|
||||
|
|
|
@ -1,114 +0,0 @@
|
|||
// import 'package:app_popup_menu/app_popup_menu.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:fluttericon/font_awesome_icons.dart';
|
||||
// import 'package:unit2/bloc/profile/profile_bloc.dart';
|
||||
// import 'package:unit2/bloc/user/user_bloc.dart';
|
||||
// import 'package:unit2/model/profile/eligibility.dart';
|
||||
// import 'package:unit2/screens/profile/components/eligibility/edit_modal.dart';
|
||||
// import 'package:unit2/theme-data.dart/box_shadow.dart';
|
||||
// import 'package:unit2/theme-data.dart/colors.dart';
|
||||
// import 'package:unit2/utils/alerts.dart';
|
||||
// import 'package:unit2/utils/global.dart';
|
||||
// import 'package:unit2/utils/text_container.dart';
|
||||
// import 'package:unit2/widgets/add_leading.dart';
|
||||
// import 'package:unit2/widgets/empty_data.dart';
|
||||
|
||||
// class EligibiltyScreen extends StatefulWidget {
|
||||
// const EligibiltyScreen({
|
||||
// super.key,
|
||||
// });
|
||||
|
||||
// @override
|
||||
// State<EligibiltyScreen> createState() => _EligibiltyScreenState();
|
||||
// }
|
||||
|
||||
// class _EligibiltyScreenState extends State<EligibiltyScreen> {
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// title: const Text(elibilityScreenTitle),
|
||||
// centerTitle: true,
|
||||
// backgroundColor: primary,
|
||||
// actions: context.read()[AddLeading(
|
||||
// onPressed: () => () {},
|
||||
// )],
|
||||
// ),
|
||||
// body: BlocBuilder<UserBloc, UserState>(
|
||||
// builder: (context, state) {
|
||||
// return BlocBuilder<ProfileBloc, ProfileState>(
|
||||
// builder: (context, state) {
|
||||
// if (state is EligibilityLoaded) {
|
||||
// return ListView.builder(
|
||||
// padding: const EdgeInsets.symmetric(
|
||||
// vertical: 8, horizontal: 10),
|
||||
// itemCount: state.eligibilities.length,
|
||||
// itemBuilder: (BuildContext context, int index) {
|
||||
// String title =
|
||||
// state.eligibilities[index].eligibility!.title!;
|
||||
// return Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.start,
|
||||
// crossAxisAlignment: CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// Container(
|
||||
// width: screenWidth,
|
||||
// padding: const EdgeInsets.symmetric(
|
||||
// horizontal: 12, vertical: 8),
|
||||
// decoration: box1(),
|
||||
// child: Row(
|
||||
// children: [
|
||||
// Expanded(
|
||||
// child: Column(
|
||||
// mainAxisAlignment:
|
||||
// MainAxisAlignment.start,
|
||||
// crossAxisAlignment:
|
||||
// CrossAxisAlignment.start,
|
||||
// children: [
|
||||
// Text(
|
||||
// title,
|
||||
// style: Theme.of(context)
|
||||
// .textTheme
|
||||
// .titleMedium!
|
||||
// .copyWith(
|
||||
// fontWeight:
|
||||
// FontWeight.w500),
|
||||
// ),
|
||||
// const Divider(),
|
||||
// const SizedBox(
|
||||
// height: 5,
|
||||
// ),
|
||||
// Text(
|
||||
// "$licenseNumber: ${state.eligibilities[index].licenseNumber == null ? 'N/A' : state.eligibilities[index].licenseNumber.toString()}",
|
||||
// style: Theme.of(context)
|
||||
// .textTheme
|
||||
// .titleSmall),
|
||||
// const SizedBox(
|
||||
// height: 3,
|
||||
// ),
|
||||
// Text(
|
||||
// " : ${state.eligibilities[index].rating ?? 'N/A'}.",
|
||||
// style: Theme.of(context)
|
||||
// .textTheme
|
||||
// .titleSmall)
|
||||
// ]),
|
||||
// ),
|
||||
// ]
|
||||
// ),
|
||||
// ),
|
||||
// const SizedBox(
|
||||
// height: 5,
|
||||
// )
|
||||
// ],
|
||||
// );
|
||||
// });
|
||||
// }
|
||||
// return Container();
|
||||
// },
|
||||
// );
|
||||
// },
|
||||
// ));
|
||||
// }
|
||||
// }
|
|
@ -1,20 +1,18 @@
|
|||
import 'package:app_popup_menu/app_popup_menu.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_progress_hud/flutter_progress_hud.dart';
|
||||
import 'package:fluttericon/font_awesome_icons.dart';
|
||||
import 'package:unit2/bloc/profile/profile_bloc.dart';
|
||||
import 'package:unit2/bloc/user/user_bloc.dart';
|
||||
import 'package:unit2/model/profile/eligibility.dart';
|
||||
import 'package:unit2/screens/profile/components/eligibility/add_modal.dart';
|
||||
import 'package:unit2/screens/profile/components/eligibility/edit_modal.dart';
|
||||
import 'package:unit2/theme-data.dart/box_shadow.dart';
|
||||
import 'package:unit2/theme-data.dart/colors.dart';
|
||||
import 'package:unit2/utils/global.dart';
|
||||
import 'package:unit2/utils/text_container.dart';
|
||||
import 'package:unit2/widgets/add_leading.dart';
|
||||
import 'package:unit2/widgets/empty_data.dart';
|
||||
|
||||
import '../../../utils/alerts.dart';
|
||||
|
||||
|
@ -23,33 +21,56 @@ class EligibiltyScreen extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String? token;
|
||||
String? profileId;
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text(elibilityScreenTitle),
|
||||
centerTitle: true,
|
||||
backgroundColor: primary,
|
||||
actions: [AddLeading(onPressed: () {})],
|
||||
actions: [AddLeading(onPressed: () {
|
||||
context.read<ProfileBloc>().add(const AddEligibility(overseas: false,selectedProvince: null,selectedRegion: null,selectedEligibility: null));
|
||||
})],
|
||||
),
|
||||
body: BlocBuilder<UserBloc, UserState>(
|
||||
builder: (context, state) {
|
||||
if (state is UserLoggedIn) {
|
||||
token = state.userData!.user!.login!.token;
|
||||
profileId =
|
||||
state.userData!.user!.login!.user!.profileId.toString();
|
||||
return ProgressHUD(
|
||||
child: BlocConsumer<ProfileBloc, ProfileState>(
|
||||
listener: (context, state) {
|
||||
if (state is EditEligibilityState) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
}
|
||||
if (state is ProfileLoading) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.showWithText("Loading");
|
||||
}
|
||||
if (state is EditNotOverseasEligibilityState) {
|
||||
if (state is EligibilityLoaded) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
}if (state is EditOverseasEligibilityState) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
}if(state is EligibilityLoaded){
|
||||
}if(state is AddEligibilityState){
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
}
|
||||
if (state is DeletedState) {
|
||||
if (state.success) {
|
||||
successAlert(context, "Deletion Successfull",
|
||||
"Eligibility has been deleted successfully", () {
|
||||
context.read<ProfileBloc>().add(LoadEligibility(
|
||||
eligibilities: state.eligibilities));
|
||||
});
|
||||
} else {
|
||||
errorAlert(context, "Deletion Failed",
|
||||
"Error deleting eligibility", () {
|
||||
context.read<ProfileBloc>().add(LoadEligibility(
|
||||
eligibilities: state.eligibilities));
|
||||
});
|
||||
}
|
||||
}
|
||||
// TODO: implement listener
|
||||
},
|
||||
builder: (context, state) {
|
||||
|
@ -62,7 +83,7 @@ class EligibiltyScreen extends StatelessWidget {
|
|||
itemCount: state.eligibilities.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
String title = state
|
||||
.eligibilities[index].eligibility!.title!;
|
||||
.eligibilities[index].eligibility!.title;
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
|
@ -104,7 +125,7 @@ class EligibiltyScreen extends StatelessWidget {
|
|||
height: 3,
|
||||
),
|
||||
Text(
|
||||
"Rating : ${state.eligibilities[index].rating}.",
|
||||
"Rating : ${state.eligibilities[index].rating ?? 'N/A'}.",
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleSmall)
|
||||
|
@ -115,10 +136,19 @@ class EligibiltyScreen extends StatelessWidget {
|
|||
elevation: 3,
|
||||
onSelected: (value) {
|
||||
if (value == 2) {
|
||||
confirmAlert(
|
||||
context,
|
||||
() => null,
|
||||
"Delete?",
|
||||
confirmAlert(context, () {
|
||||
BlocProvider.of<
|
||||
ProfileBloc>(context)
|
||||
.add(DeleteEligibility(
|
||||
eligibilities: state
|
||||
.eligibilities,
|
||||
eligibilityId: state
|
||||
.eligibilities[
|
||||
index]
|
||||
.id!,
|
||||
profileId: profileId!,
|
||||
token: token!));
|
||||
}, "Delete?",
|
||||
"Confirm Delete?");
|
||||
}
|
||||
if (value == 1) {
|
||||
|
@ -140,17 +170,12 @@ class EligibiltyScreen extends StatelessWidget {
|
|||
overseas;
|
||||
progress!
|
||||
.showWithText("Loading...");
|
||||
if (eligibityCert.overseas!) {
|
||||
context.read<ProfileBloc>().add(
|
||||
EditEligibilityOverseas(
|
||||
EditEligibility(
|
||||
selectedProvince: null,
|
||||
selectedRegion: null,
|
||||
eligibityCert:
|
||||
eligibityCert));
|
||||
} else {
|
||||
context.read<ProfileBloc>().add(
|
||||
EditEligibilityNotOverseas(
|
||||
eligibityCert:
|
||||
eligibityCert));
|
||||
}
|
||||
}
|
||||
},
|
||||
menuItems: [
|
||||
|
@ -183,12 +208,22 @@ class EligibiltyScreen extends StatelessWidget {
|
|||
);
|
||||
});
|
||||
}
|
||||
if (state is EditNotOverseasEligibilityState) {
|
||||
return EditEligibilityScreen(
|
||||
eligibityCert: state.eligibityCert);
|
||||
}if(state is EditOverseasEligibilityState){
|
||||
if (state is EditEligibilityState) {
|
||||
return EditEligibilityScreen(
|
||||
eligibityCert: state.eligibityCert);
|
||||
}if(state is AddEligibilityState){
|
||||
return const AddEligibilityScreen();
|
||||
}
|
||||
if (state is DeletedState) {
|
||||
return Center(
|
||||
child: Container(
|
||||
child: Text(state.success.toString())),
|
||||
);
|
||||
}
|
||||
if (state is ProfileErrorState) {
|
||||
return Center(
|
||||
child: Text(state.mesage),
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
},
|
||||
|
|
|
@ -60,7 +60,7 @@ class _UniT2LoginState extends State<UniT2Login> {
|
|||
if (state is InvalidCredentials) {
|
||||
final progress = ProgressHUD.of(context);
|
||||
progress!.dismiss();
|
||||
errorAlert(context, "Error Login", state.message);
|
||||
errorAlert(context, "Error Login", state.message,(){});
|
||||
context.read<UserBloc>().add(LoadVersion());
|
||||
}
|
||||
}, builder: (context, state) {
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:unit2/utils/request.dart';
|
||||
import 'package:unit2/utils/urls.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
class EligibilityService{
|
||||
static final EligibilityService _instance = EligibilityService();
|
||||
static EligibilityService get instance => _instance;
|
||||
|
||||
Future<bool> delete({required int eligibilityId, required int profileId,required String token})async{
|
||||
bool? success;
|
||||
String Authtoken = "Token $token";
|
||||
String path = "${Url.instance.deleteEligibility()}$profileId/";
|
||||
Map body = { "eligibility_id": eligibilityId};
|
||||
Map<String, dynamic> params ={"force_mode":"true"};
|
||||
Map<String, String> headers = {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
'Authorization': "Token $token"
|
||||
};
|
||||
// try{
|
||||
http.Response response = await Request.instance.deleteRequest(path: path, headers: headers, body: body, param: params);
|
||||
if(response.statusCode == 200){
|
||||
Map data = jsonDecode(response.body);
|
||||
success = data['success'];
|
||||
}else{
|
||||
success = false;
|
||||
}
|
||||
|
||||
// }catch(e){
|
||||
// throw(e.toString());
|
||||
// }
|
||||
return success!;
|
||||
}
|
||||
|
||||
}
|
|
@ -36,7 +36,7 @@ confirmAlert(context, Function() yes,String title, String subtitle) {
|
|||
).show();
|
||||
}
|
||||
|
||||
errorAlert(context, title, description) {
|
||||
errorAlert(context, title, description,Function() func) {
|
||||
AwesomeDialog(
|
||||
width: blockSizeHorizontal * 90,
|
||||
context: context,
|
||||
|
@ -45,7 +45,20 @@ errorAlert(context, title, description) {
|
|||
headerAnimationLoop: false,
|
||||
title: title,
|
||||
desc: description,
|
||||
btnOkOnPress: () {},
|
||||
btnOkOnPress: func,
|
||||
btnOkColor: Colors.red,
|
||||
).show();
|
||||
}
|
||||
successAlert(context, title, description,Function() func) {
|
||||
AwesomeDialog(
|
||||
width: blockSizeHorizontal * 90,
|
||||
context: context,
|
||||
dialogType: DialogType.success,
|
||||
animType: AnimType.scale,
|
||||
headerAnimationLoop: false,
|
||||
title: title,
|
||||
desc: description,
|
||||
btnOkOnPress: func,
|
||||
btnOkColor: Colors.red,
|
||||
).show();
|
||||
}
|
||||
|
|
|
@ -96,4 +96,47 @@ class Request {
|
|||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
Future<Response> deleteRequest(
|
||||
{required String path,
|
||||
required Map<String, String>? headers,
|
||||
required Map? body,
|
||||
required Map<String, dynamic>? param}) async {
|
||||
Response response;
|
||||
// try {
|
||||
response = await delete(Uri.http(host, path, param),
|
||||
headers: headers, body: jsonEncode(body))
|
||||
.timeout(Duration(seconds: requestTimeout));
|
||||
// } on TimeoutException catch (_) {
|
||||
// Fluttertoast.showToast(
|
||||
// msg: timeoutError,
|
||||
// toastLength: Toast.LENGTH_LONG,
|
||||
// gravity: ToastGravity.BOTTOM,
|
||||
// backgroundColor: Colors.black,
|
||||
// );
|
||||
// throw (timeoutError);
|
||||
// } on SocketException catch (_) {
|
||||
// Fluttertoast.showToast(
|
||||
// msg: timeoutError,
|
||||
// toastLength: Toast.LENGTH_LONG,
|
||||
// gravity: ToastGravity.BOTTOM,
|
||||
// backgroundColor: Colors.black,
|
||||
// );
|
||||
// throw (timeoutError);
|
||||
// } on FormatException catch (_) {
|
||||
// throw const FormatException(formatError);
|
||||
// } on HttpException catch (_) {
|
||||
// throw const HttpException(httpError);
|
||||
// } on Error catch (e) {
|
||||
// debugPrint("post request error: $e");
|
||||
// Fluttertoast.showToast(
|
||||
// msg: onError,
|
||||
// toastLength: Toast.LENGTH_LONG,
|
||||
// gravity: ToastGravity.BOTTOM,
|
||||
// backgroundColor: Colors.black,
|
||||
// );
|
||||
// throw (e.toString());
|
||||
// }
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@ class Url {
|
|||
|
||||
String eligibilities(){
|
||||
return "/api/jobnet_app/eligibilities/";
|
||||
}
|
||||
String deleteEligibility(){
|
||||
return "/api/jobnet_app/profile/pds/eligibility/";
|
||||
}
|
||||
// location utils path
|
||||
String getCounties(){
|
||||
|
|
Loading…
Reference in New Issue