commit before stateful builder

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-02-23 08:53:14 +08:00
parent fb1ec643cd
commit a7ee63627d
12 changed files with 1036 additions and 627 deletions

View File

@ -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/eligibility.dart';
import 'package:unit2/model/profile/profileInfomation.dart'; import 'package:unit2/model/profile/profileInfomation.dart';
import 'package:unit2/model/utils/eligibility.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/sevices/profile/profile_service.dart';
import 'package:unit2/test_data.dart';
import 'package:unit2/utils/location_utilities.dart'; import 'package:unit2/utils/location_utilities.dart';
import 'package:unit2/utils/profile_utilities.dart'; import 'package:unit2/utils/profile_utilities.dart';
import '../../model/location/country.dart'; import '../../model/location/country.dart';
@ -19,6 +21,12 @@ part 'profile_state.dart';
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> { class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
ProfileBloc() : super(ProfileInitial()) { ProfileBloc() : super(ProfileInitial()) {
ProfileInformation? _profileInformation; ProfileInformation? _profileInformation;
List<Country>? _countries;
List<Region>? _regions;
List<Eligibility>? _eligibilities;
List<Province>? _provinces;
List<CityMunicipality>? _cities;
////=========================================================================
on<LoadProfile>((event, emit) async { on<LoadProfile>((event, emit) async {
// try { // try {
emit(ProfileLoading()); emit(ProfileLoading());
@ -30,58 +38,203 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
// emit(ProfileErrorState(mesage: e.toString())); // emit(ProfileErrorState(mesage: e.toString()));
// } // }
}); });
////=====================================================================
on<LoadEligibility>((event, emit) { on<LoadEligibility>((event, emit) {
emit(ProfileLoading()); emit(ProfileLoading());
emit(EligibilityLoaded(eligibilities: event.eligibilities)); emit(EligibilityLoaded(eligibilities: event.eligibilities));
}); });
////====================================================================
on<EditEligibilityNotOverseas>((event, emit) async { on<EditEligibility>((event, emit) async {
Region? currentRegion;
Province? currentProvince;
CityMunicipality? currentCity;
// try{ // try{
emit(ProfileLoading()); emit(ProfileLoading());
if (_countries == null) {
List<Country> countries = await LocationUtils.instance.getCountries();
_countries = countries;
}
if (_regions == null) {
List<Region> regions = await LocationUtils.instance.getRegions(); List<Region> regions = await LocationUtils.instance.getRegions();
_regions = regions;
}
if (_eligibilities == null) {
List<Eligibility> eligibilities = List<Eligibility> eligibilities =
await ProfileUtilities.instance.getEligibilities(); 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; bool? isOverseas = event.eligibityCert.overseas;
List<Province> provinces =
event.eligibityCert.examAddress?.cityMunicipality?.province?.region != null if (event.selectedRegion != null) {
? await LocationUtils.instance.getProvinces( 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! regionCode: event.eligibityCert.examAddress!.cityMunicipality!
.province!.region!.code! .province!.region!.code!
.toString()) .toString());
: []; _provinces = provinces;
List<CityMunicipality> citymuns =
event.eligibityCert.examAddress?.cityMunicipality != null currentProvince = _provinces!.firstWhere((Province p) =>
? await LocationUtils.instance.getCities( event.eligibityCert.examAddress!.cityMunicipality!.province!
.code ==
p.code);
List<CityMunicipality> citymuns = await LocationUtils.instance
.getCities(
code: event.eligibityCert.examAddress!.cityMunicipality! code: event.eligibityCert.examAddress!.cityMunicipality!
.province!.code!) .province!.code!);
: []; _cities = citymuns;
emit(EditNotOverseasEligibilityState(
currentEligibility: null, currentCity = _cities!.firstWhere((CityMunicipality c) =>
currentRegion: null, event.eligibityCert.examAddress!.cityMunicipality!.code ==
c.code);
}
}
emit(EditEligibilityState(
isOverseas: isOverseas!, isOverseas: isOverseas!,
cityMuns: citymuns, currentEligibility: currentEligibility,
provinces: provinces, currentCountry: currentCountry,
currentRegion: currentRegion,
currentCity: currentCity,
cityMuns: _cities,
provinces: _provinces,
eligibityCert: event.eligibityCert, eligibityCert: event.eligibityCert,
regions: regions, countries: _countries!,
eligibilities: eligibilities)); regions: _regions!,
currentProvince: currentProvince,
eligibilities: _eligibilities!));
// }catch(e){ // }catch(e){
// emit(ProfileErrorState(mesage: e.toString())); // 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()); 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 = List<Eligibility> eligibilities =
await ProfileUtilities.instance.getEligibilities(); await ProfileUtilities.instance.getEligibilities();
bool? isOverseas = event.eligibityCert.overseas; _eligibilities = eligibilities;
emit(EditOverseasEligibilityState( }
countries: countries, if (_countries == null) {
currentCOuntry: null, List<Country> countries = await LocationUtils.instance.getCountries();
currentEligibility: null, _countries = countries;
isOverseas: isOverseas!, }
eligibityCert: event.eligibityCert,
eligibilities: eligibilities)); 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()));
}
}); });
} }
} }

