diff --git a/lib/bloc/profile/eligibility/eligibility_bloc.dart b/lib/bloc/profile/eligibility/eligibility_bloc.dart index 9ce54ee..28c0627 100644 --- a/lib/bloc/profile/eligibility/eligibility_bloc.dart +++ b/lib/bloc/profile/eligibility/eligibility_bloc.dart @@ -16,33 +16,57 @@ class EligibilityBloc extends Bloc { EligibilityBloc() : super(EligibilityInitial()) { List? globalCountries; List? globalRegions; - List? globalEligibilities; - List? eligibilities; -////===================================================================== + List globalEligibilities = []; + List eligibilities = []; +//// LOAD ELIGIBILTY on((event, emit) { emit(EligibilityLoadingState()); - eligibilities = event.eligibilities; - emit(EligibilityLoaded(eligibilities: event.eligibilities)); + if (eligibilities.isEmpty) { + GetEligibilities(profileId: event.profileId!, token: event.token!); + } else { + emit(EligibilityLoaded(eligibilities: eligibilities)); + } }); -////==================================================================== - on((event, emit) async { + + //// DELETE + on((event, emit) async { try { - if (eligibilities != null) { - emit(EligibilityLoaded(eligibilities: eligibilities!)); + final bool success = await EligibilityService.instance.delete( + eligibilityId: event.eligibilityId, + profileId: int.parse(event.profileId), + token: event.token); + if (success) { + eligibilities.removeWhere( + ((EligibityCert element) => element.id == event.eligibilityId)); + emit(DeletedState( + success: success, + )); } else { - emit(EligibilityLoadingState()); - eligibilities = await EligibilityService.instance - .getEligibilities(event.profileId, event.token); - emit(EligibilityLoaded(eligibilities: eligibilities!)); + emit(DeletedState(success: success)); } } catch (e) { emit(EligibilityErrorState(message: e.toString())); } }); -////==================================================================== + +//// GET ELIGIBILITY + on((event, emit) async { + try { + if (eligibilities.isNotEmpty) { + emit(EligibilityLoaded(eligibilities: eligibilities)); + } else { + emit(EligibilityLoadingState()); + eligibilities = await EligibilityService.instance + .getEligibilities(event.profileId, event.token); + emit(EligibilityLoaded(eligibilities: eligibilities)); + } + } catch (e) { + emit(EligibilityErrorState(message: e.toString())); + } + }); +//// SHOW EDIT FORM on((event, emit) async { try { - emit(EligibilityLoadingState()); if (globalCountries == null) { List countries = await LocationUtils.instance.getCountries(); globalCountries = countries; @@ -51,12 +75,12 @@ class EligibilityBloc extends Bloc { List regions = await LocationUtils.instance.getRegions(); globalRegions = regions; } - if (globalEligibilities == null) { + if (globalEligibilities.isEmpty) { List eligibilities = await ProfileUtilities.instance.getEligibilities(); globalEligibilities = eligibilities; } - Eligibility currentEligibility = globalEligibilities!.firstWhere( + Eligibility currentEligibility = globalEligibilities.firstWhere( (Eligibility eligibility) => event.eligibityCert.eligibility!.id == eligibility.id); bool? isOverseas = event.eligibityCert.overseas; @@ -95,7 +119,7 @@ class EligibilityBloc extends Bloc { eligibityCert: event.eligibityCert, countries: globalCountries!, regions: globalRegions!, - eligibilities: globalEligibilities!)); + eligibilities: globalEligibilities)); } else { emit(EditEligibilityState( selectedCountry: currentCountry, @@ -109,17 +133,16 @@ class EligibilityBloc extends Bloc { eligibityCert: event.eligibityCert, countries: globalCountries!, regions: globalRegions!, - eligibilities: globalEligibilities!)); + eligibilities: globalEligibilities)); } } catch (e) { emit(EligibilityErrorState(message: e.toString())); } }); - ////==================================================================== + //// UPDATE on((event, emit) async { try { - emit(EligibilityLoadingState()); Map status = await EligibilityService.instance.update( eligibityCert: event.eligibityCert, token: event.token, @@ -127,26 +150,25 @@ class EligibilityBloc extends Bloc { oldEligibility: event.oldEligibility); if (status['success']) { EligibityCert newEligibility = EligibityCert.fromJson(status['data']); - eligibilities!.removeWhere( + eligibilities.removeWhere( (EligibityCert element) => element.id == event.eligibityCert.id); - eligibilities!.add(newEligibility); - emit(EligibilityEditedState( - eligibilities: eligibilities!, response: status)); + eligibilities.add(newEligibility); + emit(EligibilityEditedState(response: status)); } else { - emit(EligibilityEditedState( - eligibilities: eligibilities!, response: status)); + emit(EligibilityEditedState(response: status)); } } catch (e) { emit(EligibilityErrorState(message: e.toString())); } }); + //// SHOW ADD FORM on((event, emit) async { emit(EligibilityLoadingState()); if (globalRegions == null) { List regions = await LocationUtils.instance.getRegions(); globalRegions = regions; } - if (globalEligibilities == null) { + if (globalEligibilities.isEmpty) { List eligibilities = await ProfileUtilities.instance.getEligibilities(); globalEligibilities = eligibilities; @@ -157,37 +179,15 @@ class EligibilityBloc extends Bloc { } emit(AddEligibilityState( - eligibilities: globalEligibilities!, + eligibilities: globalEligibilities, regions: globalRegions!, countries: globalCountries!)); }); - ////==================================================================== - on((event, emit) async { - emit(EligibilityLoadingState()); - 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 eligibilities = event.eligibilities; - emit(DeletedState(success: success, eligibilities: eligibilities)); - } else { - emit(DeletedState( - success: success, eligibilities: event.eligibilities)); - } - } catch (e) { - emit(EligibilityErrorState(message: e.toString())); - } - }); - ////==================================================================== + + //// ADD on( (event, emit) async { try { - emit(EligibilityLoadingState()); Map status = await EligibilityService.instance.add( eligibityCert: event.eligibityCert, token: event.token, @@ -195,12 +195,10 @@ class EligibilityBloc extends Bloc { if (status['success']) { EligibityCert? eligibityCert = EligibityCert.fromJson(status['data']); - eligibilities!.add(eligibityCert); - emit(EligibilityAddedState( - eligibilities: eligibilities!, response: status)); + eligibilities.add(eligibityCert); + emit(EligibilityAddedState(response: status)); } else { - emit(EligibilityAddedState( - eligibilities: eligibilities!, response: status)); + emit(EligibilityAddedState(response: status)); } } catch (e) { emit(EligibilityErrorState(message: e.toString())); diff --git a/lib/bloc/profile/eligibility/eligibility_event.dart b/lib/bloc/profile/eligibility/eligibility_event.dart index 381ffd8..6b83a27 100644 --- a/lib/bloc/profile/eligibility/eligibility_event.dart +++ b/lib/bloc/profile/eligibility/eligibility_event.dart @@ -38,8 +38,9 @@ class UpdateEligibility extends EligibilityEvent{ List get props =>[eligibityCert,profileId,token,oldEligibility]; } class LoadEligibility extends EligibilityEvent { - final List eligibilities; - const LoadEligibility({required this.eligibilities}); + final int? profileId; + final String? token; + const LoadEligibility({ this.profileId, this.token}); @override List get props => []; } @@ -52,17 +53,16 @@ class ShowEditEligibilityForm extends EligibilityEvent { } class DeleteEligibility extends EligibilityEvent { - final List 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 get props => [eligibilities, profileId, eligibilityId, token]; + List get props => [ profileId, eligibilityId, token]; } class CallErrorState extends EligibilityEvent{ diff --git a/lib/bloc/profile/eligibility/eligibility_state.dart b/lib/bloc/profile/eligibility/eligibility_state.dart index 63421db..3b57f6d 100644 --- a/lib/bloc/profile/eligibility/eligibility_state.dart +++ b/lib/bloc/profile/eligibility/eligibility_state.dart @@ -43,11 +43,10 @@ class EditEligibilityState extends EligibilityState { } class DeletedState extends EligibilityState { - final List eligibilities; final bool success; - const DeletedState({required this.eligibilities, required this.success}); + const DeletedState({required this.success}); @override - List get props => [success, eligibilities]; + List get props => [success]; } class AddEligibilityState extends EligibilityState { @@ -63,20 +62,18 @@ class AddEligibilityState extends EligibilityState { List get props => [eligibilities,countries,regions]; } class EligibilityEditedState extends EligibilityState{ - final List eligibilities; final Map response; - const EligibilityEditedState({required this.eligibilities, required this.response}); + const EligibilityEditedState({required this.response}); @override - List get props =>[eligibilities, response]; + List get props =>[ response]; } class EligibilityAddedState extends EligibilityState{ - final List eligibilities; final Map response; - const EligibilityAddedState({required this.eligibilities, required this.response}); + const EligibilityAddedState({ required this.response}); @override - List get props =>[eligibilities,response]; + List get props =>[response]; } class EligibilityLoadingState extends EligibilityState{ diff --git a/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart b/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart index 41da2ed..fee8447 100644 --- a/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart +++ b/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart @@ -1,6 +1,5 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; -import 'package:unit2/model/profile/work_history.dart'; import 'package:unit2/model/utils/agency.dart'; import 'package:unit2/model/utils/category.dart'; import 'package:unit2/sevices/profile/orgmembership_services.dart'; @@ -30,7 +29,7 @@ class OrganizationMembershipBloc extends Bloc((event,emit){ - emit(OrganizationMembershipLoaded(orgMemberships: event.organizationMemberships)); + emit(OrganizationMembershipLoaded(orgMemberships: organizationMemberships)); }); ////SHOW ADD ORG MEMBERSHIP FORM @@ -52,15 +51,14 @@ class OrganizationMembershipBloc extends Bloc((event,emit)async{ - emit(OrgmembershipLoadingState()); try{ Map status= await OrganizationMembershipServices.instance.add(agency: event.agency, token: event.token, profileId: event.profileId.toString()); if(status["success"]){ OrganizationMembership organizationMembership = OrganizationMembership.fromJson(status["data"]); organizationMemberships.add(organizationMembership); - emit(OrgMembershipAddedState(orgMemberships: organizationMemberships, response: status)); + emit(OrgMembershipAddedState( response: status)); }else{ - emit(OrgMembershipAddedState(orgMemberships: organizationMemberships, response: status)); + emit(OrgMembershipAddedState( response: status)); } }catch(e){ emit(OrganizationMembershipErrorState(message: e.toString())); @@ -72,11 +70,10 @@ class OrganizationMembershipBloc extends Bloc element.agency!.id == event.org.agency!.id ); - List orgmemberships = event.organizationMemberships; - emit(OrgMembershipDeletedState(organizationMemberships: orgmemberships, success: success)); + organizationMemberships.removeWhere((element) => element.agency!.id == event.org.agency!.id ); + emit(OrgMembershipDeletedState(success: success)); }else{ - emit(OrgMembershipDeletedState(organizationMemberships: organizationMemberships, success: success)); + emit(OrgMembershipDeletedState(success: success)); } }catch(e){ emit(OrganizationMembershipErrorState(message: e.toString())); diff --git a/lib/bloc/profile/other_information/org_membership/organization_membership_event.dart b/lib/bloc/profile/other_information/org_membership/organization_membership_event.dart index 2be3627..a85a91a 100644 --- a/lib/bloc/profile/other_information/org_membership/organization_membership_event.dart +++ b/lib/bloc/profile/other_information/org_membership/organization_membership_event.dart @@ -8,17 +8,15 @@ abstract class OrganizationMembershipEvent extends Equatable { } class LoadOrganizationMemberships extends OrganizationMembershipEvent{ - final List organizationMemberships; - const LoadOrganizationMemberships({required this.organizationMemberships}); @override - List get props => [organizationMemberships]; + List get props => []; } class GetOrganizationMembership extends OrganizationMembershipEvent{ final int? profileId; final String? token; - const GetOrganizationMembership({ this.profileId, this.token}); + const GetOrganizationMembership({this.profileId, this.token}); } class ShowAddOrgMembershipForm extends OrganizationMembershipEvent{ @@ -37,9 +35,9 @@ class DeleteOrgMemberShip extends OrganizationMembershipEvent{ final int profileId; final String token; final OrganizationMembership org; - final List organizationMemberships; - const DeleteOrgMemberShip({required this.profileId, required this.token, required this.org, required this.organizationMemberships}); + + const DeleteOrgMemberShip({required this.profileId, required this.token, required this.org,}); @override - List get props => [profileId,token,org,organizationMemberships]; + List get props => [profileId,token,org]; } diff --git a/lib/bloc/profile/other_information/org_membership/organization_membership_state.dart b/lib/bloc/profile/other_information/org_membership/organization_membership_state.dart index f84adb7..0680c75 100644 --- a/lib/bloc/profile/other_information/org_membership/organization_membership_state.dart +++ b/lib/bloc/profile/other_information/org_membership/organization_membership_state.dart @@ -27,18 +27,16 @@ class OrgmembershipLoadingState extends OrganizationMembershipState{ } class OrgMembershipDeletedState extends OrganizationMembershipState{ - final List organizationMemberships; final bool success; - const OrgMembershipDeletedState({required this.organizationMemberships, required this.success}); + const OrgMembershipDeletedState({ required this.success}); @override - List get props => [organizationMemberships,success]; + List get props => [success]; } class OrgMembershipAddedState extends OrganizationMembershipState{ - final List orgMemberships; final Map response; - const OrgMembershipAddedState({required this.orgMemberships, required this.response}); + const OrgMembershipAddedState({required this.response}); @override - List get props => [orgMemberships,response]; + List get props => [response]; } class AddOrgMembershipState extends OrganizationMembershipState{ diff --git a/lib/bloc/profile/primary_information/contact/contact_bloc.dart b/lib/bloc/profile/primary_information/contact/contact_bloc.dart index 9f8070d..5753c70 100644 --- a/lib/bloc/profile/primary_information/contact/contact_bloc.dart +++ b/lib/bloc/profile/primary_information/contact/contact_bloc.dart @@ -14,7 +14,7 @@ part 'contact_state.dart'; class ContactBloc extends Bloc { ContactBloc() : super(ContactInitial()) { List contactInformations = []; - List serviceTypes =[]; + List serviceTypes = []; //// get all contacts on((event, emit) { emit(ContactLoadingState()); @@ -26,72 +26,118 @@ class ContactBloc extends Bloc { } }); //// Load Contacts - on((event,emit){ - emit(ContactLoadedState(contactInformation: event.contactInformation)); + on((event, emit) { + emit(ContactLoadedState(contactInformation: contactInformations)); }); - //// show add form - on((event,emit)async{ - try{ - emit(ContactLoadingState()); - if(serviceTypes.isEmpty){ + //// show add form + on((event, emit) async { + try { + emit(ContactLoadingState()); + if (serviceTypes.isEmpty) { + serviceTypes = await ProfileUtilities.instance.getServiceType(); + } + emit(ContactAddingState(serviceTypes: serviceTypes)); + } catch (e) { + emit(ContactErrorState(message: e.toString())); + } + }); + ///// Show edit form + on((event, emit) async { + ServiceType serviceType; + List commServiceProvivers; + CommService serviceProvider; + try{ + if (serviceTypes.isEmpty) { serviceTypes = await ProfileUtilities.instance.getServiceType(); } - emit(ContactAddingState(serviceTypes: serviceTypes)); - }catch(e){ - emit(ContactErrorState(message: e.toString())); - } - }); - ///// Show edit form - on((event,emit)async{ - ServiceType serviceType; - List serviceProvivers; - ServiceProvider serviceProvider; - try{ - if(serviceTypes.isEmpty){ - serviceTypes = await ProfileUtilities.instance.getServiceType(); - } - serviceType = serviceTypes.firstWhere((var element){ - return event.contactInfo.commService!.serviceType!.id == element.id; + serviceType = serviceTypes.firstWhere((ServiceType element) { + return element.id == event.contactInfo.commService!.serviceType!.id; }); - serviceProvivers = await ContactService.instance.getServiceProvider(serviceTypeId: serviceType.id!); - serviceProvider = serviceProvivers.firstWhere((element) => element.id == event.contactInfo.commService!.serviceProvider!.id); - emit(ContactEditingState(serviceTypes: serviceTypes,selectedServiceType: serviceType,serviceProviders: serviceProvivers,selectedProvider: serviceProvider, contactInfo: event.contactInfo)); - }catch(e){ - emit(ContactErrorState(message: e.toString())); - } - }); - ////edit contact - on((event,emit)async{ - Map responseStatus = await ContactService.instance.update(profileId: event.profileId, token: event.token, contactInfo: event.contactInfo); - if(responseStatus['success']){ - ContactInfo contactInfo = ContactInfo.fromJson(responseStatus['data']['contact_info']); - contactInformations.removeWhere((ContactInfo element) => element.id == event.contactInfo.id); - contactInformations.add(contactInfo); - emit(ContactEditedState(contactInformation: contactInformations, response: responseStatus)); - }else{ - emit(ContactEditedState(contactInformation: contactInformations, response: responseStatus)); - } - }); - - //// add contact - try{ - - }catch(e){ - emit(ContactErrorState(message: e.toString())); - } - //// delete contact - on((event, emit)async{ - try{ - final bool success = await ContactService.instance.deleteContact(profileId: event.profileId, token: event.token, contactInfo: event.contactInfo); - if(success){ - contactInformations.removeWhere((element) => element.id == event.contactInfo.id); - emit(ContactDeletedState(contactInformation: contactInformations, succcess: success)); - }else{ - emit(ContactDeletedState(contactInformation: contactInformations, succcess: success)); + commServiceProvivers = await ContactService.instance + .getServiceProvider(serviceTypeId: serviceType.id!); + serviceProvider = commServiceProvivers.firstWhere((CommService element) => + element.id == event.contactInfo.commService!.id); + emit(ContactEditingState( + serviceTypes: serviceTypes, + selectedServiceType: serviceType, + commServiceProviders: commServiceProvivers, + selectedProvider: serviceProvider, + contactInfo: event.contactInfo)); + }catch(e){ + emit(ContactErrorState(message: e.toString())); } - }catch(e){ - emit(ContactErrorState(message: e.toString())); - } - }); + }); + ////edit contact + on((event, emit) async { + try { + Map responseStatus = await ContactService.instance + .update( + profileId: event.profileId, + token: event.token, + contactInfo: event.contactInfo); + if (responseStatus['success']) { + ContactInfo contactInfo = + ContactInfo.fromJson(responseStatus['data']['contact_info']); + contactInformations.removeWhere( + (ContactInfo element) => element.id == event.contactInfo.id); + contactInformations.add(contactInfo); + emit(ContactEditedState( + + response: responseStatus)); + } else { + emit(ContactEditedState( + + response: responseStatus)); + } + } catch (e) { + emit(ContactErrorState(message: e.toString())); + } + }); + + //// add contact + + on((event, emit) async { + try { + Map responseStatus = await ContactService.instance + .add( + profileId: event.profileId, + token: event.token, + contactInfo: event.contactInfo); + if (responseStatus['success']) { + ContactInfo contactInfo = + ContactInfo.fromJson(responseStatus['data']['contact_info']); + contactInformations.add(contactInfo); + emit(ContactEditedState( + + response: responseStatus)); + } else { + emit(ContactEditedState( + + response: responseStatus)); + } + } catch (e) { + emit(ContactErrorState(message: e.toString())); + } + }); + //// delete contact + on((event, emit) async { + try { + final bool success = await ContactService.instance.deleteContact( + profileId: event.profileId, + token: event.token, + contactInfo: event.contactInfo); + if (success) { + contactInformations + .removeWhere((element) => element.id == event.contactInfo.id); + emit(ContactDeletedState( + succcess: success)); + } else { + emit(ContactDeletedState( + succcess: success)); + } + } catch (e) { + emit(ContactErrorState(message: e.toString())); + } + }); } } diff --git a/lib/bloc/profile/primary_information/contact/contact_event.dart b/lib/bloc/profile/primary_information/contact/contact_event.dart index e5259eb..5e7106f 100644 --- a/lib/bloc/profile/primary_information/contact/contact_event.dart +++ b/lib/bloc/profile/primary_information/contact/contact_event.dart @@ -17,10 +17,9 @@ class GetContacts extends ContactEvent{ //// load contacts class LoadContacts extends ContactEvent{ - final List contactInformation; - const LoadContacts({required this.contactInformation}); + @override - List get props => [contactInformation]; + List get props => []; } //// show add form diff --git a/lib/bloc/profile/primary_information/contact/contact_state.dart b/lib/bloc/profile/primary_information/contact/contact_state.dart index 863f11c..af38743 100644 --- a/lib/bloc/profile/primary_information/contact/contact_state.dart +++ b/lib/bloc/profile/primary_information/contact/contact_state.dart @@ -30,11 +30,11 @@ class ContactAddingState extends ContactState{ //// Editing state class ContactEditingState extends ContactState{ final List serviceTypes; - final List serviceProviders; - final ServiceProvider selectedProvider; + final List commServiceProviders; + final CommService selectedProvider; final ServiceType selectedServiceType; final ContactInfo contactInfo; - const ContactEditingState({ required this.serviceTypes, required this.selectedServiceType, required this.selectedProvider, required this.serviceProviders, required this.contactInfo}); + const ContactEditingState({ required this.serviceTypes, required this.selectedServiceType, required this.selectedProvider, required this.commServiceProviders, required this.contactInfo}); @override List get props => [serviceTypes]; } @@ -42,11 +42,11 @@ class ContactEditingState extends ContactState{ //// added state class ContactAddedState extends ContactState{ - final List contactInformation; + final Map response; - const ContactAddedState({required this.contactInformation, required this.response}); + const ContactAddedState({ required this.response}); @override - List get props => [contactInformation,response]; + List get props => [response]; } @@ -54,19 +54,19 @@ class ContactAddedState extends ContactState{ //// edited state class ContactEditedState extends ContactState{ - final List contactInformation; + final Map response; - const ContactEditedState({required this.contactInformation, required this.response}); + const ContactEditedState({ required this.response}); @override - List get props => [contactInformation,response]; + List get props => [response]; } ////deleted state class ContactDeletedState extends ContactState{ - final List contactInformation; + final bool succcess; - const ContactDeletedState({required this.contactInformation, required this.succcess}); + const ContactDeletedState({required this.succcess}); @override - List get props => [contactInformation,succcess]; + List get props => [succcess]; } ////error state diff --git a/lib/bloc/profile/references/references_bloc.dart b/lib/bloc/profile/references/references_bloc.dart index 3564706..ba27258 100644 --- a/lib/bloc/profile/references/references_bloc.dart +++ b/lib/bloc/profile/references/references_bloc.dart @@ -104,7 +104,11 @@ class ReferencesBloc extends Bloc { event.personalReference.address!.cityMunicipality!.code == city.code); List barangays = await LocationUtils.instance.getBarangay(code: selectedCity.code.toString()); - selectedBarangay = barangays.firstWhere((Barangay barangay)=>event.personalReference.address!.barangay!.code == barangay.code); + if(event.personalReference.address?.barangay!=null){ + selectedBarangay = barangays.firstWhere((Barangay barangay)=>event.personalReference.address?.barangay?.code == barangay.code); + }else{ + selectedBarangay = null; + } emit(EditReferenceState( selectedRegion: selectedRegion, ref: event.personalReference, @@ -144,17 +148,16 @@ class ReferencesBloc extends Bloc { message: "Something went wrong. Please try again")); //// EDIT REFERENCES EVENT });on((event,emit)async{ - emit(ReferencesLoadingState()); Map status =await ReferencesServices.instace.update(ref: event.reference, token: event.token, profileId: event.profileId); if (status['success']) { PersonalReference ref = PersonalReference.fromJson(status['data']); references.removeWhere((PersonalReference element)=>element.id == event.reference.id); references.add(ref); emit( - ReferenceEditedState(personalRefs: references, response: status)); + ReferenceEditedState( response: status)); } else { emit( - ReferenceEditedState(personalRefs: references, response: status)); + ReferenceEditedState( response: status)); } }); @@ -171,10 +174,10 @@ class ReferencesBloc extends Bloc { PersonalReference ref = PersonalReference.fromJson(status['data']); references.add(ref); emit( - ReferencesAddedState(personalRefs: references, response: status)); + ReferencesAddedState( response: status)); } else { emit( - ReferencesAddedState(personalRefs: references, response: status)); + ReferencesAddedState( response: status)); } } catch (e) { emit(ReferencesErrorState(message: e.toString())); @@ -183,7 +186,6 @@ class ReferencesBloc extends Bloc { ////LOAD REFERENCE on((event, emit) { emit(ReferencesLoadingState()); - references = event.references; emit(ReferencesLoadedState(references: references)); }); @@ -196,9 +198,9 @@ class ReferencesBloc extends Bloc { event.references.removeWhere( (PersonalReference element) => element.id == event.refId); references = event.references; - emit(DeleteReferenceState(references: references, success: success)); + emit(DeleteReferenceState( success: success)); } else { - emit(DeleteReferenceState(references: references, success: success)); + emit(DeleteReferenceState(success: success)); } } catch (e) { emit(ReferencesErrorState(message: e.toString())); diff --git a/lib/bloc/profile/references/references_event.dart b/lib/bloc/profile/references/references_event.dart index 584bebb..5eedf7d 100644 --- a/lib/bloc/profile/references/references_event.dart +++ b/lib/bloc/profile/references/references_event.dart @@ -7,63 +7,60 @@ abstract class ReferencesEvent extends Equatable { List get props => []; } -class GetReferences extends ReferencesEvent{ +class GetReferences extends ReferencesEvent { final int profileId; final String token; const GetReferences({required this.profileId, required this.token}); - @override - List get props => [profileId,token]; + @override + List get props => [profileId, token]; } -class ShowAddReferenceForm extends ReferencesEvent{ - -} +class ShowAddReferenceForm extends ReferencesEvent {} -class ShowEditReferenceForm extends ReferencesEvent{ +class ShowEditReferenceForm extends ReferencesEvent { final PersonalReference personalReference; const ShowEditReferenceForm({required this.personalReference}); - @override + @override List get props => [personalReference]; - -} -class CallErrorState extends ReferencesEvent{ - } +class CallErrorState extends ReferencesEvent {} -class AddReference extends ReferencesEvent{ +class AddReference extends ReferencesEvent { final PersonalReference reference; final String token; final int profileId; - const AddReference({required this.profileId, required this.reference,required this.token}); - @override - List get props => [profileId,token,reference]; -} -class EditReference extends ReferencesEvent{ - final PersonalReference reference; - final String token; - final int profileId; - const EditReference({required this.profileId, required this.reference,required this.token}); - @override - List get props => [profileId,token,reference]; + const AddReference( + {required this.profileId, required this.reference, required this.token}); + @override + List get props => [profileId, token, reference]; } -class DeleteReference extends ReferencesEvent{ - final Listreferences; +class EditReference extends ReferencesEvent { + final PersonalReference reference; + final String token; + final int profileId; + const EditReference( + {required this.profileId, required this.reference, required this.token}); + @override + List get props => [profileId, token, reference]; +} + +class DeleteReference extends ReferencesEvent { + final List references; final int profileId; final String token; final int refId; - const DeleteReference({required this.profileId, required this.refId, required this.references, required this.token}); - @override - List get props => [profileId,token,refId,references]; -} - -class LoadReferences extends ReferencesEvent{ - final List references; - const LoadReferences({required this.references}); + const DeleteReference( + {required this.profileId, + required this.refId, + required this.references, + required this.token}); @override - List get props => [references]; + List get props => [profileId, token, refId, references]; } - - +class LoadReferences extends ReferencesEvent { + @override + List get props => []; +} diff --git a/lib/bloc/profile/references/references_state.dart b/lib/bloc/profile/references/references_state.dart index 207a3fe..b3a07d3 100644 --- a/lib/bloc/profile/references/references_state.dart +++ b/lib/bloc/profile/references/references_state.dart @@ -28,20 +28,19 @@ class ReferencesErrorState extends ReferencesState { class ReferencesLoadingState extends ReferencesState {} class ReferencesAddedState extends ReferencesState { - final List personalRefs; final Map response; const ReferencesAddedState( - {required this.personalRefs, required this.response}); + { required this.response}); @override - List get props => [personalRefs, response]; + List get props => [ response]; } class ReferenceEditedState extends ReferencesState { - final List personalRefs; + final Map response; const ReferenceEditedState( - {required this.personalRefs, required this.response}); + { required this.response}); @override - List get props => [personalRefs, response]; + List get props => [ response]; } class EditReferenceState extends ReferencesState { @@ -89,7 +88,6 @@ class AddReferenceState extends ReferencesState { } class DeleteReferenceState extends ReferencesState { - final List references; final bool success; - const DeleteReferenceState({required this.references, required this.success}); + const DeleteReferenceState({ required this.success}); } diff --git a/lib/bloc/profile/workHistory/workHistory_bloc.dart b/lib/bloc/profile/workHistory/workHistory_bloc.dart index 4f42748..d19eca5 100644 --- a/lib/bloc/profile/workHistory/workHistory_bloc.dart +++ b/lib/bloc/profile/workHistory/workHistory_bloc.dart @@ -24,9 +24,12 @@ class WorkHistoryBloc extends Bloc { on((event, emit) async { emit(WorkHistoryLoadingState()); try { - List works = await WorkHistoryService.instance - .getWorkExperiences(event.profileId, event.token); - workExperiences = works; + if (workExperiences.isEmpty) { + List works = await WorkHistoryService.instance + .getWorkExperiences(event.profileId!, event.token!); + workExperiences = works; + } + emit(WorkHistoryLoaded(workExperiences: workExperiences)); } catch (e) { emit(WorkHistoryErrorState(message: e.toString())); @@ -35,34 +38,29 @@ class WorkHistoryBloc extends Bloc { ///// LOAD WORK HISTORIES on((event, emit) { emit(WorkHistoryLoadingState()); - workExperiences = event.workHistories; emit(WorkHistoryLoaded(workExperiences: workExperiences)); }); ////DELETE on((event, emit) async { - emit(WorkHistoryLoadingState()); try { final bool success = await WorkHistoryService.instance.delete( profileId: event.profileId, token: event.token, work: event.workHistory); if (success) { - event.workHistories.removeWhere( + workExperiences.removeWhere( (WorkHistory element) => element.id == event.workHistory.id); - List newWorkHistories = event.workHistories; - emit(DeletedState(success: success, workHistories: newWorkHistories)); + emit(DeletedState(success: success)); } else { - emit(DeletedState( - success: success, workHistories: event.workHistories)); + emit(DeletedState(success: success)); } } catch (e) { emit(WorkHistoryErrorState(message: e.toString())); } }); - //// ADD WORK HISTORIES + //// ADD WORK HISTORIES on((event, emit) async { try { - emit(WorkHistoryLoadingState()); Map status = await WorkHistoryService.instance.add( isPrivate: event.isPrivate, workHistory: event.workHistory, @@ -71,39 +69,39 @@ class WorkHistoryBloc extends Bloc { if (status['success']) { WorkHistory workHistory = WorkHistory.fromJson(status['data']); workExperiences.add(workHistory); - emit(WorkHistoryAddedState( - response: status, workExperiences: workExperiences)); + emit(WorkHistoryAddedState(response: status)); } else { - emit(WorkHistoryAddedState( - response: status, workExperiences: workExperiences)); + emit(WorkHistoryAddedState(response: status)); } } catch (e) { emit(WorkHistoryErrorState(message: e.toString())); } }); - ////UPDATE WORK HISTORY -on((event, emit)async{ - emit(WorkHistoryLoadingState()); - // try{ - Map status = await WorkHistoryService.instance.update(oldWorkHistory: event.oldWorkHistory, newWorkHistory: event.workHistory, token: event.token, profileId: event.profileId); - if(status['success']){ - WorkHistory workHistory = WorkHistory.fromJson(status['data']); - workExperiences.removeWhere((WorkHistory work) { - return work.id == event.oldWorkHistory.id; + on((event, emit) async { + try { + Map status = await WorkHistoryService.instance.update( + oldWorkHistory: event.oldWorkHistory, + newWorkHistory: event.workHistory, + token: event.token, + profileId: event.profileId); + if (status['success']) { + WorkHistory workHistory = WorkHistory.fromJson(status['data']); + workExperiences.removeWhere((WorkHistory work) { + return work.id == event.oldWorkHistory.id; + }); + workExperiences.add(workHistory); + emit(WorkHistoryEditedState(response: status)); + } else { + emit(WorkHistoryEditedState( + response: status, + )); + } + } catch (e) { + emit(WorkHistoryErrorState(message: e.toString())); + } }); - workExperiences.add(workHistory); - emit(WorkHistoryEditedState(workExperiences: workExperiences,response: status)); - }else{ - emit(WorkHistoryEditedState(response: status, workExperiences: workExperiences)); - } - - // }catch(e){ - // emit(WorkHistoryErrorState(message: e.toString())); - // } -}); - ////SHOW EDIT WORK HISTORIES on((event, emit) async { @@ -150,23 +148,31 @@ on((event, emit)async{ emit(WorkHistoryLoadingState()); try { /////POSITIONS------------------------------------------ - List positions = - await WorkHistoryService.instance.getAgencyPosition(); - agencyPositions = positions; + if (agencyPositions.isEmpty) { + List positions = + await WorkHistoryService.instance.getAgencyPosition(); + agencyPositions = positions; + } /////AGENCIES------------------------------------------ - List newAgencies = - await ProfileUtilities.instance.getAgecies(); - agencies = newAgencies; + if (agencies.isEmpty) { + List newAgencies = + await ProfileUtilities.instance.getAgecies(); + agencies = newAgencies; + } /////Category Agency------------------------------------------ - List categoryAgencies = - await ProfileUtilities.instance.agencyCategory(); - agencyCategory = categoryAgencies; + if (agencyCategory.isEmpty) { + List categoryAgencies = + await ProfileUtilities.instance.agencyCategory(); + agencyCategory = categoryAgencies; + } /////////------------------------------------- - List status = - WorkHistoryService.instance.getAppointmentStatusList(); - appointmentStatus = status; + if (appointmentStatus.isEmpty) { + List status = + WorkHistoryService.instance.getAppointmentStatusList(); + appointmentStatus = status; + } emit(AddWorkHistoryState( agencyPositions: agencyPositions, diff --git a/lib/bloc/profile/workHistory/workHistory_event.dart b/lib/bloc/profile/workHistory/workHistory_event.dart index 5a0dbe1..0f394b7 100644 --- a/lib/bloc/profile/workHistory/workHistory_event.dart +++ b/lib/bloc/profile/workHistory/workHistory_event.dart @@ -18,10 +18,8 @@ class GetWorkHistories extends WorkHistorytEvent{ } class LoadWorkHistories extends WorkHistorytEvent{ - final List workHistories; - const LoadWorkHistories({required this.workHistories}); @override - List get props => [workHistories]; + List get props => []; } class ShowAddWorkHistoryForm extends WorkHistorytEvent{ @@ -35,13 +33,12 @@ class ShowEditWorkHistoryForm extends WorkHistorytEvent{ } class DeleteWorkHistory extends WorkHistorytEvent{ - final List workHistories; final String token; final int profileId; final WorkHistory workHistory; - const DeleteWorkHistory({required this.profileId, required this.token, required this.workHistory, required this.workHistories}); + const DeleteWorkHistory({required this.profileId, required this.token, required this.workHistory}); @override - List get props => [token, profileId,workHistory, workHistories]; + List get props => [token, profileId,workHistory]; } class UpdateWorkHistory extends WorkHistorytEvent{ diff --git a/lib/bloc/profile/workHistory/workHistory_state.dart b/lib/bloc/profile/workHistory/workHistory_state.dart index 12a2037..2008857 100644 --- a/lib/bloc/profile/workHistory/workHistory_state.dart +++ b/lib/bloc/profile/workHistory/workHistory_state.dart @@ -53,25 +53,22 @@ class EditWorkHistoryState extends WorkHistoryState{ } class DeletedState extends WorkHistoryState{ - final List workHistories; final bool success; - const DeletedState({required this.success, required this.workHistories}); + const DeletedState({required this.success}); @override - List get props => [workHistories,success]; + List get props => [success]; } class WorkHistoryEditedState extends WorkHistoryState{ - final List workExperiences; final Map response; - const WorkHistoryEditedState({required this.response, required this.workExperiences}); + const WorkHistoryEditedState({required this.response}); @override - List get props => [workExperiences,response]; + List get props => [response]; } class WorkHistoryAddedState extends WorkHistoryState{ - final List workExperiences; final Map response; - const WorkHistoryAddedState({required this.response, required this.workExperiences}); + const WorkHistoryAddedState({required this.response}); @override - List get props => [workExperiences,response]; + List get props => [response]; } diff --git a/lib/bloc/user/user_bloc.dart b/lib/bloc/user/user_bloc.dart index 26e3e2f..5c9c705 100644 --- a/lib/bloc/user/user_bloc.dart +++ b/lib/bloc/user/user_bloc.dart @@ -34,6 +34,8 @@ class UserBloc extends Bloc { final String? saved = CREDENTIALS?.get('saved'); final String? username = CREDENTIALS?.get('username'); final String? password = CREDENTIALS?.get('password'); + debugPrint(username); + debugPrint(password); if (saved != null) { save = true; add(UserLogin(username: username, password: password)); diff --git a/lib/screens/profile/components/basic_information/contact_information/add_modal.dart b/lib/screens/profile/components/basic_information/contact_information/add_modal.dart index 362d88f..40c2494 100644 --- a/lib/screens/profile/components/basic_information/contact_information/add_modal.dart +++ b/lib/screens/profile/components/basic_information/contact_information/add_modal.dart @@ -31,14 +31,14 @@ class _AddContactInformationScreenState extends State { final formKey = GlobalKey(); ServiceType? selectedServiceType; - ServiceProvider? selectedProvider; - List serviceProviders = []; + CommService? selectedCommServiceProvider; + List commServiceProviders = []; bool callServiceType = false; bool primaryaContact = false; bool active = false; String? numberMail; var mobileFormatter = MaskTextInputFormatter( - mask: "+63 (##) ###-###", + mask: "+63 (###) ###-####", filter: {"#": RegExp(r"^[1-9][0-9]*$")}, type: MaskAutoCompletionType.lazy, initialText: "0"); @@ -82,7 +82,7 @@ class _AddContactInformationScreenState setState(() { callServiceType = true; }); - serviceProviders = await ContactService.instance + commServiceProviders = await ContactService.instance .getServiceProvider( serviceTypeId: selectedServiceType!.id!); setState(() { @@ -101,22 +101,22 @@ class _AddContactInformationScreenState child: ModalProgressHUD( color: Colors.transparent, inAsyncCall: callServiceType, - child: FormBuilderDropdown( + child: FormBuilderDropdown( validator: FormBuilderValidators.required( errorText: "This field is required"), name: "Service Provider", - items: serviceProviders.isEmpty + items: commServiceProviders.isEmpty ? [] - : serviceProviders - .map>( - (ServiceProvider e) { - return DropdownMenuItem( - value: e, child: Text(e.agency!.name!)); + : commServiceProviders + .map>( + (CommService e) { + return DropdownMenuItem( + value: e, child: Text(e.serviceProvider!.agency!.name!)); }).toList(), decoration: normalTextFieldStyle( "Communication Service *", ""), onChanged: (var serviceProvider) { - selectedProvider = serviceProvider; + selectedCommServiceProvider = serviceProvider; }), ), ), @@ -215,10 +215,7 @@ class _AddContactInformationScreenState numberMail = formKey.currentState!.value['number-mail']; - CommService commService = CommService( - id: null, - serviceType: selectedServiceType, - serviceProvider: selectedProvider); + CommService commService = selectedCommServiceProvider!; ContactInfo contactInfo = ContactInfo( id: null, active: active, diff --git a/lib/screens/profile/components/basic_information/contact_information/edit_modal.dart b/lib/screens/profile/components/basic_information/contact_information/edit_modal.dart index 9b6b1e4..e2c10a0 100644 --- a/lib/screens/profile/components/basic_information/contact_information/edit_modal.dart +++ b/lib/screens/profile/components/basic_information/contact_information/edit_modal.dart @@ -31,15 +31,15 @@ class _EditContactInformationScreenState extends State { final formKey = GlobalKey(); ServiceType? selectedServiceType; - ServiceProvider? selectedProvider; - List serviceProviders = []; + CommService? selectedCommProvider; + List commServiceProviders = []; String? numberMail; bool callServiceType = false; bool? primaryaContact; bool? active; var mobileFormatter = MaskTextInputFormatter( - mask: "+63 (##) ###-###", + mask: "+63 (###) ###-####", filter: {"#": RegExp(r"^[1-9][0-9]*$")}, type: MaskAutoCompletionType.lazy, initialText: "0"); @@ -56,8 +56,8 @@ class _EditContactInformationScreenState builder: (context, state) { if (state is ContactEditingState) { selectedServiceType = state.selectedServiceType; - selectedProvider = state.selectedProvider; - serviceProviders = state.serviceProviders; + selectedCommProvider = state.selectedProvider; + commServiceProviders = state.commServiceProviders; primaryaContact = state.contactInfo.primary!; active = state.contactInfo.active!; return FormBuilder( @@ -91,11 +91,11 @@ class _EditContactInformationScreenState setState(() { callServiceType = true; }); - serviceProviders = await ContactService.instance + commServiceProviders = await ContactService.instance .getServiceProvider( serviceTypeId: selectedServiceType!.id!); - selectedProvider = null; + selectedCommProvider = null; setState(() { setState(() { callServiceType = false; @@ -112,24 +112,24 @@ class _EditContactInformationScreenState child: ModalProgressHUD( color: Colors.transparent, inAsyncCall: callServiceType, - child: DropdownButtonFormField( - value: selectedProvider, + child: DropdownButtonFormField( + value: selectedCommProvider, validator: FormBuilderValidators.required( errorText: "This field is required"), - items: serviceProviders.isEmpty + items: commServiceProviders.isEmpty ? [] - : serviceProviders - .map>( - (ServiceProvider e) { + : commServiceProviders + .map>( + (CommService e) { return DropdownMenuItem< - ServiceProvider>( + CommService>( value: e, - child: Text(e.agency!.name!)); + child: Text(e.serviceProvider!.agency!.name!)); }).toList(), decoration: normalTextFieldStyle( "Communication Service *", ""), - onChanged: (var serviceProvider) { - selectedProvider = serviceProvider; + onChanged: (var commServiceProvider) { + selectedCommProvider = commServiceProvider; }), ), ), @@ -243,10 +243,7 @@ class _EditContactInformationScreenState if (formKey.currentState!.saveAndValidate()) { numberMail = formKey.currentState!.value['number-mail']; - CommService commService = CommService( - id: state.contactInfo.commService!.id, - serviceType: selectedServiceType, - serviceProvider: selectedProvider); + CommService commService = selectedCommProvider!; ContactInfo contactInfo = ContactInfo( id: state.contactInfo.id, active: active, diff --git a/lib/screens/profile/components/basic_information/contact_information_screen.dart b/lib/screens/profile/components/basic_information/contact_information_screen.dart index 721ab4c..b572c86 100644 --- a/lib/screens/profile/components/basic_information/contact_information_screen.dart +++ b/lib/screens/profile/components/basic_information/contact_information_screen.dart @@ -3,7 +3,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; -import 'package:fluttericon/font_awesome_icons.dart'; import 'package:unit2/bloc/profile/primary_information/contact/contact_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; @@ -14,9 +13,9 @@ import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/utils/alerts.dart'; import 'package:unit2/utils/text_container.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart'; +import 'package:unit2/widgets/Leadings/close_leading.dart'; import 'package:unit2/widgets/empty_data.dart'; - -import '../../../../bloc/profile/eligibility/eligibility_bloc.dart'; +import 'package:unit2/widgets/error_state.dart'; class ContactInformationScreen extends StatelessWidget { const ContactInformationScreen({ @@ -33,11 +32,15 @@ class ContactInformationScreen extends StatelessWidget { title: const Text(contactScreenTitle), centerTitle: true, backgroundColor: primary, - actions: [ + actions: context.watch().state is ContactLoadedState? [ AddLeading(onPressed: () { context.read().add(ShowAddForm()); }) - ], + ]:( context.watch().state is ContactAddingState || context.watch().state is ContactEditingState)?[ + CloseLeading(onPressed: (){ + context.read().add(LoadContacts()); + }) + ]:[] ), body: ProgressHUD( padding: const EdgeInsets.all(24), @@ -67,15 +70,14 @@ class ContactInformationScreen extends StatelessWidget { final progress = ProgressHUD.of(context); progress!.dismiss(); } - ////EDIT CONTACT STATE - if (state is ContactEditedState) { + ////ADDED CONTACT STATE + if (state is ContactAddedState) { if (state.response['success']) { successAlert(context, "Update Successfull!", state.response['message'], () { Navigator.of(context).pop(); context.read().add(LoadContacts( - contactInformation: - state.contactInformation)); + )); }); } else { errorAlert(context, "Update Failed", @@ -83,8 +85,27 @@ class ContactInformationScreen extends StatelessWidget { () { Navigator.of(context).pop(); context.read().add(LoadContacts( - contactInformation: - state.contactInformation)); + )); + }); + } + } + + ////EDIT CONTACT STATE + if (state is ContactEditedState) { + if (state.response['success']) { + successAlert(context, "Update Successfull!", + state.response['message'], () { + Navigator.of(context).pop(); + context.read().add(LoadContacts( + )); + }); + } else { + errorAlert(context, "Update Failed", + "Something went wrong. Please try again.", + () { + Navigator.of(context).pop(); + context.read().add(LoadContacts( + )); }); } } @@ -97,16 +118,14 @@ class ContactInformationScreen extends StatelessWidget { () { Navigator.of(context).pop(); context.read().add(LoadContacts( - contactInformation: - state.contactInformation)); + )); }); } else { errorAlert(context, "Deletion Failed", "Error deleting Contact Info", () { Navigator.of(context).pop(); context.read().add(LoadContacts( - contactInformation: - state.contactInformation)); + )); }); } } @@ -136,8 +155,7 @@ class ContactInformationScreen extends StatelessWidget { children: [ Container( decoration: box1(), - padding: const EdgeInsets.symmetric( - horizontal: 12, vertical: 8), + padding: const EdgeInsets.fromLTRB(12, 12, 0, 12), child: Row( children: [ Expanded( @@ -149,30 +167,18 @@ class ContactInformationScreen extends StatelessWidget { CrossAxisAlignment .start, children: [ - Text(numberMail, - style: Theme.of( - context) - .textTheme - .titleMedium! - .copyWith( - fontWeight: - FontWeight - .w500)), - const Divider(), - const SizedBox( - height: 5, - ), Row( children: [ Expanded( child: Text( - commService - .toString(), - style: Theme.of( - context) - .textTheme - .titleSmall, - ), + numberMail, + style: Theme.of( + context) + .textTheme + .titleMedium! + .copyWith( + fontWeight: + FontWeight.w500)), ), state.contactInformation[index] .active == @@ -201,17 +207,40 @@ class ContactInformationScreen extends StatelessWidget { : const SizedBox() ], ), + const Divider(), const SizedBox( height: 5, ), - Text(state - .contactInformation[ - index] - .commService! - .serviceProvider! - .agency! - .name - .toString()), + Row( + children: [ + Flexible( + flex: 2, + child: Text( + commService + .toString().toUpperCase(), + style: Theme.of( + context) + .textTheme + .titleSmall, + ), + ), + const SizedBox( + + child: Text(" - "), + ), + Flexible( + flex: 1, + child: Text(state + .contactInformation[ + index] + .commService! + .serviceProvider! + .agency! + .name + .toString()), + ), + ], + ), ]), ), AppPopupMenu( @@ -298,6 +327,12 @@ class ContactInformationScreen extends StatelessWidget { return EditContactInformationScreen( profileId: profileId, token: token); } + if (state is ContactErrorState) { + return SomethingWentWrong( + message: state.message, onpressed: () { + context.read().add(LoadContacts()); + }); + } return Container(); }, ); diff --git a/lib/screens/profile/components/eligibility/add_modal.dart b/lib/screens/profile/components/eligibility/add_modal.dart index 7b896fa..07068e9 100644 --- a/lib/screens/profile/components/eligibility/add_modal.dart +++ b/lib/screens/profile/components/eligibility/add_modal.dart @@ -24,7 +24,10 @@ import '../../../../utils/location_utilities.dart'; import '../../../../utils/text_container.dart'; class AddEligibilityScreen extends StatefulWidget { - const AddEligibilityScreen({super.key}); + const AddEligibilityScreen( + {super.key, required this.profileId, required this.token}); + final int profileId; + final String token; @override State createState() => _AddEligibilityScreenState(); @@ -32,7 +35,7 @@ class AddEligibilityScreen extends StatefulWidget { class _AddEligibilityScreenState extends State { final formKey = GlobalKey(); - bool? overseas; + bool? overseas = false; DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); Region? selectedRegion; Province? selectedProvince; @@ -51,449 +54,400 @@ class _AddEligibilityScreenState extends State { String? license; @override Widget build(BuildContext context) { - ////USERBLOC - return BlocBuilder( + return BlocBuilder( + buildWhen: (previous, current) { + return false; + }, builder: (context, state) { - ////LOGGED IN USER STATE - if (state is UserLoggedIn) { - ////PROFIILE BLOC - token = state.userData!.user!.login!.token; - profileId = state.userData!.user!.login!.user!.profileId.toString(); - return BlocBuilder( - builder: (context, state) { - if (state is ProfileLoaded) { - return BlocBuilder( - buildWhen: (previous, current) { - if (state is EditEligibilityState) {} - return false; - }, - builder: (context, state) { - ////ADD ELIGIBILITY STATE - if (state is AddEligibilityState) { - return ProgressHUD( - child: Center( - child: Padding( - padding: const EdgeInsets.symmetric( - vertical: 25, horizontal: 18), - child: FormBuilder( - key: formKey, - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - ////ELIGIBILITIES DROPDOWN - FormBuilderDropdown( - onChanged: (Eligibility? eligibility) { - selectedEligibility = eligibility; - }, - autovalidateMode: - AutovalidateMode.onUserInteraction, - validator: (value) => - value == null ? 'required' : null, - items: state.eligibilities - .map>( - (Eligibility eligibility) { - return DropdownMenuItem( - value: eligibility, - child: Text(eligibility.title)); - }).toList(), - name: "eligibility", - decoration: normalTextFieldStyle( - "Eligibility", "Eligibility")), - const SizedBox( - height: 20, + ////ADD ELIGIBILITY STATE + if (state is AddEligibilityState) { + return SingleChildScrollView( + child: SizedBox( + height: screenHeight * .95, + child: ProgressHUD( + child: Center( + child: Padding( + padding: + const EdgeInsets.symmetric(vertical: 25, horizontal: 18), + child: FormBuilder( + key: formKey, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + ////ELIGIBILITIES DROPDOWN + FormBuilderDropdown( + onChanged: (Eligibility? eligibility) { + selectedEligibility = eligibility; + }, + autovalidateMode: + AutovalidateMode.onUserInteraction, + validator: (value) => + value == null ? 'required' : null, + items: state.eligibilities + .map>( + (Eligibility eligibility) { + return DropdownMenuItem( + value: eligibility, + child: Text(eligibility.title)); + }).toList(), + name: "eligibility", + decoration: normalTextFieldStyle( + "Eligibility", "Eligibility")), + const SizedBox( + height: 8, + ), + + SizedBox( + width: screenWidth, + child: Row( + children: [ + ////LICENSE NUMBER + Flexible( + flex: 1, + child: FormBuilderTextField( + onChanged: (value) { + license = value; + }, + name: 'license_number', + decoration: normalTextFieldStyle( + "license number", "license number"), ), - - SizedBox( - width: screenWidth, - child: Row( - children: [ - ////LICENSE NUMBER - Flexible( - flex: 1, - child: FormBuilderTextField( - onChanged: (value) { - license = value; - }, - name: 'license_number', - decoration: normalTextFieldStyle( - "license number", - "license number"), - ), - ), - const SizedBox( - width: 12, - ), - ////RATING - Flexible( - flex: 1, - child: FormBuilderTextField( - keyboardType: const TextInputType - .numberWithOptions(), - onChanged: (value) { - rating = value; - }, - name: 'rating', - decoration: normalTextFieldStyle( - 'rating %', 'rating'), - ), - ), - ], - ), + ), + const SizedBox( + width: 8, + ), + ////RATING + Flexible( + flex: 1, + child: FormBuilderTextField( + keyboardType: + const TextInputType.numberWithOptions(), + onChanged: (value) { + rating = value; + }, + name: 'rating', + decoration: normalTextFieldStyle( + 'rating %', 'rating'), ), - const SizedBox( - height: 20, - ), - SizedBox( - width: screenWidth, - child: Row( - children: [ - ////EXAM DATE - Flexible( - flex: 1, - child: DateTimePicker( - validator: FormBuilderValidators.required(errorText: "This field is required"), - use24HourFormat: false, - icon: const Icon( - Icons.date_range), - controller: examDateController, - firstDate: DateTime(1970), - lastDate: DateTime(2100), - timeHintText: - "Date of Examination/Conferment", - decoration: - normalTextFieldStyle( - "Exam date", "") - .copyWith( - prefixIcon: - const Icon( - Icons.date_range, - color: Colors.black87, - )), - initialValue: null, - )), - const SizedBox( - width: 12, - ), - ////VALIDITY DATE - Flexible( - flex: 1, - child: DateTimePicker( - validator: FormBuilderValidators.required(errorText: "This field is required"), - controller: - validityDateController, - firstDate: DateTime(1970), - lastDate: DateTime(2100), - decoration: normalTextFieldStyle( - "Validity date", - "Validity date") - .copyWith( - prefixIcon: const Icon( - Icons.date_range, - color: Colors.black87, - )), - initialValue: null, - ), - ), - ], - ), - ), - const SizedBox( - height: 20, - ), - Text( - "Placement of Examination/Conferment", - style: Theme.of(context) - .textTheme - .displaySmall! + ), + ], + ), + ), + const SizedBox( + height: 8, + ), + SizedBox( + width: screenWidth, + child: Row( + children: [ + ////EXAM DATE + Flexible( + flex: 1, + child: DateTimePicker( + validator: FormBuilderValidators.required( + errorText: "This field is required"), + use24HourFormat: false, + icon: const Icon(Icons.date_range), + controller: examDateController, + firstDate: DateTime(1970), + lastDate: DateTime(2100), + timeHintText: + "Date of Examination/Conferment", + decoration: + normalTextFieldStyle("Exam date", "") + .copyWith( + prefixIcon: const Icon( + Icons.date_range, + color: Colors.black87, + )), + initialValue: null, + )), + const SizedBox( + width: 8, + ), + ////VALIDITY DATE + Flexible( + flex: 1, + child: DateTimePicker( + validator: FormBuilderValidators.required( + errorText: "This field is required"), + controller: validityDateController, + firstDate: DateTime(1970), + lastDate: DateTime(2100), + decoration: normalTextFieldStyle( + "Validity date", "Validity date") .copyWith( - fontSize: blockSizeVertical * 2), + prefixIcon: const Icon( + Icons.date_range, + color: Colors.black87, + )), + initialValue: null, ), - const SizedBox( - height: 12, - ), - ////OVERSEAS ADDRESS SWITCH - Column( - children: [ - FormBuilderSwitch( - validator: FormBuilderValidators.required(errorText: 'This field is required'), - initialValue: overseas, - activeColor: second, - onChanged: (value) { - setState(() { - overseas = value; - }); - }, - decoration: - normalTextFieldStyle("", ''), - name: 'overseas', - title: - const Text("Overseas Address?"), - ), - const SizedBox( - height: 20, - ), - ////COUNTRY DROPDOWN - SizedBox( - child: overseas == true - ? FormBuilderDropdown( - initialValue: null, - validator: FormBuilderValidators.required(errorText: "This field is required"), - items: state.countries.map< - DropdownMenuItem< - Country>>( - (Country country) { - return DropdownMenuItem< - Country>( - value: country, - child: FittedBox( - child: Text( - country - .name!))); - }).toList(), - name: 'country', + ), + ], + ), + ), + const SizedBox( + height: 8, + ), + Text( + "Placement of Examination/Conferment", + style: Theme.of(context) + .textTheme + .displaySmall! + .copyWith(fontSize: blockSizeVertical * 2), + ), + const SizedBox( + height: 8, + ), + ////OVERSEAS ADDRESS SWITCH + Column( + children: [ + FormBuilderSwitch( + validator: FormBuilderValidators.required( + errorText: 'This field is required'), + initialValue: overseas, + activeColor: second, + onChanged: (value) { + setState(() { + overseas = value; + }); + }, + decoration: normalTextFieldStyle("", ''), + name: 'overseas', + title: const Text("Overseas Address?"), + ), + const SizedBox( + height: 8, + ), + ////COUNTRY DROPDOWN + SizedBox( + child: overseas == true + ? FormBuilderDropdown( + initialValue: null, + validator: + FormBuilderValidators.required( + errorText: + "This field is required"), + items: state.countries + .map>( + (Country country) { + return DropdownMenuItem( + value: country, + child: FittedBox( + child: Text(country.name!))); + }).toList(), + name: 'country', + decoration: normalTextFieldStyle( + "Country*", "Country"), + onChanged: (Country? value) { + selectedCountry = value; + }, + ) + : Column( + children: [ + ////REGION DROPDOWN + FormBuilderDropdown( + autovalidateMode: AutovalidateMode + .onUserInteraction, + validator: + FormBuilderValidators.required( + errorText: + "This field is required"), + //// region onchange + onChanged: (Region? region) async { + + if(selectedRegion != region){ + setState(() { + provinceCall = true; + }); + selectedRegion = region; + getProvinces(); + } + }, + initialValue: selectedRegion, + decoration: normalTextFieldStyle( + "Region*", "Region"), + name: 'region', + items: state.regions + .map>( + (Region region) { + return DropdownMenuItem( + value: region, + child: Text( + region.description!)); + }).toList(), + ), + const SizedBox( + height: 8, + ), + ////PROVINCE DROPDOWN + SizedBox( + height: 70, + child: ModalProgressHUD( + color: Colors.transparent, + inAsyncCall: provinceCall, + child: DropdownButtonFormField< + Province?>( + autovalidateMode: + AutovalidateMode + .onUserInteraction, + validator: (value) => + value == null + ? 'required' + : null, + isExpanded: true, + value: selectedProvince, + onChanged: + (Province? province) { + + if(selectedProvince != province){ + setState(() { + cityCall = true; + }); + selectedProvince = province; + getCities(); + } + }, + items: provinces == null + ? [] + : provinces!.map< + DropdownMenuItem< + Province>>( + (Province province) { + return DropdownMenuItem( + value: province, + child: FittedBox( + child: Text(province + .description!), + )); + }).toList(), + decoration: + normalTextFieldStyle( + "Province*", + "Province")), + ), + ), + + //// CityMunicipalities dropdown + SizedBox( + height: 60, + child: ModalProgressHUD( + color: Colors.white, + inAsyncCall: cityCall, + child: DropdownButtonFormField< + CityMunicipality>( + validator: (value) => + value == null + ? 'required' + : null, + isExpanded: true, + onChanged: + (CityMunicipality? city) { + selectedMunicipality = city; + }, decoration: normalTextFieldStyle( - "Country*", - "Country"), - onChanged: - (Country? value) { - selectedCountry = value; - }, - ) - : Column( - children: [ - ////REGION DROPDOWN - FormBuilderDropdown< - Region?>( - autovalidateMode: - AutovalidateMode - .onUserInteraction, - validator: FormBuilderValidators.required(errorText: "This field is required"), - //// region onchange - onChanged: (Region? - region) async { - setState(() { - provinceCall = true; - }); - selectedRegion = - region; - getProvinces(); - }, - initialValue: - selectedRegion, - decoration: - normalTextFieldStyle( - "Region*", - "Region"), - name: 'region', - items: state.regions.map< - DropdownMenuItem< - Region>>((Region - region) { - return DropdownMenuItem< - Region>( - value: region, - child: Text(region - .description!)); - }).toList(), - ), - const SizedBox( - height: 20, - ), - ////PROVINCE DROPDOWN - SizedBox( - height: 70, - child: ModalProgressHUD( - color: Colors - .transparent, - inAsyncCall: - provinceCall, - child: DropdownButtonFormField< - Province?>( - autovalidateMode: - AutovalidateMode - .onUserInteraction, - validator: (value) => - value == null - ? 'required' - : null, - isExpanded: true, - value: - selectedProvince, - onChanged: - (Province? - province) { - setState(() { - cityCall = - true; - }); - selectedProvince = - province; - getCities(); - }, - items: provinces == - null - ? [] - : provinces!.map< - DropdownMenuItem< - Province>>((Province - province) { - return DropdownMenuItem( - value: - province, - child: - FittedBox( - child: - Text(province.description!), - )); - }).toList(), - decoration: - normalTextFieldStyle( - "Province*", - "Province")), - ), - ), - - //// CityMunicipalities dropdown - SizedBox( - height: 70, - child: ModalProgressHUD( - color: Colors.white, - inAsyncCall: cityCall, - child: DropdownButtonFormField< - CityMunicipality>( - validator: (value) => - value == null - ? 'required' - : null, - isExpanded: true, - onChanged: - (CityMunicipality? - city) { - selectedMunicipality = - city; - }, - decoration: normalTextFieldStyle( - "Municipality*", - "Municipality"), - value: - selectedMunicipality, - items: citymuns == - null - ? [] - : citymuns!.map< - DropdownMenuItem< - CityMunicipality>>( - (CityMunicipality - c) { - return DropdownMenuItem( - value: - c, - child: Text( - c.description!)); - }).toList(), - ), - ), - ), - const SizedBox( - height: 20, - ), - ], - )), - ], - ), - - const Expanded( - child: SizedBox(), - ), - - SizedBox( - width: screenWidth, - height: 60, - child: ElevatedButton( - style: mainBtnStyle(primary, - Colors.transparent, second), - onPressed: () { - //rating - double? rate = rating == null - ? null - : double.parse(rating!); - //lisence - String? licenseNumber = license; - CityMunicipality? cityMunicipality = - selectedMunicipality; - DateTime? examDate = - examDateController.text.isEmpty - ? null - : DateTime.parse( - examDateController - .text); - DateTime? validityDate = - validityDateController - .text.isEmpty - ? null - : DateTime.parse( - validityDateController - .text); - - ExamAddress examAddress = - ExamAddress( - barangay: null, - id: null, - addressCategory: null, - examAddressClass: null, - country: selectedCountry ?? - Country( - id: 175, - name: 'Philippines', - code: 'PH'), - cityMunicipality: - cityMunicipality); - EligibityCert eligibityCert = - EligibityCert( - id: null, - rating: rate, - examDate: examDate, - attachments: null, - eligibility: - selectedEligibility, - examAddress: examAddress, - validityDate: validityDate, - licenseNumber: - licenseNumber, - overseas: overseas); - if (formKey.currentState! - .saveAndValidate()) { - context - .read() - .add(AddEligibility( - eligibityCert: - eligibityCert, - profileId: profileId!, - token: token!)); - } - // context.read().add(AddEligibility(eligibityCert: eligibityCert, profileId: profileId, token: token)) - }, - child: const Text(submit)), - ), - const SizedBox( - height: 20, - ), - ]), + "Municipality*", + "Municipality"), + value: selectedMunicipality, + items: citymuns == null + ? [] + : citymuns!.map< + DropdownMenuItem< + CityMunicipality>>( + (CityMunicipality c) { + return DropdownMenuItem( + value: c, + child: Text(c + .description!)); + }).toList(), + ), + ), + ), + + ], + )), + ], ), - ), - ), - ); - } - return Container(); - }, - ); - } - return Container(); - }, + + const Expanded( + child: SizedBox(), + ), + + SizedBox( + width: screenWidth, + height: 60, + child: ElevatedButton( + style: mainBtnStyle( + primary, Colors.transparent, second), + onPressed: () { + //rating + double? rate = rating == null + ? null + : double.parse(rating!); + //lisence + String? licenseNumber = license; + CityMunicipality? cityMunicipality = + selectedMunicipality; + DateTime? examDate = examDateController + .text.isEmpty + ? null + : DateTime.parse(examDateController.text); + DateTime? validityDate = + validityDateController.text.isEmpty + ? null + : DateTime.parse( + validityDateController.text); + + ExamAddress examAddress = ExamAddress( + barangay: null, + id: null, + addressCategory: null, + examAddressClass: null, + country: selectedCountry ?? + Country( + id: 175, + name: 'Philippines', + code: 'PH'), + cityMunicipality: cityMunicipality); + EligibityCert eligibityCert = EligibityCert( + id: null, + rating: rate, + examDate: examDate, + attachments: null, + eligibility: selectedEligibility, + examAddress: examAddress, + validityDate: validityDate, + licenseNumber: licenseNumber, + overseas: overseas); + if (formKey.currentState!.saveAndValidate()) { + final progress = ProgressHUD.of(context); + progress!.showWithText("Loading..."); + context.read().add( + AddEligibility( + eligibityCert: eligibityCert, + profileId: + widget.profileId.toString(), + token: widget.token)); + } + // context.read().add(AddEligibility(eligibityCert: eligibityCert, profileId: profileId, token: token)) + }, + child: const Text(submit)), + ), + const SizedBox( + height: 20, + ), + ]), + ), + ), + ), + ), + ), ); } + return Container(); }, ); diff --git a/lib/screens/profile/components/eligibility/edit_modal.dart b/lib/screens/profile/components/eligibility/edit_modal.dart index 24df914..b2ffb29 100644 --- a/lib/screens/profile/components/eligibility/edit_modal.dart +++ b/lib/screens/profile/components/eligibility/edit_modal.dart @@ -2,11 +2,10 @@ 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:form_builder_validators/form_builder_validators.dart'; import 'package:intl/intl.dart'; import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart'; -import 'package:unit2/bloc/profile/profile_bloc.dart'; -import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/model/location/city.dart'; import 'package:unit2/model/profile/eligibility.dart'; import 'package:unit2/model/utils/eligibility.dart'; @@ -23,7 +22,9 @@ import '../../../../utils/text_container.dart'; class EditEligibilityScreen extends StatefulWidget { final EligibityCert eligibityCert; - const EditEligibilityScreen({super.key, required this.eligibityCert}); + final int profileId; + final String token; + const EditEligibilityScreen({super.key, required this.eligibityCert, required this.profileId, required this.token}); @override State createState() => _EditEligibilityScreenState(); @@ -52,20 +53,10 @@ class _EditEligibilityScreenState extends State { final validityDateController = TextEditingController(); @override Widget build(BuildContext context) { - //USERBLOC - return BlocBuilder( - builder: (context, state) { - //LOGGED IN USER STATE - if (state is UserLoggedIn) { - //PROFIILE BLOC - token = state.userData!.user!.login!.token; - profileId = state.userData!.user!.login!.user!.profileId.toString(); - return BlocBuilder( - builder: (context, state) { - if(state is ProfileLoaded){ + return BlocBuilder( buildWhen: (previous, current) { - if (state is EditEligibilityState) {} + return false; }, builder: (context, state) { @@ -194,6 +185,8 @@ class _EditEligibilityScreenState extends State { Flexible( flex: 1, child: DateTimePicker( + validator: FormBuilderValidators.required(errorText: "This field is required"), + use24HourFormat: false, controller: validityDateController, firstDate: DateTime(1970), @@ -514,6 +507,11 @@ class _EditEligibilityScreenState extends State { overseas: overseas); if (formKey.currentState! .saveAndValidate()) { + final progress = + ProgressHUD.of( + context); + progress!.showWithText( + "Loading..."); context.read().add( UpdateEligibility( eligibityCert: eligibityCert, @@ -521,8 +519,8 @@ class _EditEligibilityScreenState extends State { .eligibityCert .eligibility! .id, - profileId: profileId!, - token: token!)); + profileId:widget.profileId.toString(), + token: widget.token)); } }, child: const Text(submit)), @@ -534,15 +532,8 @@ class _EditEligibilityScreenState extends State { ), ), ); - } - return Container(); - }, - ); - } - return Container(); - }, - ); + } return Container(); }, diff --git a/lib/screens/profile/components/eligibility_screen.dart b/lib/screens/profile/components/eligibility_screen.dart index 96e43d5..34c1af2 100644 --- a/lib/screens/profile/components/eligibility_screen.dart +++ b/lib/screens/profile/components/eligibility_screen.dart @@ -16,6 +16,7 @@ import 'package:unit2/utils/text_container.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/Leadings/close_leading.dart'; import 'package:unit2/widgets/empty_data.dart'; +import 'package:unit2/widgets/error_state.dart'; import '../../../bloc/profile/eligibility/eligibility_bloc.dart'; import '../../../utils/alerts.dart'; @@ -25,13 +26,14 @@ class EligibiltyScreen extends StatelessWidget { @override Widget build(BuildContext context) { String? token; - String? profileId; + int? profileId; return WillPopScope( onWillPop: () async { return true; }, child: Scaffold( + resizeToAvoidBottomInset: true, appBar: AppBar( title: context.watch().state is AddEligibilityState ? const Text("Add Eligiblity") @@ -40,8 +42,8 @@ class EligibiltyScreen extends StatelessWidget { : const Text(elibilityScreenTitle), centerTitle: true, backgroundColor: primary, - actions: (context.watch().state is EligibilityLoaded || - context.watch().state is ProfileLoading) + actions: (context.watch().state is EligibilityLoaded) + ? [ AddLeading(onPressed: () { context @@ -49,19 +51,18 @@ class EligibiltyScreen extends StatelessWidget { .add(ShowAddEligibilityForm()); }) ] - : [ + :(context.watch().state is AddEligibilityState || context.watch().state is EditEligibilityState)? [ CloseLeading(onPressed: () { - context.read().add(GetEligibilities( - profileId: int.parse(profileId!), token: token!)); + context.read().add(const LoadEligibility()); }) - ], + ]:[], ), body: BlocBuilder( builder: (context, state) { if (state is UserLoggedIn) { token = state.userData!.user!.login!.token; profileId = - state.userData!.user!.login!.user!.profileId.toString(); + state.userData!.user!.login!.user!.profileId; return BlocBuilder( builder: (context, state) { if(state is ProfileLoaded){ @@ -82,7 +83,9 @@ class EligibiltyScreen extends StatelessWidget { state is EditEligibilityState || state is DeletedState || state is EligibilityAddedState || - state is EligibilityEditedState) { + state is EligibilityEditedState || + state is EligibilityErrorState + ) { final progress = ProgressHUD.of(context); progress!.dismiss(); } @@ -93,15 +96,15 @@ class EligibiltyScreen extends StatelessWidget { "Eligibility has been deleted successfully", () { Navigator.of(context).pop(); - context.read().add(LoadEligibility( - eligibilities: state.eligibilities)); + context.read().add(const LoadEligibility( + )); }); } else { errorAlert(context, "Deletion Failed", "Error deleting eligibility", () { Navigator.of(context).pop(); - context.read().add(LoadEligibility( - eligibilities: state.eligibilities)); + context.read().add(const LoadEligibility( + )); }); } } @@ -111,16 +114,16 @@ class EligibiltyScreen extends StatelessWidget { successAlert(context, "Adding Successfull!", state.response['message'], () { Navigator.of(context).pop(); - context.read().add(LoadEligibility( - eligibilities: state.eligibilities)); + context.read().add(const LoadEligibility( + )); }); } else { errorAlert(context, "Adding Failed", "Something went wrong. Please try again.", () { Navigator.of(context).pop(); - context.read().add(LoadEligibility( - eligibilities: state.eligibilities)); + context.read().add(const LoadEligibility( + )); }); } } @@ -130,16 +133,16 @@ class EligibiltyScreen extends StatelessWidget { successAlert(context, "Update Successfull!", state.response['message'], () { Navigator.of(context).pop(); - context.read().add(LoadEligibility( - eligibilities: state.eligibilities)); + context.read().add(const LoadEligibility( + )); }); } else { errorAlert(context, "Update Failed", "Something went wrong. Please try again.", () { Navigator.of(context).pop(); - context.read().add(LoadEligibility( - eligibilities: state.eligibilities)); + context.read().add(const LoadEligibility( + )); }); } } @@ -221,27 +224,29 @@ class EligibiltyScreen extends StatelessWidget { const Offset(-10, -10), elevation: 3, onSelected: (value) { - final progress = + + ////delete eligibilty-= = = = = = = = =>> + if (value == 2) { + + confirmAlert(context, + () { + final progress = ProgressHUD.of( context); progress!.showWithText( "Loading..."); - ////delete eligibilty-= = = = = = = = =>> - if (value == 2) { - confirmAlert(context, - () { BlocProvider.of< EligibilityBloc>( context) .add(DeleteEligibility( - eligibilities: state - .eligibilities, + + eligibilityId: state .eligibilities[ index] .id!, profileId: - profileId!, + profileId.toString(), token: token!)); }, "Delete?", @@ -249,6 +254,11 @@ class EligibiltyScreen extends StatelessWidget { } if (value == 1) { ////edit eligibilty-= = = = = = = = =>> + final progress = + ProgressHUD.of( + context); + progress!.showWithText( + "Loading..."); EligibityCert eligibityCert = state.eligibilities[ @@ -312,15 +322,17 @@ class EligibiltyScreen extends StatelessWidget { } if (state is EditEligibilityState) { return EditEligibilityScreen( + profileId: profileId!, + token: token!, eligibityCert: state.eligibityCert); } if (state is AddEligibilityState) { - return const AddEligibilityScreen(); + return AddEligibilityScreen(token: token!,profileId: profileId!,); } if (state is EligibilityErrorState) { - return Center( - child: Text(state.message), - ); + return SomethingWentWrong(message: state.message, onpressed: (){ + context.read().add(LoadEligibility(token: token,profileId: profileId)); + }); } return Container( color: Colors.grey.shade200, diff --git a/lib/screens/profile/components/loading_screen.dart b/lib/screens/profile/components/loading_screen.dart index 36952e2..0d469b9 100644 --- a/lib/screens/profile/components/loading_screen.dart +++ b/lib/screens/profile/components/loading_screen.dart @@ -135,21 +135,20 @@ class LoadingScreen extends StatelessWidget { ), Center( child: Container( - height: 120, - width: 120, + height: 80, + width: 80, decoration:const BoxDecoration( color: Colors.black87, - borderRadius: BorderRadius.all(Radius.circular(25)) + borderRadius: BorderRadius.all(Radius.circular(8)) ), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: const[ SpinKitFadingCircle( - + size: 42, color: Colors.white), - SizedBox(height: 10,), - Text("Loading Profile",textAlign: TextAlign.center, style: TextStyle(color: Colors.white,fontSize: 10),) + ], ), ), diff --git a/lib/screens/profile/components/other_information/org_membership/add_modal.dart b/lib/screens/profile/components/other_information/org_membership/add_modal.dart index 0e019f7..b2e60df 100644 --- a/lib/screens/profile/components/other_information/org_membership/add_modal.dart +++ b/lib/screens/profile/components/other_information/org_membership/add_modal.dart @@ -5,11 +5,8 @@ import 'package:fluttericon/font_awesome_icons.dart'; import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:searchfield/searchfield.dart'; import 'package:unit2/bloc/profile/other_information/org_membership/organization_membership_bloc.dart'; -import 'package:unit2/bloc/profile/profile_bloc.dart'; -import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/model/utils/agency.dart'; import 'package:unit2/utils/text_container.dart'; - import '../../../../../model/utils/category.dart'; import '../../../../../theme-data.dart/box_shadow.dart'; import '../../../../../theme-data.dart/btn-style.dart'; @@ -17,7 +14,10 @@ import '../../../../../theme-data.dart/colors.dart'; import '../../../../../theme-data.dart/form-style.dart'; class AddOrgMemberShipScreen extends StatefulWidget { - const AddOrgMemberShipScreen({super.key}); + final int profileId; + final String token; + const AddOrgMemberShipScreen( + {super.key, required this.profileId, required this.token}); @override State createState() => _AddOrgMemberShipScreenState(); @@ -34,339 +34,290 @@ Agency? newAgency; bool showIsPrivateRadio = false; bool? isPrivate = false; final _formKey = GlobalKey(); - int? profileId; - String? token; class _AddOrgMemberShipScreenState extends State { @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (context, state) { - if (state is UserLoggedIn) { - token = state.userData!.user!.login!.token; - profileId = state.userData!.user!.login!.user!.profileId; - return BlocBuilder( - builder: (context, state) { - if (state is ProfileLoaded) { - return BlocBuilder( - builder: (context, state) { - if (state is AddOrgMembershipState) { - return SingleChildScrollView( - child: FormBuilder( - key: _formKey, - child: Padding( - padding: const EdgeInsets.symmetric( - vertical: 25, horizontal: 18), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - const SizedBox( - height: 100, - ), - StatefulBuilder( - builder: (context, setState) { - //// AGENCY SEARCHFIELD - return Column( - children: [ - SearchField( - itemHeight: 70, - suggestions: state.agencies - .map((Agency agency) => - SearchFieldListItem( - agency.name!, - item: agency, - child: ListTile( - title: Text( - agency.name! - .toUpperCase(), - overflow: - TextOverflow - .ellipsis, - ), - subtitle: Text(agency - .privateEntity == - true - ? "Private" - : agency.privateEntity == - false - ? "Government" - : ""), - ))) - .toList(), - validator: FormBuilderValidators - .required( - errorText: - "This field is required"), - focusNode: agencyFocusNode, - searchInputDecoration: - normalTextFieldStyle( - "Agency *", "") - .copyWith( - suffixIcon: - const Icon(Icons - .arrow_drop_down)), - ////agency suggestion tap - onSuggestionTap: (agency) { - setState(() { - selectedAgency = agency.item; - agencyFocusNode.unfocus(); - if (selectedAgency - ?.category == - null) { - showAgencyCategory = true; - showIsPrivateRadio = true; - } else { - showAgencyCategory = false; - showIsPrivateRadio = false; - } - }); - }, - emptyWidget: Container( - decoration: box1(), - height: 100, - child: Column( - mainAxisAlignment: - MainAxisAlignment - .center, - crossAxisAlignment: - CrossAxisAlignment - .center, - children: [ - const SizedBox( - height: 20, - ), - const Text( - "No result found..."), - const SizedBox( - height: 10, - ), - TextButton( - //// Add agency onpressed - onPressed: () { - showDialog( - context: - context, - builder: - (BuildContext - context) { - return AlertDialog( - title: const Text( - "Add Agency?"), - content: - SizedBox( - height: - 130, - child: - Column( - children: [ - TextFormField( - controller: - addAgencyController, - decoration: - normalTextFieldStyle("", ""), - ), - const SizedBox( - height: - 12, - ), - SizedBox( - width: double.infinity, - height: 50, - child: ElevatedButton( - style: mainBtnStyle(primary, Colors.transparent, second), - //// onpressed - onPressed: () { - setState(() { - newAgency = Agency(id: null, name: addAgencyController.text.toUpperCase(), category: null, privateEntity: null); - state.agencies.insert(0, newAgency!); - addAgencyController.clear(); - Navigator.pop(context); - }); - }, - child: const Text("Add"))), - ], - ), - ), - ); - }); - }, - child: const Text( - "Add position")) - ]), - ), - ), - const SizedBox( - height: 8, - ), - SizedBox( - child: showAgencyCategory - ? SearchField( - focusNode: - agencyCategoryFocusNode, - itemHeight: 70, - suggestions: state - .agencyCategories - .map((Category - category) => - SearchFieldListItem( - category - .name!, - item: - category, - child: - ListTile( - title: Text( - category - .name!), - subtitle: Text(category - .industryClass! - .name!), - ))) - .toList(), - emptyWidget: Container( - height: 100, - decoration: box1(), - child: const Center( - child: Text( - "No result found ...")), - ), - ////agency controller suggestion tap - onSuggestionTap: - (agencyCategory) { - setState(() { - selectedCategory = - agencyCategory - .item; - - agencyCategoryFocusNode - .unfocus(); - }); - }, - searchInputDecoration: - normalTextFieldStyle( - "Category *", - "") - .copyWith( - suffixIcon: - const Icon( - Icons - .arrow_drop_down)), - validator: - FormBuilderValidators - .required( - errorText: - "This field is required"), - ) - : const SizedBox(), - ), - - ////PRVIATE SECTOR - SizedBox( - child: showIsPrivateRadio - ? FormBuilderRadioGroup( - decoration: - InputDecoration( - border: - InputBorder.none, - label: Row( + if (state is AddOrgMembershipState) { + return SingleChildScrollView( + child: FormBuilder( + key: _formKey, + child: Padding( + padding: + const EdgeInsets.symmetric(vertical: 25, horizontal: 18), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox( + height: 100, + ), + StatefulBuilder(builder: (context, setState) { + //// AGENCY SEARCHFIELD + return Column( + children: [ + SearchField( + itemHeight: 70, + suggestions: state.agencies + .map((Agency agency) => + SearchFieldListItem(agency.name!, + item: agency, + child: ListTile( + title: Text( + agency.name!.toUpperCase(), + overflow: TextOverflow.ellipsis, + ), + subtitle: Text( + agency.privateEntity == true + ? "Private" + : agency.privateEntity == + false + ? "Government" + : ""), + ))) + .toList(), + validator: FormBuilderValidators.required( + errorText: "This field is required"), + focusNode: agencyFocusNode, + searchInputDecoration: normalTextFieldStyle( + "Agency *", "") + .copyWith( + suffixIcon: + const Icon(Icons.arrow_drop_down)), + ////agency suggestion tap + onSuggestionTap: (agency) { + setState(() { + selectedAgency = agency.item; + agencyFocusNode.unfocus(); + if (selectedAgency?.category == null) { + showAgencyCategory = true; + showIsPrivateRadio = true; + } else { + showAgencyCategory = false; + showIsPrivateRadio = false; + } + }); + }, + emptyWidget: Container( + decoration: box1(), + height: 100, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + const SizedBox( + height: 20, + ), + const Text("No result found..."), + const SizedBox( + height: 10, + ), + TextButton( + //// Add agency onpressed + onPressed: () { + showDialog( + context: context, + builder: + (BuildContext context) { + return AlertDialog( + title: const Text( + "Add Agency?"), + content: SizedBox( + height: 130, + child: Column( children: [ - Text( - "Is this private sector? ", - style: Theme.of( - context) - .textTheme - .headlineSmall! - .copyWith( - fontSize: - 24), + TextFormField( + controller: + addAgencyController, + decoration: + normalTextFieldStyle( + "", ""), ), - const Icon(FontAwesome - .help_circled) + const SizedBox( + height: 12, + ), + SizedBox( + width: double + .infinity, + height: 50, + child: + ElevatedButton( + style: mainBtnStyle( + primary, + Colors + .transparent, + second), + //// onpressed + onPressed: + () { + setState( + () { + newAgency = Agency( + id: null, + name: addAgencyController.text.toUpperCase(), + category: null, + privateEntity: null); + state.agencies.insert(0, + newAgency!); + addAgencyController.clear(); + Navigator.pop(context); + }); + }, + child: const Text( + "Add"))), ], ), ), - - ////onvhange private sector - onChanged: (value) { - setState(() { - if (value - .toString() == - "YES") { - isPrivate = true; - } else { - isPrivate = false; - } - }); - }, - - name: 'isPrivate', - validator: - FormBuilderValidators - .required( - errorText: - "This field is required"), - options: ["YES", "NO"] - .map((lang) => - FormBuilderFieldOption( - value: - lang)) - .toList( - growable: - false), - ) - : const SizedBox()), - ], - ); - }), - ////SHOW CATEGORY AGENCY - - const SizedBox( - height: 24, - ), - SizedBox( - height: 60, - width: double.infinity, - child: ElevatedButton( - style: mainBtnStyle(primary, - Colors.transparent, second), - onPressed: () { - if (_formKey.currentState! - .saveAndValidate()) { - if(selectedAgency?.privateEntity != null){ - newAgency = selectedAgency; - }else{ - newAgency = Agency( - id: selectedAgency?.id, - name: selectedAgency!.name, - category: - selectedCategory, - privateEntity: isPrivate); - } - - context.read().add(AddOrgMembership(agency: newAgency!, profileId: profileId!, token: token!)); - setState(() { - showAgencyCategory = false; - showIsPrivateRadio = false; + ); }); - } + }, + child: const Text("Add position")) + ]), + ), + ), + const SizedBox( + height: 8, + ), + SizedBox( + child: showAgencyCategory + ? SearchField( + focusNode: agencyCategoryFocusNode, + itemHeight: 70, + suggestions: state.agencyCategories + .map((Category category) => + SearchFieldListItem( + category.name!, + item: category, + child: ListTile( + title: + Text(category.name!), + subtitle: Text(category + .industryClass! + .name!), + ))) + .toList(), + emptyWidget: Container( + height: 100, + decoration: box1(), + child: const Center( + child: + Text("No result found ...")), + ), + ////agency controller suggestion tap + onSuggestionTap: (agencyCategory) { + setState(() { + selectedCategory = + agencyCategory.item; + + agencyCategoryFocusNode.unfocus(); + }); + }, + searchInputDecoration: + normalTextFieldStyle( + "Category *", "") + .copyWith( + suffixIcon: const Icon( + Icons.arrow_drop_down)), + validator: + FormBuilderValidators.required( + errorText: + "This field is required"), + ) + : const SizedBox(), + ), + + ////PRVIATE SECTOR + SizedBox( + child: showIsPrivateRadio + ? FormBuilderRadioGroup( + decoration: InputDecoration( + border: InputBorder.none, + label: Row( + children: [ + Text( + "Is this private sector? ", + style: Theme.of(context) + .textTheme + .headlineSmall! + .copyWith(fontSize: 24), + ), + const Icon( + FontAwesome.help_circled) + ], + ), + ), + + ////onvhange private sector + onChanged: (value) { + setState(() { + if (value.toString() == "YES") { + isPrivate = true; + } else { + isPrivate = false; + } + }); }, - child: const Text(submit)), - ) - ]), - )), - ); - } - return Container(); - }, - ); - } - return Container(); - }, + + name: 'isPrivate', + validator: + FormBuilderValidators.required( + errorText: + "This field is required"), + options: ["YES", "NO"] + .map((lang) => + FormBuilderFieldOption( + value: lang)) + .toList(growable: false), + ) + : const SizedBox()), + ], + ); + }), + ////SHOW CATEGORY AGENCY + + const SizedBox( + height: 24, + ), + SizedBox( + height: 60, + width: double.infinity, + child: ElevatedButton( + style: mainBtnStyle( + primary, Colors.transparent, second), + onPressed: () { + if (_formKey.currentState!.saveAndValidate()) { + if (selectedAgency?.privateEntity != null) { + newAgency = selectedAgency; + } else { + newAgency = Agency( + id: selectedAgency?.id, + name: selectedAgency!.name, + category: selectedCategory, + privateEntity: isPrivate); + } + + context + .read() + .add(AddOrgMembership( + agency: newAgency!, + profileId: widget.profileId, + token: widget.token)); + setState(() { + showAgencyCategory = false; + showIsPrivateRadio = false; + }); + } + }, + child: const Text(submit)), + ) + ]), + )), ); } - return const Placeholder(); + return Container(); }, ); } diff --git a/lib/screens/profile/components/other_information/org_membership_screen.dart b/lib/screens/profile/components/other_information/org_membership_screen.dart index 7ade0c0..68cdc20 100644 --- a/lib/screens/profile/components/other_information/org_membership_screen.dart +++ b/lib/screens/profile/components/other_information/org_membership_screen.dart @@ -14,6 +14,7 @@ import 'package:unit2/utils/text_container.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/Leadings/close_leading.dart'; import 'package:unit2/widgets/empty_data.dart'; +import 'package:unit2/widgets/error_state.dart'; import '../../../../bloc/profile/other_information/org_membership/organization_membership_bloc.dart'; import '../../../../utils/alerts.dart'; import '../../../../utils/global.dart'; @@ -65,6 +66,7 @@ class OrgMembershipsScreen extends StatelessWidget { final progress = ProgressHUD.of(context); progress!.dismiss(); } + ////ADDED STATE if (state is OrgMembershipAddedState) { if (state.response['success']) { @@ -73,8 +75,7 @@ class OrgMembershipsScreen extends StatelessWidget { Navigator.of(context).pop(); context.read().add( LoadOrganizationMemberships( - organizationMemberships: - state.orgMemberships)); + )); }); } else { errorAlert(context, "Adding Failed", @@ -83,8 +84,7 @@ class OrgMembershipsScreen extends StatelessWidget { Navigator.of(context).pop(); context.read().add( LoadOrganizationMemberships( - organizationMemberships: - state.orgMemberships)); + )); }); } } @@ -96,7 +96,7 @@ class OrgMembershipsScreen extends StatelessWidget { Navigator.of(context).pop(); context.read().add( LoadOrganizationMemberships( - organizationMemberships: state.organizationMemberships)); + )); }); } else { errorAlert(context, "Deletion Failed", @@ -104,7 +104,7 @@ class OrgMembershipsScreen extends StatelessWidget { Navigator.of(context).pop(); context.read().add( LoadOrganizationMemberships( - organizationMemberships: state.organizationMemberships)); + )); }); } } @@ -161,14 +161,15 @@ class OrgMembershipsScreen extends StatelessWidget { offset: const Offset(-10, -10), elevation: 3, onSelected: (value) { - final progress = - ProgressHUD.of(context); - progress! - .showWithText("Loading..."); + ////delete orgmembership-= = = = = = = = =>> if (value == 1) { confirmAlert(context, () { - context.read().add(DeleteOrgMemberShip(profileId: profileId, token: token!, org: state.orgMemberships[index], organizationMemberships: state.orgMemberships)); + final progress = + ProgressHUD.of(context); + progress! + .showWithText("Loading..."); + context.read().add(DeleteOrgMemberShip(profileId: profileId, token: token!, org: state.orgMemberships[index])); }, "Delete?", "Confirm Delete?"); } @@ -198,9 +199,13 @@ class OrgMembershipsScreen extends StatelessWidget { }); } if (state is AddOrgMembershipState) { - return const AddOrgMemberShipScreen(); + return AlertDialog( + content: AddOrgMemberShipScreen(profileId: profileId,token: token!,) + ); }if(state is OrganizationMembershipErrorState){ - return Container(child: Text(state.message),); + return SomethingWentWrong(message: state.message, onpressed: (){ + context.read().add(GetOrganizationMembership(token: token,profileId: profileId)); + }); } return Container(); }, diff --git a/lib/screens/profile/components/other_information/skills_and_hobbies_screen.dart b/lib/screens/profile/components/other_information/skills_and_hobbies_screen.dart index 727b909..53a28a7 100644 --- a/lib/screens/profile/components/other_information/skills_and_hobbies_screen.dart +++ b/lib/screens/profile/components/other_information/skills_and_hobbies_screen.dart @@ -1,6 +1,4 @@ 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:flutter_spinkit/flutter_spinkit.dart'; @@ -9,9 +7,7 @@ import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/model/profile/other_information/skills_and_hobbies.dart'; import 'package:unit2/screens/profile/components/other_information/skills_hobbies/add_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/Leadings/add_leading.dart'; import 'package:unit2/widgets/empty_data.dart'; diff --git a/lib/screens/profile/components/reference/add_modal.dart b/lib/screens/profile/components/reference/add_modal.dart index d3f73b9..6195f9c 100644 --- a/lib/screens/profile/components/reference/add_modal.dart +++ b/lib/screens/profile/components/reference/add_modal.dart @@ -4,14 +4,13 @@ import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart'; -import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/profile/references/references_bloc.dart'; -import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/model/location/address_category.dart'; import 'package:unit2/model/location/barangay.dart'; import 'package:unit2/model/profile/references.dart'; import 'package:unit2/theme-data.dart/btn-style.dart'; import 'package:unit2/theme-data.dart/form-style.dart'; +import 'package:unit2/utils/global.dart'; import '../../../../model/location/city.dart'; import '../../../../model/location/country.dart'; import '../../../../model/location/provinces.dart'; @@ -21,7 +20,10 @@ import '../../../../utils/location_utilities.dart'; import '../../../../utils/text_container.dart'; class AddReferenceScreen extends StatefulWidget { - const AddReferenceScreen({super.key}); + final int profileId; + final String token; + const AddReferenceScreen( + {super.key, required this.profileId, required this.token}); @override State createState() => _AddReferenceScreenState(); @@ -29,8 +31,6 @@ class AddReferenceScreen extends StatefulWidget { class _AddReferenceScreenState extends State { final formKey = GlobalKey(); - String? token; - String? profileId; bool provinceCall = false; bool cityCall = false; bool barangayCall = false; @@ -48,452 +48,376 @@ class _AddReferenceScreenState extends State { AddressCategory? selectedCategory; @override Widget build(BuildContext context) { - return BlocBuilder( + return BlocBuilder( builder: (context, state) { - if (state is UserLoggedIn) { - token = state.userData!.user!.login!.token; - profileId = state.userData!.user!.login!.user!.profileId.toString(); - return BlocBuilder( - builder: (context, state) { - if (state is ProfileLoaded) { - return BlocBuilder( - builder: (context, state) { - if (state is AddReferenceState) { - return ProgressHUD( - child: Padding( - padding: const EdgeInsets.symmetric( - vertical: 25, horizontal: 18), - child: FormBuilder( - key: formKey, - child: Column( - children: [ - const SizedBox(height: 25), - Row( + if (state is AddReferenceState) { + return SingleChildScrollView( + child: SizedBox( + height: screenHeight * .95, + child: ProgressHUD( + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 25, horizontal: 18), + child: FormBuilder( + key: formKey, + child: Column( + children: [ + const SizedBox(height: 25), + Row( + children: [ + ////LAST NAME + Flexible( + flex: 1, + child: FormBuilderTextField( + decoration: normalTextFieldStyle( + "Last name *", "Last name *"), + name: "lastname", + validator: FormBuilderValidators.required( + errorText: "This field is required"), + ), + ), + const SizedBox( + width: 5, + ), + ////FIRST NAME + Flexible( + flex: 1, + child: FormBuilderTextField( + decoration: normalTextFieldStyle( + "First name *", "First name *"), + name: "firstname", + validator: FormBuilderValidators.required( + errorText: "This field is required"), + ), + ), + ], + ), + const SizedBox( + height: 8, + ), + Row( + children: [ + Flexible( + flex: 1, + child: FormBuilderTextField( + decoration: normalTextFieldStyle( + "Middle name *", "Midlle name *"), + name: "middlename", + validator: FormBuilderValidators.required( + errorText: "This field is required"), + ), + ), + const SizedBox( + width: 5, + ), + ////CATEGORY + Flexible( + flex: 1, + child: FormBuilderDropdown( + name: 'category', + validator: + FormBuilderValidators.required(errorText: ""), + decoration: + normalTextFieldStyle("Category", "Category"), + items: state.categories + .map>( + (AddressCategory cat) { + return DropdownMenuItem( + value: cat, + child: Text(cat.name!), + ); + }).toList(), + onChanged: (value) { + setState(() { + selectedCategory = value; + }); + }, + ), + ), + ], + ), + const SizedBox( + height: 8, + ), + + ////OVERSEAS ADDRESS + FormBuilderSwitch( + initialValue: overseas, + activeColor: second, + onChanged: (value) { + setState(() { + overseas = value!; + }); + }, + decoration: normalTextFieldStyle("", ''), + name: 'overseas', + title: const Text("Overseas Address?"), + ), + SizedBox( + height: overseas == true ? 8 : 0, + ), + SizedBox( + child: overseas == false + ? Column( children: [ - ////LAST NAME - Flexible( - flex: 1, - child: FormBuilderTextField( - decoration: normalTextFieldStyle( - "Last name *", "Last name *"), - name: "lastname", - validator: - FormBuilderValidators.required( - errorText: - "This field is required"), - ), + const SizedBox( + height: 12, + ), + ////REGION DROPDOWN + FormBuilderDropdown( + autovalidateMode: + AutovalidateMode.onUserInteraction, + validator: FormBuilderValidators.required( + errorText: "This field is required"), + onChanged: (Region? region) async { + if(selectedRegion != region){ + setState(() { + provinceCall = true; + }); + selectedRegion = region; + getProvinces(); + } + }, + initialValue: null, + decoration: normalTextFieldStyle( + "Region*", "Region"), + name: 'region', + items: state.regions + .map>( + (Region region) { + return DropdownMenuItem( + value: region, + child: Text(region.description!)); + }).toList(), ), const SizedBox( - width: 5, + height: 8, ), - ////FIRST NAME - Flexible( - flex: 1, - child: FormBuilderTextField( - decoration: normalTextFieldStyle( - "First name *", "First name *"), - name: "firstname", - validator: - FormBuilderValidators.required( - errorText: - "This field is required"), - ), - ), - ], - ), - const SizedBox( - height: 8, - ), - Row( - children: [ - Flexible( - flex: 1, - child: FormBuilderTextField( - decoration: normalTextFieldStyle( - "Middle name *", "Midlle name *"), - name: "middlename", - validator: - FormBuilderValidators.required( - errorText: - "This field is required"), - ), - ), - const SizedBox( - width: 5, - ), - ////CATEGORY - Flexible( - flex: 1, - child: FormBuilderDropdown< - AddressCategory>( - name: 'category', - validator: - FormBuilderValidators.required( - errorText: ""), - decoration: normalTextFieldStyle( - "Category", "Category"), - items: state.categories.map< - DropdownMenuItem< - AddressCategory>>( - (AddressCategory cat) { - return DropdownMenuItem< - AddressCategory>( - value: cat, - child: Text(cat.name!), - ); - }).toList(), - onChanged: (value) { - setState(() { - selectedCategory = value; - }); - }, - ), - ), - ], - ), - const SizedBox( - height: 8, - ), - - ////OVERSEAS ADDRESS - FormBuilderSwitch( - initialValue: overseas, - activeColor: second, - onChanged: (value) { - setState(() { - overseas = value!; - }); - }, - decoration: normalTextFieldStyle("", ''), - name: 'overseas', - title: const Text("Overseas Address?"), - ), - SizedBox( - height: overseas == true ? 8 : 0, - ), - SizedBox( - child: overseas == false - ? Column( - children: [ - const SizedBox( - height: 12, - ), - ////REGION DROPDOWN - FormBuilderDropdown( - autovalidateMode: - AutovalidateMode - .onUserInteraction, - validator: FormBuilderValidators - .required( - errorText: - "This field is required"), - onChanged: - (Region? region) async { + //// PROVINCE DROPDOWN + SizedBox( + height: 60, + child: ModalProgressHUD( + color: Colors.transparent, + inAsyncCall: provinceCall, + child: DropdownButtonFormField( + autovalidateMode: AutovalidateMode + .onUserInteraction, + validator: (value) => + value == null ? 'required' : null, + isExpanded: true, + value: selectedProvince, + onChanged: (Province? province) { + if(selectedProvince != province){ setState(() { - provinceCall = true; - }); - selectedRegion = region; - getProvinces(); - }, - initialValue: null, - 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: 8, - ), - //// PROVINCE DROPDOWN - SizedBox( - height: 60, - child: ModalProgressHUD( - color: Colors.transparent, - inAsyncCall: provinceCall, - child: DropdownButtonFormField< - Province?>( - autovalidateMode: - AutovalidateMode - .onUserInteraction, - validator: (value) => - value == null - ? 'required' - : null, - isExpanded: true, - value: selectedProvince, - onChanged: - (Province? province) { - setState(() { - cityCall = true; - }); - selectedProvince = - province; - getCities(); - }, - items: provinces == null - ? [] - : provinces!.map< - DropdownMenuItem< - Province>>( - (Province - province) { - return DropdownMenuItem( - value: - province, - child: - FittedBox( - child: Text( - province - .description!), - )); - }).toList(), - decoration: - normalTextFieldStyle( - "Province*", - "Province")), - ), - ), - ////CITY MUNICIPALITY - SizedBox( - height: 60, - child: ModalProgressHUD( - color: Colors.white, - inAsyncCall: cityCall, - child: - DropdownButtonFormField< - CityMunicipality>( - validator: FormBuilderValidators - .required( - errorText: - "This field is required"), - isExpanded: true, - onChanged: - (CityMunicipality? - city) { - setState(() { - barangayCall = true; - }); - selectedMunicipality = - city; - getBarangays(); - }, - decoration: - normalTextFieldStyle( - "Municipality*", - "Municipality"), - value: selectedMunicipality, - items: citymuns == null - ? [] - : citymuns!.map< - DropdownMenuItem< - CityMunicipality>>( - (CityMunicipality - c) { - return DropdownMenuItem( - value: c, - child: Text(c - .description!)); - }).toList(), - ), - ), - ), - //// BARANGAY - SizedBox( - height: 60, - child: ModalProgressHUD( - color: Colors.white, - inAsyncCall: barangayCall, - child: - DropdownButtonFormField< - Barangay>( - validator: FormBuilderValidators - .required( - errorText: - "This field is required"), - isExpanded: true, - onChanged: - (Barangay? baragay) { - selectedBarangay = - baragay; - }, - decoration: - normalTextFieldStyle( - "Barangay*", - "Barangay"), - value: selectedBarangay, - items: barangays == null - ? [] - : barangays!.map< - DropdownMenuItem< - Barangay>>( - (Barangay - barangay) { - return DropdownMenuItem( - value: barangay, - child: Text(barangay - .description!)); - }).toList(), - ), - ), - ), - ], - ) - //// COUNTRY DROPDOWN - : SizedBox( - height: 60, - child: FormBuilderDropdown( - initialValue: null, - validator: FormBuilderValidators - .required( - errorText: - "This field is required"), - 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; + cityCall = true; + }); + selectedProvince = province; + getCities(); + } }, - ), + items: provinces == null + ? [] + : provinces!.map< + DropdownMenuItem< + Province>>( + (Province province) { + return DropdownMenuItem( + value: province, + child: FittedBox( + child: Text(province + .description!), + )); + }).toList(), + decoration: normalTextFieldStyle( + "Province*", "Province")), + ), + ), + ////CITY MUNICIPALITY + SizedBox( + height: 60, + child: ModalProgressHUD( + color: Colors.white, + inAsyncCall: cityCall, + child: DropdownButtonFormField< + CityMunicipality>( + validator: + FormBuilderValidators.required( + errorText: + "This field is required"), + isExpanded: true, + onChanged: (CityMunicipality? city) { + if(selectedMunicipality != city){ + setState(() { + barangayCall = true; + }); + selectedMunicipality = city; + getBarangays(); + } + }, + decoration: normalTextFieldStyle( + "Municipality*", "Municipality"), + value: selectedMunicipality, + items: citymuns == null + ? [] + : citymuns!.map< + DropdownMenuItem< + CityMunicipality>>( + (CityMunicipality c) { + return DropdownMenuItem( + value: c, + child: + Text(c.description!)); + }).toList(), ), - ), - - FormBuilderTextField( - name: "mobile", - decoration: normalTextFieldStyle( - "Tel./Mobile *", "Tel./Mobile"), - validator: FormBuilderValidators.required( - errorText: "This field is required"), - ), - const Expanded( - child: SizedBox(), - ), - SizedBox( - width: double.infinity, + ), + ), + //// BARANGAY + SizedBox( + height: 60, + child: ModalProgressHUD( + color: Colors.white, + inAsyncCall: barangayCall, + child: DropdownButtonFormField( + + isExpanded: true, + onChanged: (Barangay? baragay) { + selectedBarangay = baragay; + }, + decoration: normalTextFieldStyle( + "Barangay*", "Barangay"), + value: selectedBarangay, + items: barangays == null + ? [] + : barangays!.map< + DropdownMenuItem>( + (Barangay barangay) { + return DropdownMenuItem( + value: barangay, + child: Text( + barangay.description!)); + }).toList(), + ), + ), + ), + ], + ) + //// COUNTRY DROPDOWN + : SizedBox( height: 60, - child: ElevatedButton( - style: mainBtnStyle( - primary, Colors.transparent, second), - child: const Text(submit), - onPressed: () { - - PersonalReference? personalReference; - if (formKey.currentState! - .saveAndValidate()) { - String lastname = formKey - .currentState!.value['lastname']; - String firstname = formKey - .currentState!.value['firstname']; - String middlename = formKey - .currentState! - .value['middlename']; - String mobile = formKey - .currentState!.value['mobile']; - - - Region? region = selectedRegion; - Province? province = Province( - code: selectedProvince?.code, - description: - selectedProvince?.description, - region: region, - psgcCode: - selectedProvince?.psgcCode, - shortname: - selectedProvince?.shortname); - CityMunicipality? city = - CityMunicipality( - code: selectedMunicipality - ?.code, - description: - selectedMunicipality - ?.description, - province: province, - psgcCode: selectedMunicipality - ?.psgcCode, - zipcode: selectedMunicipality - ?.zipcode); - - Address address = Address( - id: null, - addressCategory: selectedCategory, - country: selectedCountry, - barangay: selectedBarangay, - addressClass: null, - cityMunicipality: city); - - if (selectedCountry != null) { - personalReference = - PersonalReference( - id: null, - address: Address( - id: null, - addressCategory: - selectedCategory, - country: selectedCountry, - barangay: null, - cityMunicipality: null, - addressClass: null), - lastName: lastname, - contactNo: mobile, - firstName: firstname, - middleName: middlename); - } else { - personalReference = - PersonalReference( - id: null, - address: address, - lastName: lastname, - contactNo: mobile, - firstName: firstname, - middleName: middlename); - } -final progress = ProgressHUD.of(context); -progress!.showWithText("Please wait..."); - context.read().add( - AddReference( - profileId: - int.parse(profileId!), - reference: personalReference, - token: token!)); - } + child: FormBuilderDropdown( + initialValue: null, + validator: FormBuilderValidators.required( + errorText: "This field is required"), + items: state.countries + .map>( + (Country country) { + return DropdownMenuItem( + value: country, + child: FittedBox( + child: Text(country.name!))); + }).toList(), + name: 'country', + decoration: normalTextFieldStyle( + "Country*", "Country"), + onChanged: (Country? value) { + selectedCountry = value; }, ), ), - const SizedBox( - height: 20, - ), - ], - )), - ), - ); - } - return Container(); - }, - ); - } - return Container(); - }, + ), + + FormBuilderTextField( + name: "mobile", + decoration: normalTextFieldStyle( + "Tel./Mobile *", "Tel./Mobile"), + validator: FormBuilderValidators.required( + errorText: "This field is required"), + ), + const Expanded( + child: SizedBox(), + ), + SizedBox( + width: double.infinity, + height: 60, + child: ElevatedButton( + style: + mainBtnStyle(primary, Colors.transparent, second), + child: const Text(submit), + onPressed: () { + PersonalReference? personalReference; + if (formKey.currentState!.saveAndValidate()) { + String lastname = + formKey.currentState!.value['lastname']; + String firstname = + formKey.currentState!.value['firstname']; + String middlename = + formKey.currentState!.value['middlename']; + String mobile = + formKey.currentState!.value['mobile']; + + Region? region = selectedRegion; + Province? province = Province( + code: selectedProvince?.code, + description: selectedProvince?.description, + region: region, + psgcCode: selectedProvince?.psgcCode, + shortname: selectedProvince?.shortname); + CityMunicipality? city = CityMunicipality( + code: selectedMunicipality?.code, + description: + selectedMunicipality?.description, + province: province, + psgcCode: selectedMunicipality?.psgcCode, + zipcode: selectedMunicipality?.zipcode); + + Address address = Address( + id: null, + addressCategory: selectedCategory, + country: selectedCountry, + barangay: selectedBarangay, + addressClass: null, + cityMunicipality: city); + + if (selectedCountry != null) { + personalReference = PersonalReference( + id: null, + address: Address( + id: null, + addressCategory: selectedCategory, + country: selectedCountry, + barangay: null, + cityMunicipality: null, + addressClass: null), + lastName: lastname, + contactNo: mobile, + firstName: firstname, + middleName: middlename); + } else { + personalReference = PersonalReference( + id: null, + address: address, + lastName: lastname, + contactNo: mobile, + firstName: firstname, + middleName: middlename); + } + final progress = ProgressHUD.of(context); + progress!.showWithText("Please wait..."); + context.read().add(AddReference( + profileId: widget.profileId, + reference: personalReference, + token: widget.token)); + } + }, + ), + ), + const SizedBox( + height: 20, + ), + ], + )), + ), + ), + ), ); } return Container(); diff --git a/lib/screens/profile/components/reference/edit_modal.dart b/lib/screens/profile/components/reference/edit_modal.dart index 6c02990..136081e 100644 --- a/lib/screens/profile/components/reference/edit_modal.dart +++ b/lib/screens/profile/components/reference/edit_modal.dart @@ -4,9 +4,7 @@ import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.dart'; -import '../../../../bloc/profile/profile_bloc.dart'; import '../../../../bloc/profile/references/references_bloc.dart'; -import '../../../../bloc/user/user_bloc.dart'; import '../../../../model/location/address_category.dart'; import '../../../../model/location/barangay.dart'; import '../../../../model/location/city.dart'; @@ -21,7 +19,9 @@ import '../../../../utils/location_utilities.dart'; import '../../../../utils/text_container.dart'; class EditReferenceScreen extends StatefulWidget { - const EditReferenceScreen({super.key}); + final String token; + final int profileId; + const EditReferenceScreen({super.key,required this.profileId, required this.token}); @override State createState() => _EditReferenceScreenState(); @@ -29,8 +29,6 @@ class EditReferenceScreen extends StatefulWidget { class _EditReferenceScreenState extends State { final formKey = GlobalKey(); - String? token; - String? profileId; bool provinceCall = false; bool cityCall = false; bool barangayCall = false; @@ -48,14 +46,7 @@ class _EditReferenceScreenState extends State { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - if (state is UserLoggedIn) { - token = state.userData!.user!.login!.token; - profileId = state.userData!.user!.login!.user!.profileId.toString(); - return BlocBuilder( - builder: (context, state) { - if (state is ProfileLoaded) { + return BlocBuilder( buildWhen: (previous, current) => false, builder: (context, state) { @@ -525,6 +516,10 @@ class _EditReferenceScreenState extends State { PersonalReference? personalReference; if (formKey.currentState! .saveAndValidate()) { + final progress = + ProgressHUD.of(context); + progress!.showWithText( + "Please wait..."); String lastname = formKey .currentState!.value['lastname']; String firstname = formKey @@ -607,9 +602,9 @@ class _EditReferenceScreenState extends State { context.read().add( EditReference( profileId: - int.parse(profileId!), + widget.profileId, reference: personalReference, - token: token!)); + token: widget.token)); } }, ), @@ -624,14 +619,7 @@ class _EditReferenceScreenState extends State { } return Container(); }, - ); - } - return Container(); - }, - ); - } - return Container(); - }, + ); } } diff --git a/lib/screens/profile/components/references_screen.dart b/lib/screens/profile/components/references_screen.dart index 9282301..f684f6c 100644 --- a/lib/screens/profile/components/references_screen.dart +++ b/lib/screens/profile/components/references_screen.dart @@ -26,25 +26,37 @@ class ReferencesScreen extends StatelessWidget { int? profileId; String? token; return Scaffold( + resizeToAvoidBottomInset: true, appBar: AppBar( - title: context.watch().state is AddReferenceState?const Text("Add Personal Reference"):context.watch().state is EditReferenceState?const Text("Edit Personal Reference"):const Text("Personal References"), - centerTitle: true, - backgroundColor: primary, - ////if state is adding or editing state show close button - actions: (context.watch().state is AddReferenceState || context.watch().state is EditReferenceState)? - [ - //// close button - CloseLeading(onPressed: (){ - context.read().add(GetReferences(profileId: profileId!, token: token!)); - }), - ]: - //// if state is loaded state show add button - context.watch().state is ReferencesLoadedState?[ - AddLeading(onPressed: (){ - context.read().add(ShowAddReferenceForm()); - }), - ]:[] - ), + title: context.watch().state is AddReferenceState + ? const Text("Add Personal Reference") + : context.watch().state is EditReferenceState + ? const Text("Edit Personal Reference") + : const Text("Personal References"), + centerTitle: true, + backgroundColor: primary, + ////if state is adding or editing state show close button + actions: (context.watch().state + is AddReferenceState || + context.watch().state is EditReferenceState) + ? [ + //// close button + CloseLeading(onPressed: () { + context.read().add( + GetReferences(profileId: profileId!, token: token!)); + }), + ] + : + //// if state is loaded state show add button + context.watch().state is ReferencesLoadedState + ? [ + AddLeading(onPressed: () { + context + .read() + .add(ShowAddReferenceForm()); + }), + ] + : []), body: ProgressHUD( padding: const EdgeInsets.all(24), backgroundColor: Colors.black87, @@ -83,7 +95,7 @@ class ReferencesScreen extends StatelessWidget { Navigator.of(context).pop(); context.read().add( LoadReferences( - references: state.personalRefs)); + )); }); } else { errorAlert(context, "Adding Failed", @@ -92,7 +104,7 @@ class ReferencesScreen extends StatelessWidget { Navigator.of(context).pop(); context.read().add( LoadReferences( - references: state.personalRefs)); + )); }); } } @@ -104,7 +116,7 @@ class ReferencesScreen extends StatelessWidget { Navigator.of(context).pop(); context.read().add( LoadReferences( - references: state.personalRefs)); + )); }); } else { errorAlert(context, "Update Failed", @@ -113,7 +125,7 @@ class ReferencesScreen extends StatelessWidget { Navigator.of(context).pop(); context.read().add( LoadReferences( - references: state.personalRefs)); + )); }); } } @@ -127,7 +139,7 @@ class ReferencesScreen extends StatelessWidget { Navigator.of(context).pop(); context.read().add( LoadReferences( - references: state.references)); +)); }); } else { errorAlert(context, "Deletion Failed", @@ -135,7 +147,7 @@ class ReferencesScreen extends StatelessWidget { Navigator.of(context).pop(); context.read().add( LoadReferences( - references: state.references)); + )); }); } } @@ -212,12 +224,14 @@ class ReferencesScreen extends StatelessWidget { offset: const Offset(-10, -10), elevation: 3, onSelected: (value) { - ////delete eligibilty-= = = = = = = = =>> if (value == 2) { - final progress = ProgressHUD.of(context); -progress!.showWithText("Please wait..."); + confirmAlert(context, () { + final progress = + ProgressHUD.of(context); + progress!.showWithText( + "Please wait..."); context .read< ReferencesBloc>() @@ -236,6 +250,10 @@ progress!.showWithText("Please wait..."); } if (value == 1) { ////edit reference-= = = = = = = = =>> + final progress = + ProgressHUD.of(context); + progress!.showWithText( + "Please wait..."); context .read() .add(ShowEditReferenceForm( @@ -276,14 +294,16 @@ progress!.showWithText("Please wait..."); } } if (state is AddReferenceState) { - return const AddReferenceScreen(); + return AddReferenceScreen(profileId: profileId!, token: token!,); } if (state is EditReferenceState) { - return const EditReferenceScreen(); + return EditReferenceScreen(profileId: profileId!,token: token!,); } if (state is ReferencesErrorState) { return SomethingWentWrong( - message: state.message, onpressed: () {}); + message: state.message, onpressed: () { + context.read().add(GetReferences(profileId: profileId!, token: token!)); + }); } return Container(); }, diff --git a/lib/screens/profile/components/work_history/add_modal.dart b/lib/screens/profile/components/work_history/add_modal.dart index 3a9be0b..3ba5b84 100644 --- a/lib/screens/profile/components/work_history/add_modal.dart +++ b/lib/screens/profile/components/work_history/add_modal.dart @@ -24,7 +24,9 @@ import 'package:unit2/utils/validators.dart'; import '../../../../model/utils/position.dart'; class AddWorkHistoryScreen extends StatefulWidget { - const AddWorkHistoryScreen({super.key}); + final int profileId; + final String token; + const AddWorkHistoryScreen({super.key, required this.profileId, required this.token}); @override State createState() => _AddWorkHistoryScreenState(); @@ -65,14 +67,7 @@ class _AddWorkHistoryScreenState extends State { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - if (state is UserLoggedIn) { - profileId = state.userData!.user!.login!.user!.profileId; - token = state.userData!.user!.login!.token; - return BlocBuilder( - builder: (context, state) { - if (state is ProfileLoaded) { + return BlocConsumer( listener: (context, state) { if (state is AddWorkHistoryState) { @@ -121,6 +116,7 @@ class _AddWorkHistoryScreenState extends State { positionFocusNode.unfocus(); }); }, + ////EMPTY WIDGET emptyWidget: Container( decoration: box1(), height: 100, @@ -139,6 +135,7 @@ class _AddWorkHistoryScreenState extends State { ), TextButton( onPressed: () { + ////ADD POSITION DIALOG showDialog( context: context, builder: (BuildContext @@ -638,12 +635,7 @@ class _AddWorkHistoryScreenState extends State { Flexible( flex: 1, child: DateTimePicker( - validator: (value) { - if (value == null) { - return "This field is required"; - } - return null; - }, + validator: FormBuilderValidators.required(errorText: "This field is required"), use24HourFormat: false, icon: const Icon( Icons.date_range), @@ -684,9 +676,7 @@ class _AddWorkHistoryScreenState extends State { .copyWith(), ) : DateTimePicker( - validator: (val) { - return null; - }, + validator: FormBuilderValidators.required(errorText: "This field is required"), controller: toDateController, firstDate: DateTime(1970), @@ -723,17 +713,12 @@ class _AddWorkHistoryScreenState extends State { style: mainBtnStyle( primary, Colors.transparent, second), onPressed: () { - print(selectedPosition?.title); - print(selectedStatus?.label); - print(selectedAgency?.name); - print(salary); - print(fromDateController.text); - print(toDateController.text); - - print(salaryGrade); - print(salaryGradeStep); - print(isPrivate); + if (_formKey.currentState!.validate()) { + final progress = + ProgressHUD.of(context); + progress!.showWithText( + "Loading..."); WorkHistory workHistory = WorkHistory( position: selectedPosition, id: null, @@ -780,17 +765,7 @@ class _AddWorkHistoryScreenState extends State { ), ); } - return Container(); - }); - } - return Container(); - }, - ); - } - return const Center( - child: Text("Add Work History"), - ); - }, - ); + return Container(); + }); } } diff --git a/lib/screens/profile/components/work_history/edit_modal.dart b/lib/screens/profile/components/work_history/edit_modal.dart index 975bfcd..bff0072 100644 --- a/lib/screens/profile/components/work_history/edit_modal.dart +++ b/lib/screens/profile/components/work_history/edit_modal.dart @@ -23,7 +23,10 @@ import '../../../../utils/text_container.dart'; import '../../../../utils/validators.dart'; class EditWorkHistoryScreen extends StatefulWidget { - const EditWorkHistoryScreen({super.key}); + final int profileId; + final String token; + const EditWorkHistoryScreen( + {super.key, required this.profileId, required this.token}); @override State createState() => _EditWorkHistoryScreenState(); @@ -73,756 +76,695 @@ class _EditWorkHistoryScreenState extends State { @override Widget build(BuildContext context) { - return BlocBuilder( - builder: (context, state) { - if (state is UserLoggedIn) { - profileId = state.userData!.user!.login!.user!.profileId; - token = state.userData!.user!.login!.token; - return BlocBuilder( - builder: (context, state) { - if (state is ProfileLoaded) { - return BlocConsumer( - listener: (context, state) { - if (state is AddWorkHistoryState) { - final progress = ProgressHUD.of(context); - progress!.dismiss(); - } - }, builder: (context, state) { - if (state is EditWorkHistoryState) { - oldPositionController.text = - state.workHistory.position!.title!; - oldAppointmentStatusController.text = - state.workHistory.appointmentStatus!; - oldAgencyController.text = state.workHistory.agency!.name!; - currentlyEmployed = - state.workHistory.toDate == null ? true : false; - showSalaryGradeAndSalaryStep = - !state.workHistory.agency!.privateEntity!; - fromDateController.text = - state.workHistory.fromDate.toString(); - toDateController.text = state.workHistory.toDate.toString(); - currentlyEmployed = - state.workHistory.toDate == null ? true : false; + return BlocBuilder(builder: (context, state) { + return BlocBuilder( + builder: (context, state) { + if (state is EditWorkHistoryState) { + oldPositionController.text = state.workHistory.position!.title!; + oldAppointmentStatusController.text = + state.workHistory.appointmentStatus!; + oldAgencyController.text = state.workHistory.agency!.name!; + currentlyEmployed = state.workHistory.toDate == null ? true : false; + showSalaryGradeAndSalaryStep = + !state.workHistory.agency!.privateEntity!; + fromDateController.text = state.workHistory.fromDate.toString(); + toDateController.text = state.workHistory.toDate.toString(); + currentlyEmployed = state.workHistory.toDate == null ? true : false; - return SingleChildScrollView( - child: SizedBox( - height: blockSizeVertical * 90, - child: FormBuilder( - key: _formKey, - child: Padding( - padding: const EdgeInsets.symmetric( - vertical: 25, horizontal: 18), - child: Column( - children: [ - ////POSITIONS - StatefulBuilder(builder: (context, setState) { - return SearchField( - controller: oldPositionController, - itemHeight: 50, - suggestionsDecoration: box1(), - suggestions: state.agencyPositions - .map((Position position) => - SearchFieldListItem(position.title!, - item: position, - child: Padding( - padding: const EdgeInsets - .symmetric( - horizontal: 10), - child: ListTile( - title: - Text(position.title!), - )))) - .toList(), - focusNode: positionFocusNode, - searchInputDecoration: - normalTextFieldStyle("Position *", "") - .copyWith( - suffixIcon: const Icon( - Icons.arrow_drop_down)), - onSuggestionTap: (position) { - setState(() { - selectedPosition = position.item; - positionFocusNode.unfocus(); - }); - }, - emptyWidget: Container( - decoration: box1(), - height: 100, - child: Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, - children: [ - const SizedBox( - height: 20, - ), - const Text("No result found..."), - const SizedBox( - height: 10, - ), - TextButton( - onPressed: () { - showDialog( - context: context, - builder: (BuildContext - context) { - return AlertDialog( - title: const Text( - "Add Position?"), - content: SizedBox( - height: 130, - child: Column( - children: [ - TextFormField( - controller: - addPositionController, - decoration: - normalTextFieldStyle( - "", - ""), - ), - const SizedBox( - height: 12, - ), - SizedBox( - width: double - .infinity, - height: 50, - child: ElevatedButton( - style: mainBtnStyle(primary, Colors.transparent, second), - onPressed: () { + return SingleChildScrollView( + child: SizedBox( + height: blockSizeVertical * 90, + child: FormBuilder( + key: _formKey, + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 25, horizontal: 18), + child: Column( + children: [ + ////POSITIONS + StatefulBuilder(builder: (context, setState) { + return SearchField( + controller: oldPositionController, + itemHeight: 50, + suggestionsDecoration: box1(), + suggestions: state.agencyPositions + .map((Position position) => SearchFieldListItem( + position.title!, + item: position, + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 10), + child: ListTile( + title: Text(position.title!), + )))) + .toList(), + focusNode: positionFocusNode, + searchInputDecoration: + normalTextFieldStyle("Position *", "").copyWith( + suffixIcon: + const Icon(Icons.arrow_drop_down)), + onSuggestionTap: (position) { + setState(() { + selectedPosition = position.item; + positionFocusNode.unfocus(); + }); + }, + emptyWidget: Container( + decoration: box1(), + height: 100, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + const SizedBox( + height: 20, + ), + const Text("No result found..."), + const SizedBox( + height: 10, + ), + TextButton( + onPressed: () { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text( + "Add Position?"), + content: SizedBox( + height: 130, + child: Column( + children: [ + TextFormField( + controller: + addPositionController, + decoration: + normalTextFieldStyle( + "", ""), + ), + const SizedBox( + height: 12, + ), + SizedBox( + width: + double.infinity, + height: 50, + child: + ElevatedButton( + style: mainBtnStyle( + primary, + Colors + .transparent, + second), + onPressed: + () { + setState( + () { + Position + newAgencyPosition = + Position( + id: null, + title: addPositionController.text.toUpperCase()); + state.agencyPositions.insert( + 0, + newAgencyPosition); + selectedPosition = + newAgencyPosition; + addPositionController.text = + ""; + Navigator.pop( + context); + }); + }, + child: const Text( + "Add"))), + ], + ), + ), + ); + }); + }, + child: const Text("Add position")) + ]), + ), + validator: (position) { + if (position!.isEmpty) { + return "This field is required"; + } + return null; + }, + ); + }), + const SizedBox( + height: 12, + ), + ////APPOINTMENT STATUS' + SearchField( + controller: oldAppointmentStatusController, + suggestions: state.appointmentStatus + .map((AppoinemtStatus status) => + SearchFieldListItem(status.label, + item: status)) + .toList(), + focusNode: appointmentStatusNode, + validator: (value) { + if (value!.isEmpty) { + return "This field is required"; + } + return null; + }, + onSuggestionTap: (status) { + selectedStatus = status.item; + appointmentStatusNode.unfocus(); + }, + searchInputDecoration: + normalTextFieldStyle("Appointment Status", "") + .copyWith( + suffixIcon: + const Icon(Icons.arrow_drop_down)), + ), + + const SizedBox( + height: 12, + ), + + ////AGENCY + StatefulBuilder(builder: (context, setState) { + return Column( + children: [ + SearchField( + controller: oldAgencyController, + itemHeight: 70, + focusNode: agencyFocusNode, + suggestions: state.agencies + .map((Agency agency) => + SearchFieldListItem(agency.name!, + item: agency, + child: ListTile( + title: Text( + agency.name!, + overflow: TextOverflow.ellipsis, + ), + subtitle: Text( + agency.privateEntity == true + ? "Private" + : "Government"), + ))) + .toList(), + searchInputDecoration: normalTextFieldStyle( + "Agency *", "") + .copyWith( + suffixIcon: + const Icon(Icons.arrow_drop_down)), + onSuggestionTap: (agency) { + setState(() { + selectedAgency = agency.item; + if (selectedAgency!.privateEntity == null) { + showIsPrivateRadio = true; + } else { + showIsPrivateRadio = false; + } + if (selectedAgency!.privateEntity == true) { + showSalaryGradeAndSalaryStep = false; + } + if (selectedAgency!.privateEntity == + false) { + showSalaryGradeAndSalaryStep = true; + } + agencyFocusNode.unfocus(); + }); + }, + validator: (agency) { + if (agency!.isEmpty) { + return "This field is required"; + } + return null; + }, + emptyWidget: Container( + decoration: box1(), + height: 100, + child: Column( + mainAxisAlignment: + MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + const SizedBox( + height: 20, + ), + const Text("No result found"), + const SizedBox( + height: 10, + ), + TextButton( + onPressed: () { + showDialog( + context: context, + builder: + (BuildContext context) { + return AlertDialog( + title: const Text( + "Add Position"), + content: SizedBox( + height: 130, + child: Column( + children: [ + TextFormField( + controller: + addAgencyController, + decoration: + normalTextFieldStyle( + "", ""), + ), + const SizedBox( + height: 12, + ), + SizedBox( + width: double + .infinity, + height: 50, + child: + ElevatedButton( + style: mainBtnStyle( + primary, + Colors + .transparent, + second), + onPressed: + () { setState( () { - Position - newAgencyPosition = - Position(id: null, title: addPositionController.text.toUpperCase()); - state.agencyPositions.insert(0, - newAgencyPosition); - selectedPosition = - newAgencyPosition; - addPositionController.text = + Agency newAgency = Agency( + id: null, + name: addAgencyController.text.toUpperCase(), + category: null, + privateEntity: null); + state.agencies.insert(0, + newAgency); + selectedAgency = + newAgency; + addAgencyController.text = ""; + showAgencyCategory = + true; + + showIsPrivateRadio = + true; + Navigator.pop(context); }); }, - child: const Text("Add"))), - ], - ), - ), - ); - }); - }, - child: - const Text("Add position")) - ]), - ), - validator: (position) { - if (position!.isEmpty) { - return "This field is required"; - } - return null; - }, - ); - }), - const SizedBox( - height: 12, - ), - ////APPOINTMENT STATUS' - SearchField( - controller: oldAppointmentStatusController, - suggestions: state.appointmentStatus - .map((AppoinemtStatus status) => - SearchFieldListItem(status.label, - item: status)) - .toList(), - focusNode: appointmentStatusNode, - validator: (value) { - if (value!.isEmpty) { - return "This field is required"; - } - return null; - }, - onSuggestionTap: (status) { - selectedStatus = status.item; - appointmentStatusNode.unfocus(); - }, - searchInputDecoration: normalTextFieldStyle( - "Appointment Status", "") - .copyWith( - suffixIcon: const Icon( - Icons.arrow_drop_down)), - ), - - const SizedBox( - height: 12, - ), - - ////AGENCY - StatefulBuilder(builder: (context, setState) { - return Column( - children: [ - SearchField( - controller: oldAgencyController, - itemHeight: 70, - focusNode: agencyFocusNode, - suggestions: state.agencies - .map((Agency agency) => - SearchFieldListItem( - agency.name!, - item: agency, - child: ListTile( - title: Text( - agency.name!, - overflow: TextOverflow - .ellipsis, + child: const Text( + "Add"))), + ], + ), ), - subtitle: Text( - agency.privateEntity == - true - ? "Private" - : "Government"), + ); + }); + }, + child: const Text("Add Agency")) + ]), + ), + ), + + SizedBox( + height: showAgencyCategory ? 12 : 0, + ), + ////SHOW AGENCY CATEGORY + SizedBox( + child: showAgencyCategory + ? SearchField( + focusNode: agencyCategoryFocusNode, + itemHeight: 70, + suggestions: state.agencyCategory + .map((Category category) => + SearchFieldListItem( + category.name!, + item: category, + child: ListTile( + title: + Text(category.name!), + subtitle: Text(category + .industryClass! + .name!), ))) .toList(), + emptyWidget: Container( + height: 100, + decoration: box1(), + child: const Center( + child: + Text("No result found ...")), + ), + onSuggestionTap: (agencyCategory) { + setState(() { + selectedAgencyCategory = + agencyCategory.item; + agencyCategoryFocusNode.unfocus(); + selectedAgency = Agency( + id: null, + name: selectedAgency!.name, + category: + selectedAgencyCategory, + privateEntity: null); + }); + }, searchInputDecoration: - normalTextFieldStyle("Agency *", "") + normalTextFieldStyle( + "Category *", "") .copyWith( suffixIcon: const Icon( Icons.arrow_drop_down)), - onSuggestionTap: (agency) { - setState(() { - selectedAgency = agency.item; - if (selectedAgency!.privateEntity == - null) { - showIsPrivateRadio = true; - } else { - showIsPrivateRadio = false; - } - if (selectedAgency!.privateEntity == - true) { - showSalaryGradeAndSalaryStep = - false; - } - if (selectedAgency!.privateEntity == - false) { - showSalaryGradeAndSalaryStep = - true; - } - agencyFocusNode.unfocus(); - }); - }, - validator: (agency) { - if (agency!.isEmpty) { + validator: (value) { + if (value!.isEmpty) { return "This field is required"; } return null; }, - emptyWidget: Container( - decoration: box1(), - height: 100, - child: Column( - mainAxisAlignment: - MainAxisAlignment.center, - crossAxisAlignment: - CrossAxisAlignment.center, + ) + : const SizedBox(), + ), + + ////PRVIATE SECTOR + SizedBox( + child: showIsPrivateRadio + ? FormBuilderRadioGroup( + decoration: InputDecoration( + border: InputBorder.none, + label: Row( children: [ - const SizedBox( - height: 20, + Text( + "Is this private sector? ", + style: Theme.of(context) + .textTheme + .headlineSmall! + .copyWith(fontSize: 24), ), - const Text("No result found"), - const SizedBox( - height: 10, - ), - TextButton( - onPressed: () { - showDialog( - context: context, - builder: (BuildContext - context) { - return AlertDialog( - title: const Text( - "Add Position"), - content: SizedBox( - height: 130, - child: Column( - children: [ - TextFormField( - controller: - addAgencyController, - decoration: - normalTextFieldStyle( - "", - ""), - ), - const SizedBox( - height: - 12, - ), - SizedBox( - width: double - .infinity, - height: - 50, - child: ElevatedButton( - style: mainBtnStyle(primary, Colors.transparent, second), - onPressed: () { - setState(() { - Agency newAgency = Agency(id: null, name: addAgencyController.text.toUpperCase(), category: null, privateEntity: null); - state.agencies.insert(0, newAgency); - selectedAgency = newAgency; - addAgencyController.text = ""; - showAgencyCategory = true; + const Icon( + FontAwesome.help_circled) + ], + ), + ), - showIsPrivateRadio = true; + ////onvhange private sector + onChanged: (value) { + setState(() { + if (value.toString() == "YES") { + isPrivate = true; + showSalaryGradeAndSalaryStep = + false; + } else { + isPrivate = false; + showSalaryGradeAndSalaryStep = + true; + } + selectedAgency = Agency( + id: null, + name: selectedAgency!.name, + category: + selectedAgencyCategory, + privateEntity: value == "YES" + ? true + : false); + agencyFocusNode.unfocus(); + agencyCategoryFocusNode.unfocus(); + }); + }, - Navigator.pop(context); - }); - }, - child: const Text("Add"))), - ], - ), - ), - ); - }); - }, - child: const Text( - "Add Agency")) - ]), - ), - ), - - SizedBox( - height: showAgencyCategory ? 12 : 0, - ), - ////SHOW AGENCY CATEGORY - SizedBox( - child: showAgencyCategory - ? SearchField( - focusNode: - agencyCategoryFocusNode, - itemHeight: 70, - suggestions: state - .agencyCategory - .map((Category category) => - SearchFieldListItem( - category.name!, - item: category, - child: ListTile( - title: Text( - category - .name!), - subtitle: Text( - category - .industryClass! - .name!), - ))) - .toList(), - emptyWidget: Container( - height: 100, - decoration: box1(), - child: const Center( - child: Text( - "No result found ...")), - ), - onSuggestionTap: - (agencyCategory) { - setState(() { - selectedAgencyCategory = - agencyCategory.item; - agencyCategoryFocusNode - .unfocus(); - selectedAgency = Agency( - id: null, - name: selectedAgency! - .name, - category: - selectedAgencyCategory, - privateEntity: null); - }); - }, - searchInputDecoration: - normalTextFieldStyle( - "Category *", "") - .copyWith( - suffixIcon: - const Icon(Icons - .arrow_drop_down)), - validator: (value) { - if (value!.isEmpty) { - return "This field is required"; - } - return null; - }, - ) - : const SizedBox(), - ), - - ////PRVIATE SECTOR - SizedBox( - child: showIsPrivateRadio - ? FormBuilderRadioGroup( - decoration: InputDecoration( - border: InputBorder.none, - label: Row( - children: [ - Text( - "Is this private sector? ", - style: Theme.of( - context) - .textTheme - .headlineSmall! - .copyWith( - fontSize: 24), - ), - const Icon(FontAwesome - .help_circled) - ], - ), - ), - - ////onvhange private sector - onChanged: (value) { - setState(() { - if (value.toString() == - "YES") { - isPrivate = true; - showSalaryGradeAndSalaryStep = - false; - } else { - isPrivate = false; - showSalaryGradeAndSalaryStep = - true; - } - selectedAgency = Agency( - id: null, - name: selectedAgency! - .name, - category: - selectedAgencyCategory, - privateEntity: - value == "YES" - ? true - : false); - agencyFocusNode.unfocus(); - agencyCategoryFocusNode - .unfocus(); - }); - }, - - name: 'isPrivate', - validator: - FormBuilderValidators - .required(), - options: ["YES", "NO"] - .map((lang) => - FormBuilderFieldOption( - value: lang)) - .toList(growable: false), - ) - : const SizedBox()), - SizedBox( - height: showSalaryGradeAndSalaryStep - ? 12 - : 0, - ), - ////SALARY GRADE AND SALARY GRADE STEP - SizedBox( - child: showSalaryGradeAndSalaryStep - ? Column( - children: [ - Row( - children: [ - ////SALARY GRADE - Flexible( - flex: 1, - child: - FormBuilderTextField( - initialValue: state - .workHistory - .salaryGrade - ?.toString(), - name: - 'salary_grade', - keyboardType: - TextInputType - .number, - decoration: - normalTextFieldStyle( - "Salary Grade (SG)", - "0"), - validator: - integerAndNumeric, - autovalidateMode: - AutovalidateMode - .onUserInteraction, - ), - ), - const SizedBox( - width: 12, - ), - //// SALARY STEP - Flexible( - flex: 1, - child: - FormBuilderTextField( - initialValue: state - .workHistory - .sgStep - ?.toString(), - name: 'salary_step', - keyboardType: - TextInputType - .number, - decoration: - normalTextFieldStyle( - "SG Step (SG)", - "0"), - validator: - integerAndNumeric, - autovalidateMode: - AutovalidateMode - .onUserInteraction, - ), - ) - ], - ) - ], - ) - : null), - ], - ); - }), - const SizedBox( - height: 12, - ), - ////MONTHLY SALARY - FormBuilderTextField( - initialValue: state.workHistory.monthlySalary - .toString(), - onChanged: (value) { - setState(() { - salary = value; - }); - }, - validator: numericRequired, - name: "salary", - decoration: normalTextFieldStyle( - "Monthly Salary *", "") - .copyWith(prefix: const Text("₱ ")), - ), - - const SizedBox( - height: 12, - ), - StatefulBuilder(builder: (context, setState) { - return Column( - children: [ - ////CURRENTLY EMPLOYED - FormBuilderSwitch( - initialValue: currentlyEmployed, - activeColor: second, - onChanged: (value) { - setState(() { - if (value == true) { - currentlyEmployed = true; - toDateController.text = "PRESENT"; - } else { - currentlyEmployed = false; - toDateController.text = ""; - } - }); - }, - decoration: - normalTextFieldStyle("", ''), - name: 'overseas', - title: - const Text("Currently Employed?"), - ), - const SizedBox( - height: 12, - ), - SizedBox( - width: screenWidth, - child: Row( + name: 'isPrivate', + validator: + FormBuilderValidators.required(), + options: ["YES", "NO"] + .map((lang) => + FormBuilderFieldOption( + value: lang)) + .toList(growable: false), + ) + : const SizedBox()), + SizedBox( + height: showSalaryGradeAndSalaryStep ? 12 : 0, + ), + ////SALARY GRADE AND SALARY GRADE STEP + SizedBox( + child: showSalaryGradeAndSalaryStep + ? Column( children: [ - //// FROM DATE - Flexible( - flex: 1, - child: DateTimePicker( - validator: (value) { - if (value == null) { - return "This field is required"; - } - return null; - }, - use24HourFormat: false, - icon: const Icon( - Icons.date_range), - controller: - fromDateController, - firstDate: DateTime(1970), - lastDate: DateTime(2100), - timeHintText: - "Date of Examination/Conferment", - decoration: - normalTextFieldStyle( - "From *", - "From *") - .copyWith( - prefixIcon: - const Icon( - Icons.date_range, - color: Colors.black87, - )), - initialValue: null, - )), - const SizedBox( - width: 12, - ), - //// TO DATE - Flexible( - flex: 1, - child: currentlyEmployed - ? TextFormField( - enabled: false, - initialValue: "PRESENT", - style: const TextStyle( - color: - Colors.black45), - decoration: - normalTextFieldStyle( - "", "") - .copyWith( - prefixIcon: - const Icon( - Icons.date_range, - color: Colors.black45, - )), - ) - : DateTimePicker( - validator: (val) { - return null; - }, - controller: - toDateController, - firstDate: DateTime(1970), - lastDate: DateTime(2100), - decoration: normalTextFieldStyle( - "To *", "To *") - .copyWith( - prefixIcon: - const Icon( - Icons - .date_range, - color: Colors - .black87, - ), - prefixText: - currentlyEmployed - ? "PRESENT" - : ""), - initialValue: null, - ), - ), + Row( + children: [ + ////SALARY GRADE + Flexible( + flex: 1, + child: FormBuilderTextField( + initialValue: state + .workHistory.salaryGrade + ?.toString(), + name: 'salary_grade', + keyboardType: + TextInputType.number, + decoration: + normalTextFieldStyle( + "Salary Grade (SG)", + "0"), + validator: + integerAndNumeric, + autovalidateMode: + AutovalidateMode + .onUserInteraction, + ), + ), + const SizedBox( + width: 12, + ), + //// SALARY STEP + Flexible( + flex: 1, + child: FormBuilderTextField( + initialValue: state + .workHistory.sgStep + ?.toString(), + name: 'salary_step', + keyboardType: + TextInputType.number, + decoration: + normalTextFieldStyle( + "SG Step (SG)", + "0"), + validator: + integerAndNumeric, + autovalidateMode: + AutovalidateMode + .onUserInteraction, + ), + ) + ], + ) ], - ), - ), - ], - ); - }), - const Expanded(child: SizedBox()), - ////SUBMIT BUTTON - SizedBox( - width: double.infinity, - height: 60, - child: ElevatedButton( - style: mainBtnStyle( - primary, Colors.transparent, second), - onPressed: () { - if (_formKey.currentState! - .saveAndValidate()) { - salary = _formKey - .currentState!.value['salary']; - selectedPosition ??= - state.workHistory.position; - salaryGrade = _formKey.currentState! - .value['salary_grade']; - salaryGradeStep = _formKey - .currentState! - .value['salary_step']; - selectedAgency ??= - state.workHistory.agency; - - selectedStatus ??= AppoinemtStatus( - value: state.workHistory - .appointmentStatus!, - label: state.workHistory - .appointmentStatus!); - WorkHistory newWorkHistory = - WorkHistory( - id: state.workHistory.id, - position: selectedPosition, - agency: selectedAgency, - fromDate: fromDateController - .text.isEmpty - ? null - : DateTime.parse( - fromDateController.text), - toDate: toDateController - .text.isEmpty || - toDateController.text - .toUpperCase() == - "PRESENT" || - toDateController.text - .toLowerCase() == - 'null' - ? null - : DateTime.parse( - toDateController.text), - monthlySalary: - double.parse(salary!), - appointmentStatus: - selectedStatus!.value, - salaryGrade: salaryGrade == null - ? null - : int.parse(salaryGrade!), - sgStep: salaryGradeStep == null - ? null - : int.parse(salaryGradeStep!), - ); - context.read().add( - UpdateWorkHistory( - oldWorkHistory: - state.workHistory, - profileId: - profileId.toString(), - token: token!, - workHistory: newWorkHistory)); - } - }, - child: const Text(submit)), - ), - const SizedBox( - height: 20, - ), - ], - ), - ), + ) + : null), + ], + ); + }), + const SizedBox( + height: 12, ), - ), - ); - } - return Container(); - }); - } - return Container(); - }, + ////MONTHLY SALARY + FormBuilderTextField( + initialValue: + state.workHistory.monthlySalary.toString(), + onChanged: (value) { + setState(() { + salary = value; + }); + }, + validator: numericRequired, + name: "salary", + decoration: + normalTextFieldStyle("Monthly Salary *", "") + .copyWith(prefix: const Text("₱ ")), + ), + + const SizedBox( + height: 12, + ), + StatefulBuilder(builder: (context, setState) { + return Column( + children: [ + ////CURRENTLY EMPLOYED + FormBuilderSwitch( + initialValue: currentlyEmployed, + activeColor: second, + onChanged: (value) { + setState(() { + if (value == true) { + currentlyEmployed = true; + toDateController.text = "PRESENT"; + } else { + currentlyEmployed = false; + toDateController.text = ""; + } + }); + }, + decoration: normalTextFieldStyle("", ''), + name: 'overseas', + title: const Text("Currently Employed?"), + ), + const SizedBox( + height: 12, + ), + SizedBox( + width: screenWidth, + child: Row( + children: [ + //// FROM DATE + Flexible( + flex: 1, + child: DateTimePicker( + validator: + FormBuilderValidators.required( + errorText: + "This field is required"), + use24HourFormat: false, + icon: const Icon(Icons.date_range), + controller: fromDateController, + firstDate: DateTime(1970), + lastDate: DateTime(2100), + timeHintText: + "Date of Examination/Conferment", + decoration: normalTextFieldStyle( + "From *", "From *") + .copyWith( + prefixIcon: const Icon( + Icons.date_range, + color: Colors.black87, + )), + initialValue: null, + )), + const SizedBox( + width: 12, + ), + //// TO DATE + Flexible( + flex: 1, + child: currentlyEmployed + ? TextFormField( + enabled: false, + initialValue: "PRESENT", + style: const TextStyle( + color: Colors.black45), + decoration: normalTextFieldStyle( + "", "") + .copyWith( + prefixIcon: const Icon( + Icons.date_range, + color: Colors.black45, + )), + ) + : DateTimePicker( + validator: FormBuilderValidators + .required( + errorText: + "This field is required"), + controller: toDateController, + firstDate: DateTime(1970), + lastDate: DateTime(2100), + decoration: normalTextFieldStyle( + "To *", "To *") + .copyWith( + prefixIcon: const Icon( + Icons.date_range, + color: Colors.black87, + ), + prefixText: + currentlyEmployed + ? "PRESENT" + : ""), + initialValue: null, + ), + ), + ], + ), + ), + ], + ); + }), + const Expanded(child: SizedBox()), + ////SUBMIT BUTTON + SizedBox( + width: double.infinity, + height: 60, + child: ElevatedButton( + style: mainBtnStyle( + primary, Colors.transparent, second), + onPressed: () { + if (_formKey.currentState!.saveAndValidate()) { + final progress = ProgressHUD.of(context); + progress!.showWithText("Loading..."); + salary = + _formKey.currentState!.value['salary']; + selectedPosition ??= + state.workHistory.position; + salaryGrade = _formKey + .currentState!.value['salary_grade']; + salaryGradeStep = _formKey + .currentState!.value['salary_step']; + selectedAgency ??= state.workHistory.agency; + + selectedStatus ??= AppoinemtStatus( + value: + state.workHistory.appointmentStatus!, + label: + state.workHistory.appointmentStatus!); + WorkHistory newWorkHistory = WorkHistory( + id: state.workHistory.id, + position: selectedPosition, + agency: selectedAgency, + fromDate: fromDateController.text.isEmpty + ? null + : DateTime.parse( + fromDateController.text), + toDate: toDateController.text.isEmpty || + toDateController.text + .toUpperCase() == + "PRESENT" || + toDateController.text + .toLowerCase() == + 'null' + ? null + : DateTime.parse(toDateController.text), + monthlySalary: double.parse(salary!), + appointmentStatus: selectedStatus!.value, + salaryGrade: salaryGrade == null + ? null + : int.parse(salaryGrade!), + sgStep: salaryGradeStep == null + ? null + : int.parse(salaryGradeStep!), + ); + context.read().add( + UpdateWorkHistory( + oldWorkHistory: state.workHistory, + profileId: profileId.toString(), + token: token!, + workHistory: newWorkHistory)); + } + }, + child: const Text(submit)), + ), + const SizedBox( + height: 20, + ), + ], + ), + ), + ), + ), + ); + } + return const Center( + child: Text("Add Work History"), ); - } - return const Center( - child: Text("Add Work History"), - ); - }, - ); + }, + ); + }); } } diff --git a/lib/screens/profile/components/work_history_screen.dart b/lib/screens/profile/components/work_history_screen.dart index c725291..96de174 100644 --- a/lib/screens/profile/components/work_history_screen.dart +++ b/lib/screens/profile/components/work_history_screen.dart @@ -1,5 +1,4 @@ import 'dart:io'; - import 'package:app_popup_menu/app_popup_menu.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -15,6 +14,7 @@ import 'package:unit2/theme-data.dart/box_shadow.dart'; import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/utils/text_container.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart'; +import 'package:unit2/widgets/Leadings/close_leading.dart'; import 'package:unit2/widgets/empty_data.dart'; import 'package:unit2/widgets/error_state.dart'; @@ -36,11 +36,15 @@ class WorkHistoryScreen extends StatelessWidget { title: const Text(workHistoryScreenTitle), backgroundColor: primary, centerTitle: true, - actions: [ + actions: context.watch().state is WorkHistoryLoaded?[ AddLeading(onPressed: () { context.read().add(ShowAddWorkHistoryForm()); }) - ], + ]:(context.watch().state is AddWorkHistoryState || context.watch().state is EditWorkHistoryState)?[ + CloseLeading(onPressed: (){ + context.read().add(LoadWorkHistories()); + }) + ]:[], ), body: //UserBloc @@ -68,7 +72,9 @@ class WorkHistoryScreen extends StatelessWidget { } if (state is WorkHistoryLoaded || state is WorkHistoryErrorState || - state is AddWorkHistoryState ||state is WorkHistoryAddedState || state is EditWorkHistoryState) { + state is AddWorkHistoryState || + state is WorkHistoryAddedState || + state is EditWorkHistoryState) { final progress = ProgressHUD.of(context); progress!.dismiss(); } @@ -78,55 +84,59 @@ class WorkHistoryScreen extends StatelessWidget { successAlert(context, "Deletion Successfull", "Work has been deleted successfully", () { Navigator.of(context).pop(); - context.read().add( - LoadWorkHistories( - workHistories: state.workHistories)); + context + .read() + .add(LoadWorkHistories()); }); } else { errorAlert(context, "Deletion Failed", "Error deleting Work History", () { Navigator.of(context).pop(); - context.read().add( - LoadWorkHistories( - workHistories: state.workHistories)); + context + .read() + .add(LoadWorkHistories()); }); } } ////ADDED STATE - if(state is WorkHistoryAddedState){ - if (state.response['success']) { + if (state is WorkHistoryAddedState) { + if (state.response['success']) { successAlert(context, "Adding Successfull!", state.response['message'], () { Navigator.of(context).pop(); - context.read().add(LoadWorkHistories( - workHistories: state.workExperiences)); + context + .read() + .add(LoadWorkHistories()); }); } else { errorAlert(context, "Adding Failed", "Something went wrong. Please try again.", () { Navigator.of(context).pop(); - context.read().add(LoadWorkHistories( - workHistories: state.workExperiences)); + context + .read() + .add(LoadWorkHistories()); }); } } //// EDITED STATE - if(state is WorkHistoryEditedState){ - if (state.response['success']) { + if (state is WorkHistoryEditedState) { + if (state.response['success']) { successAlert(context, "Update Successfull!", state.response['message'], () { Navigator.of(context).pop(); - context.read().add(LoadWorkHistories( - workHistories: state.workExperiences)); + context + .read() + .add(LoadWorkHistories()); }); } else { errorAlert(context, "Update Failed", "Something went wrong. Please try again.", () { Navigator.of(context).pop(); - context.read().add(LoadWorkHistories( - workHistories: state.workExperiences)); + context + .read() + .add(LoadWorkHistories()); }); } } @@ -207,31 +217,41 @@ class WorkHistoryScreen extends StatelessWidget { offset: const Offset(-10, -10), elevation: 3, onSelected: (value) { - final progress = - ProgressHUD.of(context); - progress! - .showWithText("Loading..."); ////delete workhistory-= = = = = = = = =>> if (value == 2) { confirmAlert(context, () { - BlocProvider.of( + final progress = + ProgressHUD.of(context); + progress!.showWithText( + "Loading..."); + BlocProvider.of< + WorkHistoryBloc>( context) .add(DeleteWorkHistory( - profileId: - profileId, - token: token!, - workHistory: state - .workExperiences[ - index], - workHistories: state - .workExperiences)); + profileId: profileId, + token: token!, + workHistory: + state.workExperiences[ + index], + )); }, "Delete?", "Confirm Delete?"); } if (value == 1) { ////edit eligibilty-= = = = = = = = =>> - WorkHistory workHistory = state.workExperiences[index]; - context.read().add(ShowEditWorkHistoryForm(workHistory: workHistory)); + final progress = + ProgressHUD.of(context); + progress!.showWithText( + "Loading..."); + WorkHistory workHistory = + state.workExperiences[ + index]; + context + .read() + .add( + ShowEditWorkHistoryForm( + workHistory: + workHistory)); } }, menuItems: [ @@ -269,14 +289,16 @@ class WorkHistoryScreen extends StatelessWidget { } } if (state is AddWorkHistoryState) { - return const AddWorkHistoryScreen(); + return AddWorkHistoryScreen(profileId: profileId, token: token!,); } - if(state is EditWorkHistoryState){ - return const EditWorkHistoryScreen(); + if (state is EditWorkHistoryState) { + return EditWorkHistoryScreen(profileId: profileId,token: token!,); } if (state is WorkHistoryErrorState) { return SomethingWentWrong( - message: state.message, onpressed: () {}); + message: state.message, onpressed: () { + context.read().add(GetWorkHistories(profileId: profileId,token: token!)); + }); } return Container(); }, diff --git a/lib/screens/unit2/basic-info/components/cover-image.dart b/lib/screens/unit2/basic-info/components/cover-image.dart index 69c734c..f0f5031 100644 --- a/lib/screens/unit2/basic-info/components/cover-image.dart +++ b/lib/screens/unit2/basic-info/components/cover-image.dart @@ -10,7 +10,8 @@ class CoverImage extends StatelessWidget { color: Colors.grey, child: CachedNetworkImage( imageUrl: - 'https://static.vecteezy.com/system/resources/thumbnails/008/074/253/small/tropical-forest-sunset-nature-background-with-coconut-trees-vector.jpg', + "https://live.staticflickr.com/7320/9052838885_af9b21c79b_b.jpg", + // 'https://static.vecteezy.com/system/resources/thumbnails/008/074/253/small/tropical-forest-sunset-nature-background-with-coconut-trees-vector.jpg', width: double.infinity, height: 220, fit: BoxFit.cover, diff --git a/lib/screens/unit2/homepage.dart/components/menu.dart b/lib/screens/unit2/homepage.dart/components/menu.dart index d635fd0..5ddc5cf 100644 --- a/lib/screens/unit2/homepage.dart/components/menu.dart +++ b/lib/screens/unit2/homepage.dart/components/menu.dart @@ -21,12 +21,15 @@ Widget getTile( if (title.toLowerCase() == "logout") { confirmAlert(context, () async{ await CREDENTIALS!.clear(); + await CREDENTIALS!.deleteAll(['username','password','saved']); Navigator.pushReplacementNamed (context,"/"); },"Logout","Are You sure you want to logout?"); }if(title.toLowerCase() == 'profile'){ ProfileArguments profileArguments = ProfileArguments(token: userData.user!.login!.token!, userID:userData.user!.login!.user!.profileId!); Navigator.pushNamed(context, route,arguments: profileArguments); + }if(title.toLowerCase() == 'basic info'){ + Navigator.pushNamed(context, '/basic-info'); } }, diff --git a/lib/screens/unit2/login/login.dart b/lib/screens/unit2/login/login.dart index 11e7dce..7e2c7d9 100644 --- a/lib/screens/unit2/login/login.dart +++ b/lib/screens/unit2/login/login.dart @@ -36,6 +36,7 @@ class _UniT2LoginState extends State { bool showSuffixIcon = false; bool _showPassword = true; String? password; + String? username; @override Widget build(BuildContext context) { return WillPopScope( @@ -236,7 +237,7 @@ class _UniT2LoginState extends State { TextStyle(color: Colors.white), ), onPressed: () { - password = "nav071394"; + final progress = ProgressHUD.of(context); @@ -244,20 +245,21 @@ class _UniT2LoginState extends State { if (_formKey.currentState! .saveAndValidate()) { + password = _formKey + .currentState! + .value['password']; + username = _formKey + .currentState! + .value['username']; progress?.showWithText( 'Logging in...', ); BlocProvider.of(context) .add(UserLogin( - username: "rjvincentlopeplopez", - password: "shesthequ33n", - // username: _formKey - // .currentState! - // .value['username'], - // password: _formKey - // .currentState! - // .value['password']) + + username:username, + password: password )); } }, diff --git a/lib/sevices/profile/contact_services.dart b/lib/sevices/profile/contact_services.dart index 6e23edf..f3fd302 100644 --- a/lib/sevices/profile/contact_services.dart +++ b/lib/sevices/profile/contact_services.dart @@ -9,11 +9,11 @@ class ContactService { static final ContactService _instance = ContactService(); static ContactService get instance => _instance; - Future> getServiceProvider( + Future> getServiceProvider( {required int serviceTypeId}) async { - String path = Url.instance.getServiceType(); + String path = Url.instance.getCommunicationProvider(); Map params = {"service_type__id": serviceTypeId.toString()}; - List serviceProviders = []; + List serviceProviders = []; Map headers = { 'Content-Type': 'application/json; charset=UTF-8', }; @@ -25,7 +25,7 @@ class ContactService { if (data['data'] != null) { for (var element in data['data']) { CommService commService = CommService.fromJson(element); - serviceProviders.add(commService.serviceProvider!); + serviceProviders.add(commService); } } } @@ -52,7 +52,7 @@ class ContactService { "_numbermail": contactInfo.numbermail, "_active": contactInfo.active, "_primary": contactInfo.primary, - "_commServiceId": contactInfo.commService!.serviceProvider!.id! + "_commServiceId": contactInfo.commService!.id }; Map responseStatus = {}; try { @@ -71,24 +71,38 @@ class ContactService { } //// add -// Future> update( -// {required int profileId, -// required String token, -// required ContactInfo contactInfo}) async { -// String path = "${Url.instance.contactPath()}$profileId/"; -// String authToken = "Token $token"; -// Map headers = { -// 'Content-Type': 'application/json; charset=UTF-8', -// 'Authorization': authToken -// }; -// Map body ={ -// "personid": profileId, -// "_numbermail": contactInfo.numbermail, -// "_active": contactInfo.active, -// "_primary": contactInfo.primary, -// "_commServiceId": contactInfo -// } - // } + Future> add( + {required int profileId, + required String token, + required ContactInfo contactInfo}) async { + String path = "${Url.instance.contactPath()}$profileId/"; + String authToken = "Token $token"; + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': authToken + }; + Map responseStatus = {}; + Map body = { + "personid": profileId, + "_numbermail": contactInfo.numbermail, + "_active": contactInfo.active, + "_primary": contactInfo.primary, + "_commServiceId": contactInfo.commService!.id + }; + try { + http.Response response = await Request.instance + .postRequest(path: path, headers: headers, body: body, param: {}); + if (response.statusCode == 201) { + Map data = jsonDecode(response.body); + responseStatus = data; + } else { + responseStatus.addAll({'success': false}); + } + return responseStatus; + } catch (e) { + throw e.toString(); + } + } ////delete Future deleteContact( @@ -116,7 +130,7 @@ class ContactService { try { http.Response response = await Request.instance.deleteRequest( path: path, headers: headers, body: body, param: params); - if (response.statusCode == 20) { + if (response.statusCode == 200) { Map data = jsonDecode(response.body); success = data['success']; } diff --git a/lib/utils/urls.dart b/lib/utils/urls.dart index e872d95..8849535 100644 --- a/lib/utils/urls.dart +++ b/lib/utils/urls.dart @@ -4,10 +4,10 @@ class Url { String host() { // return '192.168.10.221:3003'; - // return 'agusandelnorte.gov.ph'; + return 'agusandelnorte.gov.ph'; // return "192.168.10.219:3000"; // return "devweb.agusandelnorte.gov.ph"; - return 'devapi.agusandelnorte.gov.ph:3004'; + // return 'devapi.agusandelnorte.gov.ph:3004'; } String authentication() { @@ -111,7 +111,7 @@ String getServiceTypes(){ String contactPath(){ return "/api/jobnet_app/profile/pds/basic/contact/"; } -String getServiceType(){ +String getCommunicationProvider(){ return "/api/jobnet_app/comm_services/"; } String deleteContact (){ diff --git a/lib/widgets/splash_screen.dart b/lib/widgets/splash_screen.dart index 69eaaca..364c8ac 100644 --- a/lib/widgets/splash_screen.dart +++ b/lib/widgets/splash_screen.dart @@ -45,8 +45,8 @@ class UniTSplashScreen extends StatelessWidget { height: 1, color: Colors.black)), ), - const SizedBox(height: 5,), - SpinKitThreeBounce(color: Colors.black,size: 32,) + const SizedBox(height: 150,), + const SpinKitCircle(color: primary,size: 42,) // Row( // mainAxisAlignment: MainAxisAlignment.center, // crossAxisAlignment: CrossAxisAlignment.center,