View File

@ -28,18 +28,35 @@ class LoadEligibility extends ProfileEvent{
List<Object> get props => []; List<Object> get props => [];
} }
class EditEligibilityOverseas extends ProfileEvent{ class EditEligibility extends ProfileEvent{
final EligibityCert eligibityCert; 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 @override
List<Object> get props => []; List<Object> get props => [];
} }
class EditEligibilityNotOverseas extends ProfileEvent{ class DeleteEligibility extends ProfileEvent{
final EligibityCert eligibityCert;
const EditEligibilityNotOverseas({required this.eligibityCert}); 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 @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];
} }

View File

@ -32,44 +32,63 @@ class EligibilityLoaded extends ProfileState {
List<Object> get props => [eligibilities]; List<Object> get props => [eligibilities];
} }
class EditNotOverseasEligibilityState 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<Region> regions; final List<Region> regions;
List<Province> provinces; List<Province>? provinces;
List<CityMunicipality> cityMuns; List<CityMunicipality>? cityMuns;
Eligibility? currentEligibility; Eligibility? currentEligibility;
Country? currentCountry;
Region? currentRegion; Region? currentRegion;
Province? currentProvince; Province? currentProvince;
bool? isOverseas; CityMunicipality? currentCity;
EditNotOverseasEligibilityState( bool isOverseas;
EditEligibilityState(
{required this.currentEligibility, {required this.currentEligibility,
required this.currentCountry,
required this.currentRegion, required this.currentRegion,
required this.isOverseas, required this.isOverseas,
required this.cityMuns, required this.cityMuns,
required this.provinces, required this.provinces,
required this.eligibityCert, required this.eligibityCert,
required this.eligibilities, 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.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];
} }

View File

@ -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();
},
);
}
}

View File

@ -2,6 +2,7 @@ import 'package:date_time_picker/date_time_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.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:intl/intl.dart'; import 'package:intl/intl.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';
@ -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/login_data/employee_info/employee_info.dart';
import 'package:unit2/model/profile/eligibility.dart'; import 'package:unit2/model/profile/eligibility.dart';
import 'package:unit2/model/utils/eligibility.dart'; import 'package:unit2/model/utils/eligibility.dart';
import 'package:unit2/utils/location_utilities.dart';
import '../../../../model/location/country.dart'; import '../../../../model/location/country.dart';
import '../../../../model/location/region.dart'; import '../../../../model/location/region.dart';
import '../../../../model/location/provinces.dart'; import '../../../../model/location/provinces.dart';
@ -28,10 +30,19 @@ class EditEligibilityScreen extends StatefulWidget {
class _EditEligibilityScreenState extends State<EditEligibilityScreen> { class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
final formKey = GlobalKey<FormBuilderState>(); final formKey = GlobalKey<FormBuilderState>();
final countryKey = GlobalKey<FormBuilderState>();
bool? overseas; bool? overseas;
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
Region? selectedRegion;
Province? selectedProvince;
CityMunicipality? selectedMunicipality;
Region? regions;
Province? province;
CityMunicipality? city;
Country? selectedCountry; Country? selectedCountry;
Eligibility? selectedEligibility;
List<Province>? provinces;
// final examDateController = TextEditingController();
// final validityDateController = TextEditingController();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
//USERBLOC //USERBLOC
@ -43,9 +54,10 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
return BlocBuilder<ProfileBloc, ProfileState>( return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) { builder: (context, state) {
//EDIT ELIGIBILITY STATE //EDIT ELIGIBILITY STATE
if (state is EditNotOverseasEligibilityState) { if (state is EditEligibilityState) {
overseas = state.isOverseas; overseas = state.isOverseas;
return Center( return ProgressHUD(
child: Center(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 25, horizontal: 18), vertical: 25, horizontal: 18),
@ -57,7 +69,10 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
children: [ children: [
//ELIGIBILITIES DROPDOWN //ELIGIBILITIES DROPDOWN
FormBuilderDropdown<Eligibility>( FormBuilderDropdown<Eligibility>(
initialValue: null, onChanged: (Eligibility? eligibility){
selectedEligibility = eligibility;
},
initialValue: state.currentEligibility,
items: state.eligibilities items: state.eligibilities
.map<DropdownMenuItem<Eligibility>>( .map<DropdownMenuItem<Eligibility>>(
(Eligibility eligibility) { (Eligibility eligibility) {
@ -66,14 +81,14 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
child: Text(eligibility.title)); child: Text(eligibility.title));
}).toList(), }).toList(),
name: "eligibility", name: "eligibility",
decoration: normalTextFieldStyle( decoration:
"Eligibility", "") normalTextFieldStyle("Eligibility", "")
.copyWith( .copyWith(
hintStyle: const TextStyle( hintStyle: const TextStyle(
color: Colors.black, color: Colors.black,
), ),
labelStyle: labelStyle: const TextStyle(
const TextStyle(color: Colors.black)), color: Colors.black)),
), ),
const SizedBox( const SizedBox(
height: 20, height: 20,
@ -87,7 +102,7 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
Flexible( Flexible(
flex: 1, flex: 1,
child: FormBuilderTextField( child: FormBuilderTextField(
name: 'license number', name: 'license_number',
initialValue: initialValue:
widget.eligibityCert.licenseNumber, widget.eligibityCert.licenseNumber,
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
@ -102,8 +117,11 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
flex: 1, flex: 1,
child: FormBuilderTextField( child: FormBuilderTextField(
name: 'rating', name: 'rating',
initialValue: widget.eligibityCert.rating
.toString(), // ignore: prefer_null_aware_operators
initialValue: widget
.eligibityCert.rating== null?null:widget.eligibityCert.rating.toString(),
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
'rating', 'rating'), 'rating', 'rating'),
), ),
@ -122,16 +140,17 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
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: widget initialValue:
.eligibityCert.examDate == widget.eligibityCert.examDate ==
null null
? '' ? ''
: dteFormat2.format( : dteFormat2.format(widget
widget.eligibityCert.examDate!), .eligibityCert.examDate!),
)), )),
const SizedBox( const SizedBox(
width: 12, width: 12,
@ -140,6 +159,7 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
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(
@ -149,7 +169,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
null null
? '' ? ''
: dteFormat2.format(widget : dteFormat2.format(widget
.eligibityCert.validityDate!), .eligibityCert
.validityDate!),
), ),
), ),
], ],
@ -176,8 +197,11 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
EligibityCert newEligibility = EligibityCert newEligibility =
state.eligibityCert; state.eligibityCert;
newEligibility.overseas = value!; newEligibility.overseas = value!;
// formKey.currentState!.reset();
context.read<ProfileBloc>().add( context.read<ProfileBloc>().add(
EditEligibilityOverseas( EditEligibility(
selectedRegion: null,
selectedProvince: null,
eligibityCert: newEligibility)); eligibityCert: newEligibility));
}, },
decoration: normalTextFieldStyle("", ''), decoration: normalTextFieldStyle("", ''),
@ -187,23 +211,54 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
const SizedBox( const SizedBox(
height: 20, 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: [ children: [
//REGION DROPDOWN //REGION DROPDOWN
FormBuilderDropdown<Region?>( FormBuilderDropdown<Region?>(
onChanged: (Region? region) {}, onChanged: (Region? region) {
// initialValue:state.eligibityCert.examAddress!.cityMunicipality!.province!.description!, selectedRegion = region;
decoration:
normalTextFieldStyle("Region*", "Region"),
context.read<ProfileBloc>().add(
EditEligibility(
eligibityCert:
state.eligibityCert,
selectedProvince: null,
selectedRegion:
selectedRegion));
},
initialValue: state.currentRegion,
decoration: normalTextFieldStyle(
"Region*", "Region"),
name: 'region', name: 'region',
items: state.regions items: state.regions.map<
.map<DropdownMenuItem<Region>>( DropdownMenuItem<Region>>(
(Region region) { (Region region) {
return DropdownMenuItem<Region>( return DropdownMenuItem<Region>(
value: region, value: region,
child: Text(region.description!)); child: Text(
region.description!));
}).toList(), }).toList(),
), ),
const SizedBox( const SizedBox(
@ -211,231 +266,70 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
), ),
//PROVINCE DROPDOWN //PROVINCE DROPDOWN
FormBuilderDropdown<Province?>( FormBuilderDropdown<Province?>(
initialValue: null, initialValue:state.currentProvince,
name: 'province', 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 : state.provinces!.map<
.map<DropdownMenuItem<Province>>( DropdownMenuItem<
Province>>(
(Province province) { (Province province) {
return DropdownMenuItem( return DropdownMenuItem(
value: province, value: province,
child: Text( child: Text(province
province.description!)); .description!));
}).toList(), }).toList(),
decoration: normalTextFieldStyle( decoration:
"Province*", "Province")), normalTextFieldStyle(
"Province*",
"Province")),
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
FormBuilderDropdown<CityMunicipality>( FormBuilderDropdown<
decoration: normalTextFieldStyle( CityMunicipality>(
"Municipality*", "Municipality"), onChanged: (CityMunicipality? city){
selectedMunicipality = city;
},
decoration:
normalTextFieldStyle(
"Municipality*",
"Municipality"),
name: 'municipality', name: 'municipality',
items: state.cityMuns.isEmpty items: state.cityMuns == null
? [] ? []
: state.cityMuns.map< : state.cityMuns!.map<
DropdownMenuItem< DropdownMenuItem<
CityMunicipality>>( CityMunicipality>>(
(CityMunicipality c) { (CityMunicipality c) {
return DropdownMenuItem( return DropdownMenuItem(
value: c, value: c,
child: Text(c.description!)); child: Text(c
.description!));
}).toList(), }).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: initialValue:
widget.eligibityCert.licenseNumber, state.currentCity),
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'),
),
),
],
),
),
const SizedBox( const SizedBox(
height: 20, 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( const Expanded(
width: 12, 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( SizedBox(
width: screenWidth, width: screenWidth,
@ -452,9 +346,9 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
]), ]),
), ),
), ),
),
); );
} }
return Container(); return Container();
}, },
); );

View File

@ -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();
// },
// );
// },
// ));
// }
// }

View File

@ -1,20 +1,18 @@
import 'package:app_popup_menu/app_popup_menu.dart'; import 'package:app_popup_menu/app_popup_menu.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_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:fluttericon/font_awesome_icons.dart'; import 'package:fluttericon/font_awesome_icons.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/profile/eligibility.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/screens/profile/components/eligibility/edit_modal.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart'; import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/global.dart'; import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/text_container.dart'; import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/add_leading.dart'; import 'package:unit2/widgets/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart';
import '../../../utils/alerts.dart'; import '../../../utils/alerts.dart';
@ -23,33 +21,56 @@ class EligibiltyScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String? token;
String? profileId;
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: const Text(elibilityScreenTitle), title: const Text(elibilityScreenTitle),
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));
})],
), ),
body: BlocBuilder<UserBloc, UserState>( body: BlocBuilder<UserBloc, UserState>(
builder: (context, state) { builder: (context, state) {
if (state is UserLoggedIn) { if (state is UserLoggedIn) {
token = state.userData!.user!.login!.token;
profileId =
state.userData!.user!.login!.user!.profileId.toString();
return ProgressHUD( return ProgressHUD(
child: BlocConsumer<ProfileBloc, ProfileState>( child: BlocConsumer<ProfileBloc, ProfileState>(
listener: (context, state) { listener: (context, state) {
if(state is ProfileLoading){ if (state is EditEligibilityState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
if (state is ProfileLoading) {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.showWithText("Loading"); progress!.showWithText("Loading");
} }
if (state is EditNotOverseasEligibilityState) { if (state is EligibilityLoaded) {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.dismiss(); progress!.dismiss();
}if (state is EditOverseasEligibilityState) { }if(state is AddEligibilityState){
final progress = ProgressHUD.of(context);
progress!.dismiss();
}if(state is EligibilityLoaded){
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.dismiss(); 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 // TODO: implement listener
}, },
builder: (context, state) { builder: (context, state) {
@ -62,7 +83,7 @@ class EligibiltyScreen extends StatelessWidget {
itemCount: state.eligibilities.length, itemCount: state.eligibilities.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
String title = state String title = state
.eligibilities[index].eligibility!.title!; .eligibilities[index].eligibility!.title;
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -104,7 +125,7 @@ class EligibiltyScreen extends StatelessWidget {
height: 3, height: 3,
), ),
Text( Text(
"Rating : ${state.eligibilities[index].rating}.", "Rating : ${state.eligibilities[index].rating ?? 'N/A'}.",
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.titleSmall) .titleSmall)
@ -115,10 +136,19 @@ class EligibiltyScreen extends StatelessWidget {
elevation: 3, elevation: 3,
onSelected: (value) { onSelected: (value) {
if (value == 2) { if (value == 2) {
confirmAlert( confirmAlert(context, () {
context, BlocProvider.of<
() => null, ProfileBloc>(context)
"Delete?", .add(DeleteEligibility(
eligibilities: state
.eligibilities,
eligibilityId: state
.eligibilities[
index]
.id!,
profileId: profileId!,
token: token!));
}, "Delete?",
"Confirm Delete?"); "Confirm Delete?");
} }
if (value == 1) { if (value == 1) {
@ -140,17 +170,12 @@ class EligibiltyScreen extends StatelessWidget {
overseas; overseas;
progress! progress!
.showWithText("Loading..."); .showWithText("Loading...");
if (eligibityCert.overseas!) {
context.read<ProfileBloc>().add( context.read<ProfileBloc>().add(
EditEligibilityOverseas( EditEligibility(
selectedProvince: null,
selectedRegion: null,
eligibityCert: eligibityCert:
eligibityCert)); eligibityCert));
} else {
context.read<ProfileBloc>().add(
EditEligibilityNotOverseas(
eligibityCert:
eligibityCert));
}
} }
}, },
menuItems: [ menuItems: [
@ -183,12 +208,22 @@ class EligibiltyScreen extends StatelessWidget {
); );
}); });
} }
if (state is EditNotOverseasEligibilityState) { if (state is EditEligibilityState) {
return EditEligibilityScreen(
eligibityCert: state.eligibityCert);
}if(state is EditOverseasEligibilityState){
return EditEligibilityScreen( return EditEligibilityScreen(
eligibityCert: state.eligibityCert); 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(); return Container();
}, },

View File

@ -60,7 +60,7 @@ class _UniT2LoginState extends State<UniT2Login> {
if (state is InvalidCredentials) { if (state is InvalidCredentials) {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.dismiss(); progress!.dismiss();
errorAlert(context, "Error Login", state.message); errorAlert(context, "Error Login", state.message,(){});
context.read<UserBloc>().add(LoadVersion()); context.read<UserBloc>().add(LoadVersion());
} }
}, builder: (context, state) { }, builder: (context, state) {

View File

@ -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!;
}
}

View File

@ -36,7 +36,7 @@ confirmAlert(context, Function() yes,String title, String subtitle) {
).show(); ).show();
} }
errorAlert(context, title, description) { errorAlert(context, title, description,Function() func) {
AwesomeDialog( AwesomeDialog(
width: blockSizeHorizontal * 90, width: blockSizeHorizontal * 90,
context: context, context: context,
@ -45,7 +45,20 @@ errorAlert(context, title, description) {
headerAnimationLoop: false, headerAnimationLoop: false,
title: title, title: title,
desc: description, 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, btnOkColor: Colors.red,
).show(); ).show();
} }

View File

@ -96,4 +96,47 @@ class Request {
} }
return response; 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;
}
} }

View File

@ -18,6 +18,9 @@ class Url {
String eligibilities(){ String eligibilities(){
return "/api/jobnet_app/eligibilities/"; return "/api/jobnet_app/eligibilities/";
}
String deleteEligibility(){
return "/api/jobnet_app/profile/pds/eligibility/";
} }
// location utils path // location utils path
String getCounties(){ String getCounties(){