erge into develop

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-04-11 09:27:53 +08:00
parent 3789d998a8
commit 5dcfd32a51
38 changed files with 2409 additions and 2549 deletions

View File

@ -16,33 +16,57 @@ class EligibilityBloc extends Bloc<EligibilityEvent, EligibilityState> {
EligibilityBloc() : super(EligibilityInitial()) { EligibilityBloc() : super(EligibilityInitial()) {
List<Country>? globalCountries; List<Country>? globalCountries;
List<Region>? globalRegions; List<Region>? globalRegions;
List<Eligibility>? globalEligibilities; List<Eligibility> globalEligibilities = [];
List<EligibityCert>? eligibilities; List<EligibityCert> eligibilities = [];
////===================================================================== //// LOAD ELIGIBILTY
on<LoadEligibility>((event, emit) { on<LoadEligibility>((event, emit) {
emit(EligibilityLoadingState()); emit(EligibilityLoadingState());
eligibilities = event.eligibilities; if (eligibilities.isEmpty) {
emit(EligibilityLoaded(eligibilities: event.eligibilities)); GetEligibilities(profileId: event.profileId!, token: event.token!);
});
////====================================================================
on<GetEligibilities>((event, emit) async {
try {
if (eligibilities != null) {
emit(EligibilityLoaded(eligibilities: eligibilities!));
} else { } else {
emit(EligibilityLoadingState()); emit(EligibilityLoaded(eligibilities: eligibilities));
eligibilities = await EligibilityService.instance }
.getEligibilities(event.profileId, event.token); });
emit(EligibilityLoaded(eligibilities: eligibilities!));
//// DELETE
on<DeleteEligibility>((event, emit) async {
try {
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(DeletedState(success: success));
} }
} catch (e) { } catch (e) {
emit(EligibilityErrorState(message: e.toString())); emit(EligibilityErrorState(message: e.toString()));
} }
}); });
////====================================================================
//// GET ELIGIBILITY
on<GetEligibilities>((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<ShowEditEligibilityForm>((event, emit) async { on<ShowEditEligibilityForm>((event, emit) async {
try { try {
emit(EligibilityLoadingState());
if (globalCountries == null) { if (globalCountries == null) {
List<Country> countries = await LocationUtils.instance.getCountries(); List<Country> countries = await LocationUtils.instance.getCountries();
globalCountries = countries; globalCountries = countries;
@ -51,12 +75,12 @@ class EligibilityBloc extends Bloc<EligibilityEvent, EligibilityState> {
List<Region> regions = await LocationUtils.instance.getRegions(); List<Region> regions = await LocationUtils.instance.getRegions();
globalRegions = regions; globalRegions = regions;
} }
if (globalEligibilities == null) { if (globalEligibilities.isEmpty) {
List<Eligibility> eligibilities = List<Eligibility> eligibilities =
await ProfileUtilities.instance.getEligibilities(); await ProfileUtilities.instance.getEligibilities();
globalEligibilities = eligibilities; globalEligibilities = eligibilities;
} }
Eligibility currentEligibility = globalEligibilities!.firstWhere( Eligibility currentEligibility = globalEligibilities.firstWhere(
(Eligibility eligibility) => (Eligibility eligibility) =>
event.eligibityCert.eligibility!.id == eligibility.id); event.eligibityCert.eligibility!.id == eligibility.id);
bool? isOverseas = event.eligibityCert.overseas; bool? isOverseas = event.eligibityCert.overseas;
@ -95,7 +119,7 @@ class EligibilityBloc extends Bloc<EligibilityEvent, EligibilityState> {
eligibityCert: event.eligibityCert, eligibityCert: event.eligibityCert,
countries: globalCountries!, countries: globalCountries!,
regions: globalRegions!, regions: globalRegions!,
eligibilities: globalEligibilities!)); eligibilities: globalEligibilities));
} else { } else {
emit(EditEligibilityState( emit(EditEligibilityState(
selectedCountry: currentCountry, selectedCountry: currentCountry,
@ -109,17 +133,16 @@ class EligibilityBloc extends Bloc<EligibilityEvent, EligibilityState> {
eligibityCert: event.eligibityCert, eligibityCert: event.eligibityCert,
countries: globalCountries!, countries: globalCountries!,
regions: globalRegions!, regions: globalRegions!,
eligibilities: globalEligibilities!)); eligibilities: globalEligibilities));
} }
} catch (e) { } catch (e) {
emit(EligibilityErrorState(message: e.toString())); emit(EligibilityErrorState(message: e.toString()));
} }
}); });
////==================================================================== //// UPDATE
on<UpdateEligibility>((event, emit) async { on<UpdateEligibility>((event, emit) async {
try { try {
emit(EligibilityLoadingState());
Map<dynamic, dynamic> status = await EligibilityService.instance.update( Map<dynamic, dynamic> status = await EligibilityService.instance.update(
eligibityCert: event.eligibityCert, eligibityCert: event.eligibityCert,
token: event.token, token: event.token,
@ -127,26 +150,25 @@ class EligibilityBloc extends Bloc<EligibilityEvent, EligibilityState> {
oldEligibility: event.oldEligibility); oldEligibility: event.oldEligibility);
if (status['success']) { if (status['success']) {
EligibityCert newEligibility = EligibityCert.fromJson(status['data']); EligibityCert newEligibility = EligibityCert.fromJson(status['data']);
eligibilities!.removeWhere( eligibilities.removeWhere(
(EligibityCert element) => element.id == event.eligibityCert.id); (EligibityCert element) => element.id == event.eligibityCert.id);
eligibilities!.add(newEligibility); eligibilities.add(newEligibility);
emit(EligibilityEditedState( emit(EligibilityEditedState(response: status));
eligibilities: eligibilities!, response: status));
} else { } else {
emit(EligibilityEditedState( emit(EligibilityEditedState(response: status));
eligibilities: eligibilities!, response: status));
} }
} catch (e) { } catch (e) {
emit(EligibilityErrorState(message: e.toString())); emit(EligibilityErrorState(message: e.toString()));
} }
}); });
//// SHOW ADD FORM
on<ShowAddEligibilityForm>((event, emit) async { on<ShowAddEligibilityForm>((event, emit) async {
emit(EligibilityLoadingState()); emit(EligibilityLoadingState());
if (globalRegions == null) { if (globalRegions == null) {
List<Region> regions = await LocationUtils.instance.getRegions(); List<Region> regions = await LocationUtils.instance.getRegions();
globalRegions = regions; globalRegions = regions;
} }
if (globalEligibilities == null) { if (globalEligibilities.isEmpty) {
List<Eligibility> eligibilities = List<Eligibility> eligibilities =
await ProfileUtilities.instance.getEligibilities(); await ProfileUtilities.instance.getEligibilities();
globalEligibilities = eligibilities; globalEligibilities = eligibilities;
@ -157,37 +179,15 @@ class EligibilityBloc extends Bloc<EligibilityEvent, EligibilityState> {
} }
emit(AddEligibilityState( emit(AddEligibilityState(
eligibilities: globalEligibilities!, eligibilities: globalEligibilities,
regions: globalRegions!, regions: globalRegions!,
countries: globalCountries!)); countries: globalCountries!));
}); });
////====================================================================
on<DeleteEligibility>((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<EligibityCert> eligibilities = event.eligibilities; //// ADD
emit(DeletedState(success: success, eligibilities: eligibilities));
} else {
emit(DeletedState(
success: success, eligibilities: event.eligibilities));
}
} catch (e) {
emit(EligibilityErrorState(message: e.toString()));
}
});
////====================================================================
on<AddEligibility>( on<AddEligibility>(
(event, emit) async { (event, emit) async {
try { try {
emit(EligibilityLoadingState());
Map<dynamic, dynamic> status = await EligibilityService.instance.add( Map<dynamic, dynamic> status = await EligibilityService.instance.add(
eligibityCert: event.eligibityCert, eligibityCert: event.eligibityCert,
token: event.token, token: event.token,
@ -195,12 +195,10 @@ class EligibilityBloc extends Bloc<EligibilityEvent, EligibilityState> {
if (status['success']) { if (status['success']) {
EligibityCert? eligibityCert = EligibityCert? eligibityCert =
EligibityCert.fromJson(status['data']); EligibityCert.fromJson(status['data']);
eligibilities!.add(eligibityCert); eligibilities.add(eligibityCert);
emit(EligibilityAddedState( emit(EligibilityAddedState(response: status));
eligibilities: eligibilities!, response: status));
} else { } else {
emit(EligibilityAddedState( emit(EligibilityAddedState(response: status));
eligibilities: eligibilities!, response: status));
} }
} catch (e) { } catch (e) {
emit(EligibilityErrorState(message: e.toString())); emit(EligibilityErrorState(message: e.toString()));

View File

@ -38,8 +38,9 @@ class UpdateEligibility extends EligibilityEvent{
List<Object> get props =>[eligibityCert,profileId,token,oldEligibility]; List<Object> get props =>[eligibityCert,profileId,token,oldEligibility];
} }
class LoadEligibility extends EligibilityEvent { class LoadEligibility extends EligibilityEvent {
final List<EligibityCert> eligibilities; final int? profileId;
const LoadEligibility({required this.eligibilities}); final String? token;
const LoadEligibility({ this.profileId, this.token});
@override @override
List<Object> get props => []; List<Object> get props => [];
} }
@ -52,17 +53,16 @@ class ShowEditEligibilityForm extends EligibilityEvent {
} }
class DeleteEligibility extends EligibilityEvent { class DeleteEligibility extends EligibilityEvent {
final List<EligibityCert> eligibilities;
final String profileId; final String profileId;
final int eligibilityId; final int eligibilityId;
final String token; final String token;
const DeleteEligibility( const DeleteEligibility(
{required this.eligibilities, {
required this.eligibilityId, required this.eligibilityId,
required this.profileId, required this.profileId,
required this.token}); required this.token});
@override @override
List<Object> get props => [eligibilities, profileId, eligibilityId, token]; List<Object> get props => [ profileId, eligibilityId, token];
} }
class CallErrorState extends EligibilityEvent{ class CallErrorState extends EligibilityEvent{

View File

@ -43,11 +43,10 @@ class EditEligibilityState extends EligibilityState {
} }
class DeletedState extends EligibilityState { class DeletedState extends EligibilityState {
final List<EligibityCert> eligibilities;
final bool success; final bool success;
const DeletedState({required this.eligibilities, required this.success}); const DeletedState({required this.success});
@override @override
List<Object> get props => [success, eligibilities]; List<Object> get props => [success];
} }
class AddEligibilityState extends EligibilityState { class AddEligibilityState extends EligibilityState {
@ -63,20 +62,18 @@ class AddEligibilityState extends EligibilityState {
List<Object> get props => [eligibilities,countries,regions]; List<Object> get props => [eligibilities,countries,regions];
} }
class EligibilityEditedState extends EligibilityState{ class EligibilityEditedState extends EligibilityState{
final List<EligibityCert> eligibilities;
final Map<dynamic,dynamic> response; final Map<dynamic,dynamic> response;
const EligibilityEditedState({required this.eligibilities, required this.response}); const EligibilityEditedState({required this.response});
@override @override
List<Object> get props =>[eligibilities, response]; List<Object> get props =>[ response];
} }
class EligibilityAddedState extends EligibilityState{ class EligibilityAddedState extends EligibilityState{
final List<EligibityCert> eligibilities;
final Map<dynamic,dynamic> response; final Map<dynamic,dynamic> response;
const EligibilityAddedState({required this.eligibilities, required this.response}); const EligibilityAddedState({ required this.response});
@override @override
List<Object> get props =>[eligibilities,response]; List<Object> get props =>[response];
} }
class EligibilityLoadingState extends EligibilityState{ class EligibilityLoadingState extends EligibilityState{

View File

@ -1,6 +1,5 @@
import 'package:bloc/bloc.dart'; import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.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/agency.dart';
import 'package:unit2/model/utils/category.dart'; import 'package:unit2/model/utils/category.dart';
import 'package:unit2/sevices/profile/orgmembership_services.dart'; import 'package:unit2/sevices/profile/orgmembership_services.dart';
@ -30,7 +29,7 @@ class OrganizationMembershipBloc extends Bloc<OrganizationMembershipEvent, Organ
} }
}); });
on<LoadOrganizationMemberships>((event,emit){ on<LoadOrganizationMemberships>((event,emit){
emit(OrganizationMembershipLoaded(orgMemberships: event.organizationMemberships)); emit(OrganizationMembershipLoaded(orgMemberships: organizationMemberships));
}); });
////SHOW ADD ORG MEMBERSHIP FORM ////SHOW ADD ORG MEMBERSHIP FORM
@ -52,15 +51,14 @@ class OrganizationMembershipBloc extends Bloc<OrganizationMembershipEvent, Organ
}); });
//// ADD ORGMEMBERSHIP //// ADD ORGMEMBERSHIP
on<AddOrgMembership>((event,emit)async{ on<AddOrgMembership>((event,emit)async{
emit(OrgmembershipLoadingState());
try{ try{
Map<dynamic,dynamic> status= await OrganizationMembershipServices.instance.add(agency: event.agency, token: event.token, profileId: event.profileId.toString()); Map<dynamic,dynamic> status= await OrganizationMembershipServices.instance.add(agency: event.agency, token: event.token, profileId: event.profileId.toString());
if(status["success"]){ if(status["success"]){
OrganizationMembership organizationMembership = OrganizationMembership.fromJson(status["data"]); OrganizationMembership organizationMembership = OrganizationMembership.fromJson(status["data"]);
organizationMemberships.add(organizationMembership); organizationMemberships.add(organizationMembership);
emit(OrgMembershipAddedState(orgMemberships: organizationMemberships, response: status)); emit(OrgMembershipAddedState( response: status));
}else{ }else{
emit(OrgMembershipAddedState(orgMemberships: organizationMemberships, response: status)); emit(OrgMembershipAddedState( response: status));
} }
}catch(e){ }catch(e){
emit(OrganizationMembershipErrorState(message: e.toString())); emit(OrganizationMembershipErrorState(message: e.toString()));
@ -72,11 +70,10 @@ class OrganizationMembershipBloc extends Bloc<OrganizationMembershipEvent, Organ
try{ try{
final bool success = await OrganizationMembershipServices.instance.delete(agency: event.org.agency!, profileId: event.profileId, token: event.token); final bool success = await OrganizationMembershipServices.instance.delete(agency: event.org.agency!, profileId: event.profileId, token: event.token);
if(success){ if(success){
event.organizationMemberships.removeWhere((element) => element.agency!.id == event.org.agency!.id ); organizationMemberships.removeWhere((element) => element.agency!.id == event.org.agency!.id );
List<OrganizationMembership> orgmemberships = event.organizationMemberships; emit(OrgMembershipDeletedState(success: success));
emit(OrgMembershipDeletedState(organizationMemberships: orgmemberships, success: success));
}else{ }else{
emit(OrgMembershipDeletedState(organizationMemberships: organizationMemberships, success: success)); emit(OrgMembershipDeletedState(success: success));
} }
}catch(e){ }catch(e){
emit(OrganizationMembershipErrorState(message: e.toString())); emit(OrganizationMembershipErrorState(message: e.toString()));

View File

@ -8,17 +8,15 @@ abstract class OrganizationMembershipEvent extends Equatable {
} }
class LoadOrganizationMemberships extends OrganizationMembershipEvent{ class LoadOrganizationMemberships extends OrganizationMembershipEvent{
final List<OrganizationMembership> organizationMemberships;
const LoadOrganizationMemberships({required this.organizationMemberships});
@override @override
List<Object> get props => [organizationMemberships]; List<Object> get props => [];
} }
class GetOrganizationMembership extends OrganizationMembershipEvent{ class GetOrganizationMembership extends OrganizationMembershipEvent{
final int? profileId; final int? profileId;
final String? token; final String? token;
const GetOrganizationMembership({ this.profileId, this.token}); const GetOrganizationMembership({this.profileId, this.token});
} }
class ShowAddOrgMembershipForm extends OrganizationMembershipEvent{ class ShowAddOrgMembershipForm extends OrganizationMembershipEvent{
@ -37,9 +35,9 @@ class DeleteOrgMemberShip extends OrganizationMembershipEvent{
final int profileId; final int profileId;
final String token; final String token;
final OrganizationMembership org; final OrganizationMembership org;
final List<OrganizationMembership> 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 @override
List<Object> get props => [profileId,token,org,organizationMemberships]; List<Object> get props => [profileId,token,org];
} }

View File

@ -27,18 +27,16 @@ class OrgmembershipLoadingState extends OrganizationMembershipState{
} }
class OrgMembershipDeletedState extends OrganizationMembershipState{ class OrgMembershipDeletedState extends OrganizationMembershipState{
final List<OrganizationMembership> organizationMemberships;
final bool success; final bool success;
const OrgMembershipDeletedState({required this.organizationMemberships, required this.success}); const OrgMembershipDeletedState({ required this.success});
@override @override
List<Object> get props => [organizationMemberships,success]; List<Object> get props => [success];
} }
class OrgMembershipAddedState extends OrganizationMembershipState{ class OrgMembershipAddedState extends OrganizationMembershipState{
final List<OrganizationMembership> orgMemberships;
final Map<dynamic,dynamic> response; final Map<dynamic,dynamic> response;
const OrgMembershipAddedState({required this.orgMemberships, required this.response}); const OrgMembershipAddedState({required this.response});
@override @override
List<Object> get props => [orgMemberships,response]; List<Object> get props => [response];
} }
class AddOrgMembershipState extends OrganizationMembershipState{ class AddOrgMembershipState extends OrganizationMembershipState{

View File

@ -14,7 +14,7 @@ part 'contact_state.dart';
class ContactBloc extends Bloc<ContactEvent, ContactState> { class ContactBloc extends Bloc<ContactEvent, ContactState> {
ContactBloc() : super(ContactInitial()) { ContactBloc() : super(ContactInitial()) {
List<ContactInfo> contactInformations = []; List<ContactInfo> contactInformations = [];
List<ServiceType> serviceTypes =[]; List<ServiceType> serviceTypes = [];
//// get all contacts //// get all contacts
on<GetContacts>((event, emit) { on<GetContacts>((event, emit) {
emit(ContactLoadingState()); emit(ContactLoadingState());
@ -26,70 +26,116 @@ class ContactBloc extends Bloc<ContactEvent, ContactState> {
} }
}); });
//// Load Contacts //// Load Contacts
on<LoadContacts>((event,emit){ on<LoadContacts>((event, emit) {
emit(ContactLoadedState(contactInformation: event.contactInformation)); emit(ContactLoadedState(contactInformation: contactInformations));
}); });
//// show add form //// show add form
on<ShowAddForm>((event,emit)async{ on<ShowAddForm>((event, emit) async {
try{ try {
emit(ContactLoadingState()); emit(ContactLoadingState());
if(serviceTypes.isEmpty){ if (serviceTypes.isEmpty) {
serviceTypes = await ProfileUtilities.instance.getServiceType(); serviceTypes = await ProfileUtilities.instance.getServiceType();
} }
emit(ContactAddingState(serviceTypes: serviceTypes)); emit(ContactAddingState(serviceTypes: serviceTypes));
}catch(e){ } catch (e) {
emit(ContactErrorState(message: e.toString())); emit(ContactErrorState(message: e.toString()));
} }
}); });
///// Show edit form ///// Show edit form
on<ShowEditForm>((event,emit)async{ on<ShowEditForm>((event, emit) async {
ServiceType serviceType; ServiceType serviceType;
List<ServiceProvider> serviceProvivers; List<CommService> commServiceProvivers;
ServiceProvider serviceProvider; CommService serviceProvider;
try{ try{
if(serviceTypes.isEmpty){ if (serviceTypes.isEmpty) {
serviceTypes = await ProfileUtilities.instance.getServiceType(); serviceTypes = await ProfileUtilities.instance.getServiceType();
} }
serviceType = serviceTypes.firstWhere((var element){ serviceType = serviceTypes.firstWhere((ServiceType element) {
return event.contactInfo.commService!.serviceType!.id == element.id; return element.id == event.contactInfo.commService!.serviceType!.id;
}); });
serviceProvivers = await ContactService.instance.getServiceProvider(serviceTypeId: serviceType.id!); commServiceProvivers = await ContactService.instance
serviceProvider = serviceProvivers.firstWhere((element) => element.id == event.contactInfo.commService!.serviceProvider!.id); .getServiceProvider(serviceTypeId: serviceType.id!);
emit(ContactEditingState(serviceTypes: serviceTypes,selectedServiceType: serviceType,serviceProviders: serviceProvivers,selectedProvider: serviceProvider, contactInfo: event.contactInfo)); 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){ }catch(e){
emit(ContactErrorState(message: e.toString())); emit(ContactErrorState(message: e.toString()));
} }
}); });
////edit contact ////edit contact
on<EditContactInformation>((event,emit)async{ on<EditContactInformation>((event, emit) async {
Map<dynamic,dynamic> responseStatus = await ContactService.instance.update(profileId: event.profileId, token: event.token, contactInfo: event.contactInfo); try {
if(responseStatus['success']){ Map<dynamic, dynamic> responseStatus = await ContactService.instance
ContactInfo contactInfo = ContactInfo.fromJson(responseStatus['data']['contact_info']); .update(
contactInformations.removeWhere((ContactInfo element) => element.id == event.contactInfo.id); 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); contactInformations.add(contactInfo);
emit(ContactEditedState(contactInformation: contactInformations, response: responseStatus)); emit(ContactEditedState(
}else{
emit(ContactEditedState(contactInformation: contactInformations, response: responseStatus)); response: responseStatus));
} else {
emit(ContactEditedState(
response: responseStatus));
}
} catch (e) {
emit(ContactErrorState(message: e.toString()));
} }
}); });
//// add contact //// add contact
try{
}catch(e){ on<AddContactInformation>((event, emit) async {
try {
Map<dynamic, dynamic> 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())); emit(ContactErrorState(message: e.toString()));
} }
});
//// delete contact //// delete contact
on<DeleteContactInformation>((event, emit)async{ on<DeleteContactInformation>((event, emit) async {
try{ try {
final bool success = await ContactService.instance.deleteContact(profileId: event.profileId, token: event.token, contactInfo: event.contactInfo); final bool success = await ContactService.instance.deleteContact(
if(success){ profileId: event.profileId,
contactInformations.removeWhere((element) => element.id == event.contactInfo.id); token: event.token,
emit(ContactDeletedState(contactInformation: contactInformations, succcess: success)); contactInfo: event.contactInfo);
}else{ if (success) {
emit(ContactDeletedState(contactInformation: contactInformations, succcess: success)); contactInformations
.removeWhere((element) => element.id == event.contactInfo.id);
emit(ContactDeletedState(
succcess: success));
} else {
emit(ContactDeletedState(
succcess: success));
} }
}catch(e){ } catch (e) {
emit(ContactErrorState(message: e.toString())); emit(ContactErrorState(message: e.toString()));
} }
}); });

View File

@ -17,10 +17,9 @@ class GetContacts extends ContactEvent{
//// load contacts //// load contacts
class LoadContacts extends ContactEvent{ class LoadContacts extends ContactEvent{
final List<ContactInfo> contactInformation;
const LoadContacts({required this.contactInformation});
@override @override
List<Object> get props => [contactInformation]; List<Object> get props => [];
} }
//// show add form //// show add form

View File

@ -30,11 +30,11 @@ class ContactAddingState extends ContactState{
//// Editing state //// Editing state
class ContactEditingState extends ContactState{ class ContactEditingState extends ContactState{
final List<ServiceType> serviceTypes; final List<ServiceType> serviceTypes;
final List<ServiceProvider> serviceProviders; final List<CommService> commServiceProviders;
final ServiceProvider selectedProvider; final CommService selectedProvider;
final ServiceType selectedServiceType; final ServiceType selectedServiceType;
final ContactInfo contactInfo; 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 @override
List<Object> get props => [serviceTypes]; List<Object> get props => [serviceTypes];
} }
@ -42,11 +42,11 @@ class ContactEditingState extends ContactState{
//// added state //// added state
class ContactAddedState extends ContactState{ class ContactAddedState extends ContactState{
final List<ContactInfo> contactInformation;
final Map<dynamic,dynamic> response; final Map<dynamic,dynamic> response;
const ContactAddedState({required this.contactInformation, required this.response}); const ContactAddedState({ required this.response});
@override @override
List<Object> get props => [contactInformation,response]; List<Object> get props => [response];
} }
@ -54,19 +54,19 @@ class ContactAddedState extends ContactState{
//// edited state //// edited state
class ContactEditedState extends ContactState{ class ContactEditedState extends ContactState{
final List<ContactInfo> contactInformation;
final Map<dynamic,dynamic> response; final Map<dynamic,dynamic> response;
const ContactEditedState({required this.contactInformation, required this.response}); const ContactEditedState({ required this.response});
@override @override
List<Object> get props => [contactInformation,response]; List<Object> get props => [response];
} }
////deleted state ////deleted state
class ContactDeletedState extends ContactState{ class ContactDeletedState extends ContactState{
final List<ContactInfo> contactInformation;
final bool succcess; final bool succcess;
const ContactDeletedState({required this.contactInformation, required this.succcess}); const ContactDeletedState({required this.succcess});
@override @override
List<Object> get props => [contactInformation,succcess]; List<Object> get props => [succcess];
} }
////error state ////error state

View File

@ -104,7 +104,11 @@ class ReferencesBloc extends Bloc<ReferencesEvent, ReferencesState> {
event.personalReference.address!.cityMunicipality!.code == event.personalReference.address!.cityMunicipality!.code ==
city.code); city.code);
List<Barangay> barangays = await LocationUtils.instance.getBarangay(code: selectedCity.code.toString()); List<Barangay> 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( emit(EditReferenceState(
selectedRegion: selectedRegion, selectedRegion: selectedRegion,
ref: event.personalReference, ref: event.personalReference,
@ -144,17 +148,16 @@ class ReferencesBloc extends Bloc<ReferencesEvent, ReferencesState> {
message: "Something went wrong. Please try again")); message: "Something went wrong. Please try again"));
//// EDIT REFERENCES EVENT //// EDIT REFERENCES EVENT
});on<EditReference>((event,emit)async{ });on<EditReference>((event,emit)async{
emit(ReferencesLoadingState());
Map<dynamic,dynamic> status =await ReferencesServices.instace.update(ref: event.reference, token: event.token, profileId: event.profileId); Map<dynamic,dynamic> status =await ReferencesServices.instace.update(ref: event.reference, token: event.token, profileId: event.profileId);
if (status['success']) { if (status['success']) {
PersonalReference ref = PersonalReference.fromJson(status['data']); PersonalReference ref = PersonalReference.fromJson(status['data']);
references.removeWhere((PersonalReference element)=>element.id == event.reference.id); references.removeWhere((PersonalReference element)=>element.id == event.reference.id);
references.add(ref); references.add(ref);
emit( emit(
ReferenceEditedState(personalRefs: references, response: status)); ReferenceEditedState( response: status));
} else { } else {
emit( emit(
ReferenceEditedState(personalRefs: references, response: status)); ReferenceEditedState( response: status));
} }
}); });
@ -171,10 +174,10 @@ class ReferencesBloc extends Bloc<ReferencesEvent, ReferencesState> {
PersonalReference ref = PersonalReference.fromJson(status['data']); PersonalReference ref = PersonalReference.fromJson(status['data']);
references.add(ref); references.add(ref);
emit( emit(
ReferencesAddedState(personalRefs: references, response: status)); ReferencesAddedState( response: status));
} else { } else {
emit( emit(
ReferencesAddedState(personalRefs: references, response: status)); ReferencesAddedState( response: status));
} }
} catch (e) { } catch (e) {
emit(ReferencesErrorState(message: e.toString())); emit(ReferencesErrorState(message: e.toString()));
@ -183,7 +186,6 @@ class ReferencesBloc extends Bloc<ReferencesEvent, ReferencesState> {
////LOAD REFERENCE ////LOAD REFERENCE
on<LoadReferences>((event, emit) { on<LoadReferences>((event, emit) {
emit(ReferencesLoadingState()); emit(ReferencesLoadingState());
references = event.references;
emit(ReferencesLoadedState(references: references)); emit(ReferencesLoadedState(references: references));
}); });
@ -196,9 +198,9 @@ class ReferencesBloc extends Bloc<ReferencesEvent, ReferencesState> {
event.references.removeWhere( event.references.removeWhere(
(PersonalReference element) => element.id == event.refId); (PersonalReference element) => element.id == event.refId);
references = event.references; references = event.references;
emit(DeleteReferenceState(references: references, success: success)); emit(DeleteReferenceState( success: success));
} else { } else {
emit(DeleteReferenceState(references: references, success: success)); emit(DeleteReferenceState(success: success));
} }
} catch (e) { } catch (e) {
emit(ReferencesErrorState(message: e.toString())); emit(ReferencesErrorState(message: e.toString()));

View File

@ -7,63 +7,60 @@ abstract class ReferencesEvent extends Equatable {
List<Object> get props => []; List<Object> get props => [];
} }
class GetReferences extends ReferencesEvent{ class GetReferences extends ReferencesEvent {
final int profileId; final int profileId;
final String token; final String token;
const GetReferences({required this.profileId, required this.token}); const GetReferences({required this.profileId, required this.token});
@override @override
List<Object> get props => [profileId,token]; List<Object> get props => [profileId, token];
} }
class ShowAddReferenceForm extends ReferencesEvent{ class ShowAddReferenceForm extends ReferencesEvent {}
} class ShowEditReferenceForm extends ReferencesEvent {
class ShowEditReferenceForm extends ReferencesEvent{
final PersonalReference personalReference; final PersonalReference personalReference;
const ShowEditReferenceForm({required this.personalReference}); const ShowEditReferenceForm({required this.personalReference});
@override @override
List<Object> get props => [personalReference]; List<Object> get props => [personalReference];
}
class CallErrorState extends ReferencesEvent{
} }
class CallErrorState extends ReferencesEvent {}
class AddReference extends ReferencesEvent{ class AddReference extends ReferencesEvent {
final PersonalReference reference; final PersonalReference reference;
final String token; final String token;
final int profileId; final int profileId;
const AddReference({required this.profileId, required this.reference,required this.token}); const AddReference(
{required this.profileId, required this.reference, required this.token});
@override @override
List<Object> get props => [profileId,token,reference]; List<Object> get props => [profileId, token, reference];
} }
class EditReference extends ReferencesEvent{
class EditReference extends ReferencesEvent {
final PersonalReference reference; final PersonalReference reference;
final String token; final String token;
final int profileId; final int profileId;
const EditReference({required this.profileId, required this.reference,required this.token}); const EditReference(
{required this.profileId, required this.reference, required this.token});
@override @override
List<Object> get props => [profileId,token,reference]; List<Object> get props => [profileId, token, reference];
} }
class DeleteReference extends ReferencesEvent{ class DeleteReference extends ReferencesEvent {
final List<PersonalReference>references; final List<PersonalReference> references;
final int profileId; final int profileId;
final String token; final String token;
final int refId; final int refId;
const DeleteReference({required this.profileId, required this.refId, required this.references, required this.token}); const DeleteReference(
{required this.profileId,
required this.refId,
required this.references,
required this.token});
@override @override
List<Object> get props => [profileId,token,refId,references]; List<Object> get props => [profileId, token, refId, references];
} }
class LoadReferences extends ReferencesEvent{ class LoadReferences extends ReferencesEvent {
final List<PersonalReference> references;
const LoadReferences({required this.references});
@override @override
List<Object> get props => [references]; List<Object> get props => [];
} }

View File

@ -28,20 +28,19 @@ class ReferencesErrorState extends ReferencesState {
class ReferencesLoadingState extends ReferencesState {} class ReferencesLoadingState extends ReferencesState {}
class ReferencesAddedState extends ReferencesState { class ReferencesAddedState extends ReferencesState {
final List<PersonalReference> personalRefs;
final Map<dynamic, dynamic> response; final Map<dynamic, dynamic> response;
const ReferencesAddedState( const ReferencesAddedState(
{required this.personalRefs, required this.response}); { required this.response});
@override @override
List<Object> get props => [personalRefs, response]; List<Object> get props => [ response];
} }
class ReferenceEditedState extends ReferencesState { class ReferenceEditedState extends ReferencesState {
final List<PersonalReference> personalRefs;
final Map<dynamic, dynamic> response; final Map<dynamic, dynamic> response;
const ReferenceEditedState( const ReferenceEditedState(
{required this.personalRefs, required this.response}); { required this.response});
@override @override
List<Object> get props => [personalRefs, response]; List<Object> get props => [ response];
} }
class EditReferenceState extends ReferencesState { class EditReferenceState extends ReferencesState {
@ -89,7 +88,6 @@ class AddReferenceState extends ReferencesState {
} }
class DeleteReferenceState extends ReferencesState { class DeleteReferenceState extends ReferencesState {
final List<PersonalReference> references;
final bool success; final bool success;
const DeleteReferenceState({required this.references, required this.success}); const DeleteReferenceState({ required this.success});
} }

View File

@ -24,9 +24,12 @@ class WorkHistoryBloc extends Bloc<WorkHistorytEvent, WorkHistoryState> {
on<GetWorkHistories>((event, emit) async { on<GetWorkHistories>((event, emit) async {
emit(WorkHistoryLoadingState()); emit(WorkHistoryLoadingState());
try { try {
if (workExperiences.isEmpty) {
List<WorkHistory> works = await WorkHistoryService.instance List<WorkHistory> works = await WorkHistoryService.instance
.getWorkExperiences(event.profileId, event.token); .getWorkExperiences(event.profileId!, event.token!);
workExperiences = works; workExperiences = works;
}
emit(WorkHistoryLoaded(workExperiences: workExperiences)); emit(WorkHistoryLoaded(workExperiences: workExperiences));
} catch (e) { } catch (e) {
emit(WorkHistoryErrorState(message: e.toString())); emit(WorkHistoryErrorState(message: e.toString()));
@ -35,25 +38,21 @@ class WorkHistoryBloc extends Bloc<WorkHistorytEvent, WorkHistoryState> {
///// LOAD WORK HISTORIES ///// LOAD WORK HISTORIES
on<LoadWorkHistories>((event, emit) { on<LoadWorkHistories>((event, emit) {
emit(WorkHistoryLoadingState()); emit(WorkHistoryLoadingState());
workExperiences = event.workHistories;
emit(WorkHistoryLoaded(workExperiences: workExperiences)); emit(WorkHistoryLoaded(workExperiences: workExperiences));
}); });
////DELETE ////DELETE
on<DeleteWorkHistory>((event, emit) async { on<DeleteWorkHistory>((event, emit) async {
emit(WorkHistoryLoadingState());
try { try {
final bool success = await WorkHistoryService.instance.delete( final bool success = await WorkHistoryService.instance.delete(
profileId: event.profileId, profileId: event.profileId,
token: event.token, token: event.token,
work: event.workHistory); work: event.workHistory);
if (success) { if (success) {
event.workHistories.removeWhere( workExperiences.removeWhere(
(WorkHistory element) => element.id == event.workHistory.id); (WorkHistory element) => element.id == event.workHistory.id);
List<WorkHistory> newWorkHistories = event.workHistories; emit(DeletedState(success: success));
emit(DeletedState(success: success, workHistories: newWorkHistories));
} else { } else {
emit(DeletedState( emit(DeletedState(success: success));
success: success, workHistories: event.workHistories));
} }
} catch (e) { } catch (e) {
emit(WorkHistoryErrorState(message: e.toString())); emit(WorkHistoryErrorState(message: e.toString()));
@ -62,7 +61,6 @@ class WorkHistoryBloc extends Bloc<WorkHistorytEvent, WorkHistoryState> {
//// ADD WORK HISTORIES //// ADD WORK HISTORIES
on<AddWorkHostory>((event, emit) async { on<AddWorkHostory>((event, emit) async {
try { try {
emit(WorkHistoryLoadingState());
Map<dynamic, dynamic> status = await WorkHistoryService.instance.add( Map<dynamic, dynamic> status = await WorkHistoryService.instance.add(
isPrivate: event.isPrivate, isPrivate: event.isPrivate,
workHistory: event.workHistory, workHistory: event.workHistory,
@ -71,39 +69,39 @@ class WorkHistoryBloc extends Bloc<WorkHistorytEvent, WorkHistoryState> {
if (status['success']) { if (status['success']) {
WorkHistory workHistory = WorkHistory.fromJson(status['data']); WorkHistory workHistory = WorkHistory.fromJson(status['data']);
workExperiences.add(workHistory); workExperiences.add(workHistory);
emit(WorkHistoryAddedState( emit(WorkHistoryAddedState(response: status));
response: status, workExperiences: workExperiences));
} else { } else {
emit(WorkHistoryAddedState( emit(WorkHistoryAddedState(response: status));
response: status, workExperiences: workExperiences));
} }
} catch (e) { } catch (e) {
emit(WorkHistoryErrorState(message: e.toString())); emit(WorkHistoryErrorState(message: e.toString()));
} }
}); });
////UPDATE WORK HISTORY ////UPDATE WORK HISTORY
on<UpdateWorkHistory>((event, emit)async{ on<UpdateWorkHistory>((event, emit) async {
emit(WorkHistoryLoadingState()); try {
// try{ Map<dynamic, dynamic> status = await WorkHistoryService.instance.update(
Map<dynamic,dynamic> status = await WorkHistoryService.instance.update(oldWorkHistory: event.oldWorkHistory, newWorkHistory: event.workHistory, token: event.token, profileId: event.profileId); oldWorkHistory: event.oldWorkHistory,
if(status['success']){ newWorkHistory: event.workHistory,
token: event.token,
profileId: event.profileId);
if (status['success']) {
WorkHistory workHistory = WorkHistory.fromJson(status['data']); WorkHistory workHistory = WorkHistory.fromJson(status['data']);
workExperiences.removeWhere((WorkHistory work) { workExperiences.removeWhere((WorkHistory work) {
return work.id == event.oldWorkHistory.id; return work.id == event.oldWorkHistory.id;
}); });
workExperiences.add(workHistory); workExperiences.add(workHistory);
emit(WorkHistoryEditedState(workExperiences: workExperiences,response: status)); emit(WorkHistoryEditedState(response: status));
}else{ } else {
emit(WorkHistoryEditedState(response: status, workExperiences: workExperiences)); emit(WorkHistoryEditedState(
response: status,
));
} }
} catch (e) {
// }catch(e){ emit(WorkHistoryErrorState(message: e.toString()));
// emit(WorkHistoryErrorState(message: e.toString())); }
// } });
});
////SHOW EDIT WORK HISTORIES ////SHOW EDIT WORK HISTORIES
on<ShowEditWorkHistoryForm>((event, emit) async { on<ShowEditWorkHistoryForm>((event, emit) async {
@ -150,23 +148,31 @@ on<UpdateWorkHistory>((event, emit)async{
emit(WorkHistoryLoadingState()); emit(WorkHistoryLoadingState());
try { try {
/////POSITIONS------------------------------------------ /////POSITIONS------------------------------------------
if (agencyPositions.isEmpty) {
List<Position> positions = List<Position> positions =
await WorkHistoryService.instance.getAgencyPosition(); await WorkHistoryService.instance.getAgencyPosition();
agencyPositions = positions; agencyPositions = positions;
}
/////AGENCIES------------------------------------------ /////AGENCIES------------------------------------------
if (agencies.isEmpty) {
List<Agency> newAgencies = List<Agency> newAgencies =
await ProfileUtilities.instance.getAgecies(); await ProfileUtilities.instance.getAgecies();
agencies = newAgencies; agencies = newAgencies;
}
/////Category Agency------------------------------------------ /////Category Agency------------------------------------------
if (agencyCategory.isEmpty) {
List<Category> categoryAgencies = List<Category> categoryAgencies =
await ProfileUtilities.instance.agencyCategory(); await ProfileUtilities.instance.agencyCategory();
agencyCategory = categoryAgencies; agencyCategory = categoryAgencies;
}
/////////------------------------------------- /////////-------------------------------------
if (appointmentStatus.isEmpty) {
List<AppoinemtStatus> status = List<AppoinemtStatus> status =
WorkHistoryService.instance.getAppointmentStatusList(); WorkHistoryService.instance.getAppointmentStatusList();
appointmentStatus = status; appointmentStatus = status;
}
emit(AddWorkHistoryState( emit(AddWorkHistoryState(
agencyPositions: agencyPositions, agencyPositions: agencyPositions,

View File

@ -18,10 +18,8 @@ class GetWorkHistories extends WorkHistorytEvent{
} }
class LoadWorkHistories extends WorkHistorytEvent{ class LoadWorkHistories extends WorkHistorytEvent{
final List<WorkHistory> workHistories;
const LoadWorkHistories({required this.workHistories});
@override @override
List<Object> get props => [workHistories]; List<Object> get props => [];
} }
class ShowAddWorkHistoryForm extends WorkHistorytEvent{ class ShowAddWorkHistoryForm extends WorkHistorytEvent{
@ -35,13 +33,12 @@ class ShowEditWorkHistoryForm extends WorkHistorytEvent{
} }
class DeleteWorkHistory extends WorkHistorytEvent{ class DeleteWorkHistory extends WorkHistorytEvent{
final List<WorkHistory> workHistories;
final String token; final String token;
final int profileId; final int profileId;
final WorkHistory workHistory; 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 @override
List<Object> get props => [token, profileId,workHistory, workHistories]; List<Object> get props => [token, profileId,workHistory];
} }
class UpdateWorkHistory extends WorkHistorytEvent{ class UpdateWorkHistory extends WorkHistorytEvent{

View File

@ -53,25 +53,22 @@ class EditWorkHistoryState extends WorkHistoryState{
} }
class DeletedState extends WorkHistoryState{ class DeletedState extends WorkHistoryState{
final List<WorkHistory> workHistories;
final bool success; final bool success;
const DeletedState({required this.success, required this.workHistories}); const DeletedState({required this.success});
@override @override
List<Object> get props => [workHistories,success]; List<Object> get props => [success];
} }
class WorkHistoryEditedState extends WorkHistoryState{ class WorkHistoryEditedState extends WorkHistoryState{
final List<WorkHistory> workExperiences;
final Map<dynamic,dynamic> response; final Map<dynamic,dynamic> response;
const WorkHistoryEditedState({required this.response, required this.workExperiences}); const WorkHistoryEditedState({required this.response});
@override @override
List<Object> get props => [workExperiences,response]; List<Object> get props => [response];
} }
class WorkHistoryAddedState extends WorkHistoryState{ class WorkHistoryAddedState extends WorkHistoryState{
final List<WorkHistory> workExperiences;
final Map<dynamic,dynamic> response; final Map<dynamic,dynamic> response;
const WorkHistoryAddedState({required this.response, required this.workExperiences}); const WorkHistoryAddedState({required this.response});
@override @override
List<Object> get props => [workExperiences,response]; List<Object> get props => [response];
} }

View File

@ -34,6 +34,8 @@ class UserBloc extends Bloc<UserEvent, UserState> {
final String? saved = CREDENTIALS?.get('saved'); final String? saved = CREDENTIALS?.get('saved');
final String? username = CREDENTIALS?.get('username'); final String? username = CREDENTIALS?.get('username');
final String? password = CREDENTIALS?.get('password'); final String? password = CREDENTIALS?.get('password');
debugPrint(username);
debugPrint(password);
if (saved != null) { if (saved != null) {
save = true; save = true;
add(UserLogin(username: username, password: password)); add(UserLogin(username: username, password: password));

View File

@ -31,14 +31,14 @@ class _AddContactInformationScreenState
extends State<AddContactInformationScreen> { extends State<AddContactInformationScreen> {
final formKey = GlobalKey<FormBuilderState>(); final formKey = GlobalKey<FormBuilderState>();
ServiceType? selectedServiceType; ServiceType? selectedServiceType;
ServiceProvider? selectedProvider; CommService? selectedCommServiceProvider;
List<ServiceProvider> serviceProviders = []; List<CommService> commServiceProviders = [];
bool callServiceType = false; bool callServiceType = false;
bool primaryaContact = false; bool primaryaContact = false;
bool active = false; bool active = false;
String? numberMail; String? numberMail;
var mobileFormatter = MaskTextInputFormatter( var mobileFormatter = MaskTextInputFormatter(
mask: "+63 (##) ###-###", mask: "+63 (###) ###-####",
filter: {"#": RegExp(r"^[1-9][0-9]*$")}, filter: {"#": RegExp(r"^[1-9][0-9]*$")},
type: MaskAutoCompletionType.lazy, type: MaskAutoCompletionType.lazy,
initialText: "0"); initialText: "0");
@ -82,7 +82,7 @@ class _AddContactInformationScreenState
setState(() { setState(() {
callServiceType = true; callServiceType = true;
}); });
serviceProviders = await ContactService.instance commServiceProviders = await ContactService.instance
.getServiceProvider( .getServiceProvider(
serviceTypeId: selectedServiceType!.id!); serviceTypeId: selectedServiceType!.id!);
setState(() { setState(() {
@ -101,22 +101,22 @@ class _AddContactInformationScreenState
child: ModalProgressHUD( child: ModalProgressHUD(
color: Colors.transparent, color: Colors.transparent,
inAsyncCall: callServiceType, inAsyncCall: callServiceType,
child: FormBuilderDropdown<ServiceProvider>( child: FormBuilderDropdown<CommService>(
validator: FormBuilderValidators.required( validator: FormBuilderValidators.required(
errorText: "This field is required"), errorText: "This field is required"),
name: "Service Provider", name: "Service Provider",
items: serviceProviders.isEmpty items: commServiceProviders.isEmpty
? [] ? []
: serviceProviders : commServiceProviders
.map<DropdownMenuItem<ServiceProvider>>( .map<DropdownMenuItem<CommService>>(
(ServiceProvider e) { (CommService e) {
return DropdownMenuItem<ServiceProvider>( return DropdownMenuItem<CommService>(
value: e, child: Text(e.agency!.name!)); value: e, child: Text(e.serviceProvider!.agency!.name!));
}).toList(), }).toList(),
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"Communication Service *", ""), "Communication Service *", ""),
onChanged: (var serviceProvider) { onChanged: (var serviceProvider) {
selectedProvider = serviceProvider; selectedCommServiceProvider = serviceProvider;
}), }),
), ),
), ),
@ -215,10 +215,7 @@ class _AddContactInformationScreenState
numberMail = numberMail =
formKey.currentState!.value['number-mail']; formKey.currentState!.value['number-mail'];
CommService commService = CommService( CommService commService = selectedCommServiceProvider!;
id: null,
serviceType: selectedServiceType,
serviceProvider: selectedProvider);
ContactInfo contactInfo = ContactInfo( ContactInfo contactInfo = ContactInfo(
id: null, id: null,
active: active, active: active,

View File

@ -31,15 +31,15 @@ class _EditContactInformationScreenState
extends State<EditContactInformationScreen> { extends State<EditContactInformationScreen> {
final formKey = GlobalKey<FormBuilderState>(); final formKey = GlobalKey<FormBuilderState>();
ServiceType? selectedServiceType; ServiceType? selectedServiceType;
ServiceProvider? selectedProvider; CommService? selectedCommProvider;
List<ServiceProvider> serviceProviders = []; List<CommService> commServiceProviders = [];
String? numberMail; String? numberMail;
bool callServiceType = false; bool callServiceType = false;
bool? primaryaContact; bool? primaryaContact;
bool? active; bool? active;
var mobileFormatter = MaskTextInputFormatter( var mobileFormatter = MaskTextInputFormatter(
mask: "+63 (##) ###-###", mask: "+63 (###) ###-####",
filter: {"#": RegExp(r"^[1-9][0-9]*$")}, filter: {"#": RegExp(r"^[1-9][0-9]*$")},
type: MaskAutoCompletionType.lazy, type: MaskAutoCompletionType.lazy,
initialText: "0"); initialText: "0");
@ -56,8 +56,8 @@ class _EditContactInformationScreenState
builder: (context, state) { builder: (context, state) {
if (state is ContactEditingState) { if (state is ContactEditingState) {
selectedServiceType = state.selectedServiceType; selectedServiceType = state.selectedServiceType;
selectedProvider = state.selectedProvider; selectedCommProvider = state.selectedProvider;
serviceProviders = state.serviceProviders; commServiceProviders = state.commServiceProviders;
primaryaContact = state.contactInfo.primary!; primaryaContact = state.contactInfo.primary!;
active = state.contactInfo.active!; active = state.contactInfo.active!;
return FormBuilder( return FormBuilder(
@ -91,11 +91,11 @@ class _EditContactInformationScreenState
setState(() { setState(() {
callServiceType = true; callServiceType = true;
}); });
serviceProviders = await ContactService.instance commServiceProviders = await ContactService.instance
.getServiceProvider( .getServiceProvider(
serviceTypeId: serviceTypeId:
selectedServiceType!.id!); selectedServiceType!.id!);
selectedProvider = null; selectedCommProvider = null;
setState(() { setState(() {
setState(() { setState(() {
callServiceType = false; callServiceType = false;
@ -112,24 +112,24 @@ class _EditContactInformationScreenState
child: ModalProgressHUD( child: ModalProgressHUD(
color: Colors.transparent, color: Colors.transparent,
inAsyncCall: callServiceType, inAsyncCall: callServiceType,
child: DropdownButtonFormField<ServiceProvider>( child: DropdownButtonFormField<CommService>(
value: selectedProvider, value: selectedCommProvider,
validator: FormBuilderValidators.required( validator: FormBuilderValidators.required(
errorText: "This field is required"), errorText: "This field is required"),
items: serviceProviders.isEmpty items: commServiceProviders.isEmpty
? [] ? []
: serviceProviders : commServiceProviders
.map<DropdownMenuItem<ServiceProvider>>( .map<DropdownMenuItem<CommService>>(
(ServiceProvider e) { (CommService e) {
return DropdownMenuItem< return DropdownMenuItem<
ServiceProvider>( CommService>(
value: e, value: e,
child: Text(e.agency!.name!)); child: Text(e.serviceProvider!.agency!.name!));
}).toList(), }).toList(),
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"Communication Service *", ""), "Communication Service *", ""),
onChanged: (var serviceProvider) { onChanged: (var commServiceProvider) {
selectedProvider = serviceProvider; selectedCommProvider = commServiceProvider;
}), }),
), ),
), ),
@ -243,10 +243,7 @@ class _EditContactInformationScreenState
if (formKey.currentState!.saveAndValidate()) { if (formKey.currentState!.saveAndValidate()) {
numberMail = numberMail =
formKey.currentState!.value['number-mail']; formKey.currentState!.value['number-mail'];
CommService commService = CommService( CommService commService = selectedCommProvider!;
id: state.contactInfo.commService!.id,
serviceType: selectedServiceType,
serviceProvider: selectedProvider);
ContactInfo contactInfo = ContactInfo( ContactInfo contactInfo = ContactInfo(
id: state.contactInfo.id, id: state.contactInfo.id,
active: active, active: active,

View File

@ -3,7 +3,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.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/primary_information/contact/contact_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart';
@ -14,9 +13,9 @@ import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/alerts.dart'; import 'package:unit2/utils/alerts.dart';
import 'package:unit2/utils/text_container.dart'; import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/Leadings/add_leading.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/empty_data.dart';
import 'package:unit2/widgets/error_state.dart';
import '../../../../bloc/profile/eligibility/eligibility_bloc.dart';
class ContactInformationScreen extends StatelessWidget { class ContactInformationScreen extends StatelessWidget {
const ContactInformationScreen({ const ContactInformationScreen({
@ -33,11 +32,15 @@ class ContactInformationScreen extends StatelessWidget {
title: const Text(contactScreenTitle), title: const Text(contactScreenTitle),
centerTitle: true, centerTitle: true,
backgroundColor: primary, backgroundColor: primary,
actions: [ actions: context.watch<ContactBloc>().state is ContactLoadedState? [
AddLeading(onPressed: () { AddLeading(onPressed: () {
context.read<ContactBloc>().add(ShowAddForm()); context.read<ContactBloc>().add(ShowAddForm());
}) })
], ]:( context.watch<ContactBloc>().state is ContactAddingState || context.watch<ContactBloc>().state is ContactEditingState)?[
CloseLeading(onPressed: (){
context.read<ContactBloc>().add(LoadContacts());
})
]:[]
), ),
body: ProgressHUD( body: ProgressHUD(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
@ -67,15 +70,14 @@ class ContactInformationScreen extends StatelessWidget {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.dismiss(); progress!.dismiss();
} }
////EDIT CONTACT STATE ////ADDED CONTACT STATE
if (state is ContactEditedState) { if (state is ContactAddedState) {
if (state.response['success']) { if (state.response['success']) {
successAlert(context, "Update Successfull!", successAlert(context, "Update Successfull!",
state.response['message'], () { state.response['message'], () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ContactBloc>().add(LoadContacts( context.read<ContactBloc>().add(LoadContacts(
contactInformation: ));
state.contactInformation));
}); });
} else { } else {
errorAlert(context, "Update Failed", errorAlert(context, "Update Failed",
@ -83,8 +85,27 @@ class ContactInformationScreen extends StatelessWidget {
() { () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ContactBloc>().add(LoadContacts( context.read<ContactBloc>().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<ContactBloc>().add(LoadContacts(
));
});
} else {
errorAlert(context, "Update Failed",
"Something went wrong. Please try again.",
() {
Navigator.of(context).pop();
context.read<ContactBloc>().add(LoadContacts(
));
}); });
} }
} }
@ -97,16 +118,14 @@ class ContactInformationScreen extends StatelessWidget {
() { () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ContactBloc>().add(LoadContacts( context.read<ContactBloc>().add(LoadContacts(
contactInformation: ));
state.contactInformation));
}); });
} else { } else {
errorAlert(context, "Deletion Failed", errorAlert(context, "Deletion Failed",
"Error deleting Contact Info", () { "Error deleting Contact Info", () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ContactBloc>().add(LoadContacts( context.read<ContactBloc>().add(LoadContacts(
contactInformation: ));
state.contactInformation));
}); });
} }
} }
@ -136,8 +155,7 @@ class ContactInformationScreen extends StatelessWidget {
children: [ children: [
Container( Container(
decoration: box1(), decoration: box1(),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.fromLTRB(12, 12, 0, 12),
horizontal: 12, vertical: 8),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
@ -149,30 +167,18 @@ class ContactInformationScreen extends StatelessWidget {
CrossAxisAlignment CrossAxisAlignment
.start, .start,
children: [ children: [
Text(numberMail, Row(
children: [
Expanded(
child: Text(
numberMail,
style: Theme.of( style: Theme.of(
context) context)
.textTheme .textTheme
.titleMedium! .titleMedium!
.copyWith( .copyWith(
fontWeight: fontWeight:
FontWeight FontWeight.w500)),
.w500)),
const Divider(),
const SizedBox(
height: 5,
),
Row(
children: [
Expanded(
child: Text(
commService
.toString(),
style: Theme.of(
context)
.textTheme
.titleSmall,
),
), ),
state.contactInformation[index] state.contactInformation[index]
.active == .active ==
@ -201,10 +207,30 @@ class ContactInformationScreen extends StatelessWidget {
: const SizedBox() : const SizedBox()
], ],
), ),
const Divider(),
const SizedBox( const SizedBox(
height: 5, height: 5,
), ),
Text(state 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[ .contactInformation[
index] index]
.commService! .commService!
@ -212,6 +238,9 @@ class ContactInformationScreen extends StatelessWidget {
.agency! .agency!
.name .name
.toString()), .toString()),
),
],
),
]), ]),
), ),
AppPopupMenu<int>( AppPopupMenu<int>(
@ -298,6 +327,12 @@ class ContactInformationScreen extends StatelessWidget {
return EditContactInformationScreen( return EditContactInformationScreen(
profileId: profileId, token: token); profileId: profileId, token: token);
} }
if (state is ContactErrorState) {
return SomethingWentWrong(
message: state.message, onpressed: () {
context.read<ContactBloc>().add(LoadContacts());
});
}
return Container(); return Container();
}, },
); );

View File

@ -24,7 +24,10 @@ import '../../../../utils/location_utilities.dart';
import '../../../../utils/text_container.dart'; import '../../../../utils/text_container.dart';
class AddEligibilityScreen extends StatefulWidget { 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 @override
State<AddEligibilityScreen> createState() => _AddEligibilityScreenState(); State<AddEligibilityScreen> createState() => _AddEligibilityScreenState();
@ -32,7 +35,7 @@ class AddEligibilityScreen extends StatefulWidget {
class _AddEligibilityScreenState extends State<AddEligibilityScreen> { class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
final formKey = GlobalKey<FormBuilderState>(); final formKey = GlobalKey<FormBuilderState>();
bool? overseas; bool? overseas = false;
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
Region? selectedRegion; Region? selectedRegion;
Province? selectedProvince; Province? selectedProvince;
@ -51,30 +54,21 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
String? license; String? license;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
////USERBLOC
return BlocBuilder<UserBloc, UserState>(
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<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocBuilder<EligibilityBloc, EligibilityState>( return BlocBuilder<EligibilityBloc, EligibilityState>(
buildWhen: (previous, current) { buildWhen: (previous, current) {
if (state is EditEligibilityState) {}
return false; return false;
}, },
builder: (context, state) { builder: (context, state) {
////ADD ELIGIBILITY STATE ////ADD ELIGIBILITY STATE
if (state is AddEligibilityState) { if (state is AddEligibilityState) {
return ProgressHUD( return SingleChildScrollView(
child: SizedBox(
height: screenHeight * .95,
child: ProgressHUD(
child: Center( child: Center(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric( padding:
vertical: 25, horizontal: 18), const EdgeInsets.symmetric(vertical: 25, horizontal: 18),
child: FormBuilder( child: FormBuilder(
key: formKey, key: formKey,
child: Column( child: Column(
@ -101,7 +95,7 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"Eligibility", "Eligibility")), "Eligibility", "Eligibility")),
const SizedBox( const SizedBox(
height: 20, height: 8,
), ),
SizedBox( SizedBox(
@ -117,19 +111,18 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
}, },
name: 'license_number', name: 'license_number',
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"license number", "license number", "license number"),
"license number"),
), ),
), ),
const SizedBox( const SizedBox(
width: 12, width: 8,
), ),
////RATING ////RATING
Flexible( Flexible(
flex: 1, flex: 1,
child: FormBuilderTextField( child: FormBuilderTextField(
keyboardType: const TextInputType keyboardType:
.numberWithOptions(), const TextInputType.numberWithOptions(),
onChanged: (value) { onChanged: (value) {
rating = value; rating = value;
}, },
@ -142,7 +135,7 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
), ),
), ),
const SizedBox( const SizedBox(
height: 20, height: 8,
), ),
SizedBox( SizedBox(
width: screenWidth, width: screenWidth,
@ -152,41 +145,38 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
Flexible( Flexible(
flex: 1, flex: 1,
child: DateTimePicker( child: DateTimePicker(
validator: FormBuilderValidators.required(errorText: "This field is required"), validator: FormBuilderValidators.required(
errorText: "This field is required"),
use24HourFormat: false, use24HourFormat: false,
icon: const Icon( icon: const Icon(Icons.date_range),
Icons.date_range),
controller: examDateController, controller: examDateController,
firstDate: DateTime(1970), firstDate: DateTime(1970),
lastDate: DateTime(2100), lastDate: DateTime(2100),
timeHintText: timeHintText:
"Date of Examination/Conferment", "Date of Examination/Conferment",
decoration: decoration:
normalTextFieldStyle( normalTextFieldStyle("Exam date", "")
"Exam date", "")
.copyWith( .copyWith(
prefixIcon: prefixIcon: const Icon(
const Icon(
Icons.date_range, Icons.date_range,
color: Colors.black87, color: Colors.black87,
)), )),
initialValue: null, initialValue: null,
)), )),
const SizedBox( const SizedBox(
width: 12, width: 8,
), ),
////VALIDITY DATE ////VALIDITY DATE
Flexible( Flexible(
flex: 1, flex: 1,
child: DateTimePicker( child: DateTimePicker(
validator: FormBuilderValidators.required(errorText: "This field is required"), validator: FormBuilderValidators.required(
controller: errorText: "This field is required"),
validityDateController, controller: validityDateController,
firstDate: DateTime(1970), firstDate: DateTime(1970),
lastDate: DateTime(2100), lastDate: DateTime(2100),
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"Validity date", "Validity date", "Validity date")
"Validity date")
.copyWith( .copyWith(
prefixIcon: const Icon( prefixIcon: const Icon(
Icons.date_range, Icons.date_range,
@ -199,24 +189,24 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
), ),
), ),
const SizedBox( const SizedBox(
height: 20, height: 8,
), ),
Text( Text(
"Placement of Examination/Conferment", "Placement of Examination/Conferment",
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.displaySmall! .displaySmall!
.copyWith( .copyWith(fontSize: blockSizeVertical * 2),
fontSize: blockSizeVertical * 2),
), ),
const SizedBox( const SizedBox(
height: 12, height: 8,
), ),
////OVERSEAS ADDRESS SWITCH ////OVERSEAS ADDRESS SWITCH
Column( Column(
children: [ children: [
FormBuilderSwitch( FormBuilderSwitch(
validator: FormBuilderValidators.required(errorText: 'This field is required'), validator: FormBuilderValidators.required(
errorText: 'This field is required'),
initialValue: overseas, initialValue: overseas,
activeColor: second, activeColor: second,
onChanged: (value) { onChanged: (value) {
@ -224,91 +214,80 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
overseas = value; overseas = value;
}); });
}, },
decoration: decoration: normalTextFieldStyle("", ''),
normalTextFieldStyle("", ''),
name: 'overseas', name: 'overseas',
title: title: const Text("Overseas Address?"),
const Text("Overseas Address?"),
), ),
const SizedBox( const SizedBox(
height: 20, height: 8,
), ),
////COUNTRY DROPDOWN ////COUNTRY DROPDOWN
SizedBox( SizedBox(
child: overseas == true child: overseas == true
? FormBuilderDropdown<Country>( ? FormBuilderDropdown<Country>(
initialValue: null, initialValue: null,
validator: FormBuilderValidators.required(errorText: "This field is required"), validator:
items: state.countries.map< FormBuilderValidators.required(
DropdownMenuItem< errorText:
Country>>( "This field is required"),
items: state.countries
.map<DropdownMenuItem<Country>>(
(Country country) { (Country country) {
return DropdownMenuItem< return DropdownMenuItem<Country>(
Country>(
value: country, value: country,
child: FittedBox( child: FittedBox(
child: Text( child: Text(country.name!)));
country
.name!)));
}).toList(), }).toList(),
name: 'country', name: 'country',
decoration: decoration: normalTextFieldStyle(
normalTextFieldStyle( "Country*", "Country"),
"Country*", onChanged: (Country? value) {
"Country"),
onChanged:
(Country? value) {
selectedCountry = value; selectedCountry = value;
}, },
) )
: Column( : Column(
children: [ children: [
////REGION DROPDOWN ////REGION DROPDOWN
FormBuilderDropdown< FormBuilderDropdown<Region?>(
Region?>( autovalidateMode: AutovalidateMode
autovalidateMode:
AutovalidateMode
.onUserInteraction, .onUserInteraction,
validator: FormBuilderValidators.required(errorText: "This field is required"), validator:
FormBuilderValidators.required(
errorText:
"This field is required"),
//// region onchange //// region onchange
onChanged: (Region? onChanged: (Region? region) async {
region) async {
if(selectedRegion != region){
setState(() { setState(() {
provinceCall = true; provinceCall = true;
}); });
selectedRegion = selectedRegion = region;
region;
getProvinces(); getProvinces();
}
}, },
initialValue: initialValue: selectedRegion,
selectedRegion, decoration: normalTextFieldStyle(
decoration: "Region*", "Region"),
normalTextFieldStyle(
"Region*",
"Region"),
name: 'region', name: 'region',
items: state.regions.map< items: state.regions
DropdownMenuItem< .map<DropdownMenuItem<Region>>(
Region>>((Region (Region region) {
region) { return DropdownMenuItem<Region>(
return DropdownMenuItem<
Region>(
value: region, value: region,
child: Text(region child: Text(
.description!)); region.description!));
}).toList(), }).toList(),
), ),
const SizedBox( const SizedBox(
height: 20, height: 8,
), ),
////PROVINCE DROPDOWN ////PROVINCE DROPDOWN
SizedBox( SizedBox(
height: 70, height: 70,
child: ModalProgressHUD( child: ModalProgressHUD(
color: Colors color: Colors.transparent,
.transparent, inAsyncCall: provinceCall,
inAsyncCall:
provinceCall,
child: DropdownButtonFormField< child: DropdownButtonFormField<
Province?>( Province?>(
autovalidateMode: autovalidateMode:
@ -319,33 +298,29 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
? 'required' ? 'required'
: null, : null,
isExpanded: true, isExpanded: true,
value: value: selectedProvince,
selectedProvince,
onChanged: onChanged:
(Province? (Province? province) {
province) {
if(selectedProvince != province){
setState(() { setState(() {
cityCall = cityCall = true;
true;
}); });
selectedProvince = selectedProvince = province;
province;
getCities(); getCities();
}
}, },
items: provinces == items: provinces == null
null
? [] ? []
: provinces!.map< : provinces!.map<
DropdownMenuItem< DropdownMenuItem<
Province>>((Province Province>>(
province) { (Province province) {
return DropdownMenuItem( return DropdownMenuItem(
value: value: province,
province, child: FittedBox(
child: child: Text(province
FittedBox( .description!),
child:
Text(province.description!),
)); ));
}).toList(), }).toList(),
decoration: decoration:
@ -357,7 +332,7 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
//// CityMunicipalities dropdown //// CityMunicipalities dropdown
SizedBox( SizedBox(
height: 70, height: 60,
child: ModalProgressHUD( child: ModalProgressHUD(
color: Colors.white, color: Colors.white,
inAsyncCall: cityCall, inAsyncCall: cityCall,
@ -369,36 +344,29 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
: null, : null,
isExpanded: true, isExpanded: true,
onChanged: onChanged:
(CityMunicipality? (CityMunicipality? city) {
city) { selectedMunicipality = city;
selectedMunicipality =
city;
}, },
decoration: normalTextFieldStyle( decoration:
normalTextFieldStyle(
"Municipality*", "Municipality*",
"Municipality"), "Municipality"),
value: value: selectedMunicipality,
selectedMunicipality, items: citymuns == null
items: citymuns ==
null
? [] ? []
: citymuns!.map< : citymuns!.map<
DropdownMenuItem< DropdownMenuItem<
CityMunicipality>>( CityMunicipality>>(
(CityMunicipality (CityMunicipality c) {
c) {
return DropdownMenuItem( return DropdownMenuItem(
value: value: c,
c, child: Text(c
child: Text( .description!));
c.description!));
}).toList(), }).toList(),
), ),
), ),
), ),
const SizedBox(
height: 20,
),
], ],
)), )),
], ],
@ -412,8 +380,8 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
width: screenWidth, width: screenWidth,
height: 60, height: 60,
child: ElevatedButton( child: ElevatedButton(
style: mainBtnStyle(primary, style: mainBtnStyle(
Colors.transparent, second), primary, Colors.transparent, second),
onPressed: () { onPressed: () {
//rating //rating
double? rate = rating == null double? rate = rating == null
@ -423,22 +391,17 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
String? licenseNumber = license; String? licenseNumber = license;
CityMunicipality? cityMunicipality = CityMunicipality? cityMunicipality =
selectedMunicipality; selectedMunicipality;
DateTime? examDate = DateTime? examDate = examDateController
examDateController.text.isEmpty
? null
: DateTime.parse(
examDateController
.text);
DateTime? validityDate =
validityDateController
.text.isEmpty .text.isEmpty
? null ? null
: DateTime.parse(examDateController.text);
DateTime? validityDate =
validityDateController.text.isEmpty
? null
: DateTime.parse( : DateTime.parse(
validityDateController validityDateController.text);
.text);
ExamAddress examAddress = ExamAddress examAddress = ExamAddress(
ExamAddress(
barangay: null, barangay: null,
id: null, id: null,
addressCategory: null, addressCategory: null,
@ -448,30 +411,26 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
id: 175, id: 175,
name: 'Philippines', name: 'Philippines',
code: 'PH'), code: 'PH'),
cityMunicipality: cityMunicipality: cityMunicipality);
cityMunicipality); EligibityCert eligibityCert = EligibityCert(
EligibityCert eligibityCert =
EligibityCert(
id: null, id: null,
rating: rate, rating: rate,
examDate: examDate, examDate: examDate,
attachments: null, attachments: null,
eligibility: eligibility: selectedEligibility,
selectedEligibility,
examAddress: examAddress, examAddress: examAddress,
validityDate: validityDate, validityDate: validityDate,
licenseNumber: licenseNumber: licenseNumber,
licenseNumber,
overseas: overseas); overseas: overseas);
if (formKey.currentState! if (formKey.currentState!.saveAndValidate()) {
.saveAndValidate()) { final progress = ProgressHUD.of(context);
context progress!.showWithText("Loading...");
.read<EligibilityBloc>() context.read<EligibilityBloc>().add(
.add(AddEligibility( AddEligibility(
eligibityCert: eligibityCert: eligibityCert,
eligibityCert, profileId:
profileId: profileId!, widget.profileId.toString(),
token: token!)); token: widget.token));
} }
// context.read<ProfileBloc>().add(AddEligibility(eligibityCert: eligibityCert, profileId: profileId, token: token)) // context.read<ProfileBloc>().add(AddEligibility(eligibityCert: eligibityCert, profileId: profileId, token: token))
}, },
@ -484,16 +443,11 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
), ),
), ),
), ),
),
),
); );
} }
return Container();
},
);
}
return Container();
},
);
}
return Container(); return Container();
}, },
); );

View File

@ -2,11 +2,10 @@ import 'package:date_time_picker/date_time_picker.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_form_builder/flutter_form_builder.dart'; import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.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/location/city.dart';
import 'package:unit2/model/profile/eligibility.dart'; import 'package:unit2/model/profile/eligibility.dart';
import 'package:unit2/model/utils/eligibility.dart'; import 'package:unit2/model/utils/eligibility.dart';
@ -23,7 +22,9 @@ import '../../../../utils/text_container.dart';
class EditEligibilityScreen extends StatefulWidget { class EditEligibilityScreen extends StatefulWidget {
final EligibityCert eligibityCert; 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 @override
State<EditEligibilityScreen> createState() => _EditEligibilityScreenState(); State<EditEligibilityScreen> createState() => _EditEligibilityScreenState();
@ -52,20 +53,10 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
final validityDateController = TextEditingController(); final validityDateController = TextEditingController();
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
//USERBLOC
return BlocBuilder<UserBloc, UserState>(
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<ProfileBloc, ProfileState>(
builder: (context, state) {
if(state is ProfileLoaded){
return BlocBuilder<EligibilityBloc, EligibilityState>( return BlocBuilder<EligibilityBloc, EligibilityState>(
buildWhen: (previous, current) { buildWhen: (previous, current) {
if (state is EditEligibilityState) {}
return false; return false;
}, },
builder: (context, state) { builder: (context, state) {
@ -194,6 +185,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
Flexible( Flexible(
flex: 1, flex: 1,
child: DateTimePicker( child: DateTimePicker(
validator: FormBuilderValidators.required(errorText: "This field is required"),
use24HourFormat: false, use24HourFormat: false,
controller: validityDateController, controller: validityDateController,
firstDate: DateTime(1970), firstDate: DateTime(1970),
@ -514,6 +507,11 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
overseas: overseas); overseas: overseas);
if (formKey.currentState! if (formKey.currentState!
.saveAndValidate()) { .saveAndValidate()) {
final progress =
ProgressHUD.of(
context);
progress!.showWithText(
"Loading...");
context.read<EligibilityBloc>().add( context.read<EligibilityBloc>().add(
UpdateEligibility( UpdateEligibility(
eligibityCert: eligibityCert, eligibityCert: eligibityCert,
@ -521,8 +519,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
.eligibityCert .eligibityCert
.eligibility! .eligibility!
.id, .id,
profileId: profileId!, profileId:widget.profileId.toString(),
token: token!)); token: widget.token));
} }
}, },
child: const Text(submit)), child: const Text(submit)),
@ -534,15 +532,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
), ),
), ),
); );
}
return Container();
},
);
}
return Container();
},
);
} }
return Container(); return Container();
}, },

View File

@ -16,6 +16,7 @@ import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/Leadings/close_leading.dart'; import 'package:unit2/widgets/Leadings/close_leading.dart';
import 'package:unit2/widgets/empty_data.dart'; import 'package:unit2/widgets/empty_data.dart';
import 'package:unit2/widgets/error_state.dart';
import '../../../bloc/profile/eligibility/eligibility_bloc.dart'; import '../../../bloc/profile/eligibility/eligibility_bloc.dart';
import '../../../utils/alerts.dart'; import '../../../utils/alerts.dart';
@ -25,13 +26,14 @@ class EligibiltyScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
String? token; String? token;
String? profileId; int? profileId;
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async {
return true; return true;
}, },
child: Scaffold( child: Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar( appBar: AppBar(
title: context.watch<EligibilityBloc>().state is AddEligibilityState title: context.watch<EligibilityBloc>().state is AddEligibilityState
? const Text("Add Eligiblity") ? const Text("Add Eligiblity")
@ -40,8 +42,8 @@ class EligibiltyScreen extends StatelessWidget {
: const Text(elibilityScreenTitle), : const Text(elibilityScreenTitle),
centerTitle: true, centerTitle: true,
backgroundColor: primary, backgroundColor: primary,
actions: (context.watch<EligibilityBloc>().state is EligibilityLoaded || actions: (context.watch<EligibilityBloc>().state is EligibilityLoaded)
context.watch<EligibilityBloc>().state is ProfileLoading)
? [ ? [
AddLeading(onPressed: () { AddLeading(onPressed: () {
context context
@ -49,19 +51,18 @@ class EligibiltyScreen extends StatelessWidget {
.add(ShowAddEligibilityForm()); .add(ShowAddEligibilityForm());
}) })
] ]
: [ :(context.watch<EligibilityBloc>().state is AddEligibilityState || context.watch<EligibilityBloc>().state is EditEligibilityState)? [
CloseLeading(onPressed: () { CloseLeading(onPressed: () {
context.read<EligibilityBloc>().add(GetEligibilities( context.read<EligibilityBloc>().add(const LoadEligibility());
profileId: int.parse(profileId!), token: token!));
}) })
], ]:[],
), ),
body: BlocBuilder<UserBloc, UserState>( body: BlocBuilder<UserBloc, UserState>(
builder: (context, state) { builder: (context, state) {
if (state is UserLoggedIn) { if (state is UserLoggedIn) {
token = state.userData!.user!.login!.token; token = state.userData!.user!.login!.token;
profileId = profileId =
state.userData!.user!.login!.user!.profileId.toString(); state.userData!.user!.login!.user!.profileId;
return BlocBuilder<ProfileBloc, ProfileState>( return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) { builder: (context, state) {
if(state is ProfileLoaded){ if(state is ProfileLoaded){
@ -82,7 +83,9 @@ class EligibiltyScreen extends StatelessWidget {
state is EditEligibilityState || state is EditEligibilityState ||
state is DeletedState || state is DeletedState ||
state is EligibilityAddedState || state is EligibilityAddedState ||
state is EligibilityEditedState) { state is EligibilityEditedState ||
state is EligibilityErrorState
) {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.dismiss(); progress!.dismiss();
} }
@ -93,15 +96,15 @@ class EligibiltyScreen extends StatelessWidget {
"Eligibility has been deleted successfully", "Eligibility has been deleted successfully",
() { () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<EligibilityBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(const LoadEligibility(
eligibilities: state.eligibilities)); ));
}); });
} else { } else {
errorAlert(context, "Deletion Failed", errorAlert(context, "Deletion Failed",
"Error deleting eligibility", () { "Error deleting eligibility", () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<EligibilityBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(const LoadEligibility(
eligibilities: state.eligibilities)); ));
}); });
} }
} }
@ -111,16 +114,16 @@ class EligibiltyScreen extends StatelessWidget {
successAlert(context, "Adding Successfull!", successAlert(context, "Adding Successfull!",
state.response['message'], () { state.response['message'], () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<EligibilityBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(const LoadEligibility(
eligibilities: state.eligibilities)); ));
}); });
} else { } else {
errorAlert(context, "Adding Failed", errorAlert(context, "Adding Failed",
"Something went wrong. Please try again.", "Something went wrong. Please try again.",
() { () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<EligibilityBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(const LoadEligibility(
eligibilities: state.eligibilities)); ));
}); });
} }
} }
@ -130,16 +133,16 @@ class EligibiltyScreen extends StatelessWidget {
successAlert(context, "Update Successfull!", successAlert(context, "Update Successfull!",
state.response['message'], () { state.response['message'], () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<EligibilityBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(const LoadEligibility(
eligibilities: state.eligibilities)); ));
}); });
} else { } else {
errorAlert(context, "Update Failed", errorAlert(context, "Update Failed",
"Something went wrong. Please try again.", "Something went wrong. Please try again.",
() { () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<EligibilityBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(const LoadEligibility(
eligibilities: state.eligibilities)); ));
}); });
} }
} }
@ -221,27 +224,29 @@ class EligibiltyScreen extends StatelessWidget {
const Offset(-10, -10), const Offset(-10, -10),
elevation: 3, elevation: 3,
onSelected: (value) { onSelected: (value) {
////delete eligibilty-= = = = = = = = =>>
if (value == 2) {
confirmAlert(context,
() {
final progress = final progress =
ProgressHUD.of( ProgressHUD.of(
context); context);
progress!.showWithText( progress!.showWithText(
"Loading..."); "Loading...");
////delete eligibilty-= = = = = = = = =>>
if (value == 2) {
confirmAlert(context,
() {
BlocProvider.of< BlocProvider.of<
EligibilityBloc>( EligibilityBloc>(
context) context)
.add(DeleteEligibility( .add(DeleteEligibility(
eligibilities: state
.eligibilities,
eligibilityId: state eligibilityId: state
.eligibilities[ .eligibilities[
index] index]
.id!, .id!,
profileId: profileId:
profileId!, profileId.toString(),
token: token:
token!)); token!));
}, "Delete?", }, "Delete?",
@ -249,6 +254,11 @@ class EligibiltyScreen extends StatelessWidget {
} }
if (value == 1) { if (value == 1) {
////edit eligibilty-= = = = = = = = =>> ////edit eligibilty-= = = = = = = = =>>
final progress =
ProgressHUD.of(
context);
progress!.showWithText(
"Loading...");
EligibityCert EligibityCert
eligibityCert = eligibityCert =
state.eligibilities[ state.eligibilities[
@ -312,15 +322,17 @@ class EligibiltyScreen extends StatelessWidget {
} }
if (state is EditEligibilityState) { if (state is EditEligibilityState) {
return EditEligibilityScreen( return EditEligibilityScreen(
profileId: profileId!,
token: token!,
eligibityCert: state.eligibityCert); eligibityCert: state.eligibityCert);
} }
if (state is AddEligibilityState) { if (state is AddEligibilityState) {
return const AddEligibilityScreen(); return AddEligibilityScreen(token: token!,profileId: profileId!,);
} }
if (state is EligibilityErrorState) { if (state is EligibilityErrorState) {
return Center( return SomethingWentWrong(message: state.message, onpressed: (){
child: Text(state.message), context.read<EligibilityBloc>().add(LoadEligibility(token: token,profileId: profileId));
); });
} }
return Container( return Container(
color: Colors.grey.shade200, color: Colors.grey.shade200,

View File

@ -135,21 +135,20 @@ class LoadingScreen extends StatelessWidget {
), ),
Center( Center(
child: Container( child: Container(
height: 120, height: 80,
width: 120, width: 80,
decoration:const BoxDecoration( decoration:const BoxDecoration(
color: Colors.black87, color: Colors.black87,
borderRadius: BorderRadius.all(Radius.circular(25)) borderRadius: BorderRadius.all(Radius.circular(8))
), ),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: const[ children: const[
SpinKitFadingCircle( SpinKitFadingCircle(
size: 42,
color: Colors.white), color: Colors.white),
SizedBox(height: 10,),
Text("Loading Profile",textAlign: TextAlign.center, style: TextStyle(color: Colors.white,fontSize: 10),)
], ],
), ),
), ),

View File

@ -5,11 +5,8 @@ import 'package:fluttericon/font_awesome_icons.dart';
import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:searchfield/searchfield.dart'; import 'package:searchfield/searchfield.dart';
import 'package:unit2/bloc/profile/other_information/org_membership/organization_membership_bloc.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/model/utils/agency.dart';
import 'package:unit2/utils/text_container.dart'; import 'package:unit2/utils/text_container.dart';
import '../../../../../model/utils/category.dart'; import '../../../../../model/utils/category.dart';
import '../../../../../theme-data.dart/box_shadow.dart'; import '../../../../../theme-data.dart/box_shadow.dart';
import '../../../../../theme-data.dart/btn-style.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'; import '../../../../../theme-data.dart/form-style.dart';
class AddOrgMemberShipScreen extends StatefulWidget { 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 @override
State<AddOrgMemberShipScreen> createState() => _AddOrgMemberShipScreenState(); State<AddOrgMemberShipScreen> createState() => _AddOrgMemberShipScreenState();
@ -34,39 +34,26 @@ Agency? newAgency;
bool showIsPrivateRadio = false; bool showIsPrivateRadio = false;
bool? isPrivate = false; bool? isPrivate = false;
final _formKey = GlobalKey<FormBuilderState>(); final _formKey = GlobalKey<FormBuilderState>();
int? profileId;
String? token;
class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> { class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<UserBloc, UserState>( return BlocBuilder<OrganizationMembershipBloc, OrganizationMembershipState>(
builder: (context, state) {
if (state is UserLoggedIn) {
token = state.userData!.user!.login!.token;
profileId = state.userData!.user!.login!.user!.profileId;
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocBuilder<OrganizationMembershipBloc,
OrganizationMembershipState>(
builder: (context, state) { builder: (context, state) {
if (state is AddOrgMembershipState) { if (state is AddOrgMembershipState) {
return SingleChildScrollView( return SingleChildScrollView(
child: FormBuilder( child: FormBuilder(
key: _formKey, key: _formKey,
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric( padding:
vertical: 25, horizontal: 18), const EdgeInsets.symmetric(vertical: 25, horizontal: 18),
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: crossAxisAlignment: CrossAxisAlignment.center,
CrossAxisAlignment.center,
children: [ children: [
const SizedBox( const SizedBox(
height: 100, height: 100,
), ),
StatefulBuilder( StatefulBuilder(builder: (context, setState) {
builder: (context, setState) {
//// AGENCY SEARCHFIELD //// AGENCY SEARCHFIELD
return Column( return Column(
children: [ children: [
@ -74,20 +61,15 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
itemHeight: 70, itemHeight: 70,
suggestions: state.agencies suggestions: state.agencies
.map((Agency agency) => .map((Agency agency) =>
SearchFieldListItem( SearchFieldListItem(agency.name!,
agency.name!,
item: agency, item: agency,
child: ListTile( child: ListTile(
title: Text( title: Text(
agency.name! agency.name!.toUpperCase(),
.toUpperCase(), overflow: TextOverflow.ellipsis,
overflow:
TextOverflow
.ellipsis,
), ),
subtitle: Text(agency subtitle: Text(
.privateEntity == agency.privateEntity == true
true
? "Private" ? "Private"
: agency.privateEntity == : agency.privateEntity ==
false false
@ -95,26 +77,20 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
: ""), : ""),
))) )))
.toList(), .toList(),
validator: FormBuilderValidators validator: FormBuilderValidators.required(
.required( errorText: "This field is required"),
errorText:
"This field is required"),
focusNode: agencyFocusNode, focusNode: agencyFocusNode,
searchInputDecoration: searchInputDecoration: normalTextFieldStyle(
normalTextFieldStyle(
"Agency *", "") "Agency *", "")
.copyWith( .copyWith(
suffixIcon: suffixIcon:
const Icon(Icons const Icon(Icons.arrow_drop_down)),
.arrow_drop_down)),
////agency suggestion tap ////agency suggestion tap
onSuggestionTap: (agency) { onSuggestionTap: (agency) {
setState(() { setState(() {
selectedAgency = agency.item; selectedAgency = agency.item;
agencyFocusNode.unfocus(); agencyFocusNode.unfocus();
if (selectedAgency if (selectedAgency?.category == null) {
?.category ==
null) {
showAgencyCategory = true; showAgencyCategory = true;
showIsPrivateRadio = true; showIsPrivateRadio = true;
} else { } else {
@ -128,17 +104,14 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
height: 100, height: 100,
child: Column( child: Column(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment MainAxisAlignment.center,
.center,
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment CrossAxisAlignment.center,
.center,
children: [ children: [
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
const Text( const Text("No result found..."),
"No result found..."),
const SizedBox( const SizedBox(
height: 10, height: 10,
), ),
@ -146,54 +119,62 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
//// Add agency onpressed //// Add agency onpressed
onPressed: () { onPressed: () {
showDialog( showDialog(
context: context: context,
context,
builder: builder:
(BuildContext (BuildContext context) {
context) {
return AlertDialog( return AlertDialog(
title: const Text( title: const Text(
"Add Agency?"), "Add Agency?"),
content: content: SizedBox(
SizedBox( height: 130,
height: child: Column(
130,
child:
Column(
children: [ children: [
TextFormField( TextFormField(
controller: controller:
addAgencyController, addAgencyController,
decoration: decoration:
normalTextFieldStyle("", ""), normalTextFieldStyle(
"", ""),
), ),
const SizedBox( const SizedBox(
height: height: 12,
12,
), ),
SizedBox( SizedBox(
width: double.infinity, width: double
.infinity,
height: 50, height: 50,
child: ElevatedButton( child:
style: mainBtnStyle(primary, Colors.transparent, second), ElevatedButton(
style: mainBtnStyle(
primary,
Colors
.transparent,
second),
//// onpressed //// onpressed
onPressed: () { onPressed:
setState(() { () {
newAgency = Agency(id: null, name: addAgencyController.text.toUpperCase(), category: null, privateEntity: null); setState(
state.agencies.insert(0, newAgency!); () {
newAgency = Agency(
id: null,
name: addAgencyController.text.toUpperCase(),
category: null,
privateEntity: null);
state.agencies.insert(0,
newAgency!);
addAgencyController.clear(); addAgencyController.clear();
Navigator.pop(context); Navigator.pop(context);
}); });
}, },
child: const Text("Add"))), child: const Text(
"Add"))),
], ],
), ),
), ),
); );
}); });
}, },
child: const Text( child: const Text("Add position"))
"Add position"))
]), ]),
), ),
), ),
@ -203,23 +184,16 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
SizedBox( SizedBox(
child: showAgencyCategory child: showAgencyCategory
? SearchField( ? SearchField(
focusNode: focusNode: agencyCategoryFocusNode,
agencyCategoryFocusNode,
itemHeight: 70, itemHeight: 70,
suggestions: state suggestions: state.agencyCategories
.agencyCategories .map((Category category) =>
.map((Category
category) =>
SearchFieldListItem( SearchFieldListItem(
category category.name!,
.name!, item: category,
item: child: ListTile(
category, title:
child: Text(category.name!),
ListTile(
title: Text(
category
.name!),
subtitle: Text(category subtitle: Text(category
.industryClass! .industryClass!
.name!), .name!),
@ -229,33 +203,26 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
height: 100, height: 100,
decoration: box1(), decoration: box1(),
child: const Center( child: const Center(
child: Text( child:
"No result found ...")), Text("No result found ...")),
), ),
////agency controller suggestion tap ////agency controller suggestion tap
onSuggestionTap: onSuggestionTap: (agencyCategory) {
(agencyCategory) {
setState(() { setState(() {
selectedCategory = selectedCategory =
agencyCategory agencyCategory.item;
.item;
agencyCategoryFocusNode agencyCategoryFocusNode.unfocus();
.unfocus();
}); });
}, },
searchInputDecoration: searchInputDecoration:
normalTextFieldStyle( normalTextFieldStyle(
"Category *", "Category *", "")
"")
.copyWith( .copyWith(
suffixIcon: suffixIcon: const Icon(
const Icon( Icons.arrow_drop_down)),
Icons
.arrow_drop_down)),
validator: validator:
FormBuilderValidators FormBuilderValidators.required(
.required(
errorText: errorText:
"This field is required"), "This field is required"),
) )
@ -266,24 +233,19 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
SizedBox( SizedBox(
child: showIsPrivateRadio child: showIsPrivateRadio
? FormBuilderRadioGroup( ? FormBuilderRadioGroup(
decoration: decoration: InputDecoration(
InputDecoration( border: InputBorder.none,
border:
InputBorder.none,
label: Row( label: Row(
children: [ children: [
Text( Text(
"Is this private sector? ", "Is this private sector? ",
style: Theme.of( style: Theme.of(context)
context)
.textTheme .textTheme
.headlineSmall! .headlineSmall!
.copyWith( .copyWith(fontSize: 24),
fontSize:
24),
), ),
const Icon(FontAwesome const Icon(
.help_circled) FontAwesome.help_circled)
], ],
), ),
), ),
@ -291,9 +253,7 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
////onvhange private sector ////onvhange private sector
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
if (value if (value.toString() == "YES") {
.toString() ==
"YES") {
isPrivate = true; isPrivate = true;
} else { } else {
isPrivate = false; isPrivate = false;
@ -303,18 +263,14 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
name: 'isPrivate', name: 'isPrivate',
validator: validator:
FormBuilderValidators FormBuilderValidators.required(
.required(
errorText: errorText:
"This field is required"), "This field is required"),
options: ["YES", "NO"] options: ["YES", "NO"]
.map((lang) => .map((lang) =>
FormBuilderFieldOption( FormBuilderFieldOption(
value: value: lang))
lang)) .toList(growable: false),
.toList(
growable:
false),
) )
: const SizedBox()), : const SizedBox()),
], ],
@ -329,23 +285,26 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
height: 60, height: 60,
width: double.infinity, width: double.infinity,
child: ElevatedButton( child: ElevatedButton(
style: mainBtnStyle(primary, style: mainBtnStyle(
Colors.transparent, second), primary, Colors.transparent, second),
onPressed: () { onPressed: () {
if (_formKey.currentState! if (_formKey.currentState!.saveAndValidate()) {
.saveAndValidate()) { if (selectedAgency?.privateEntity != null) {
if(selectedAgency?.privateEntity != null){
newAgency = selectedAgency; newAgency = selectedAgency;
}else{ } else {
newAgency = Agency( newAgency = Agency(
id: selectedAgency?.id, id: selectedAgency?.id,
name: selectedAgency!.name, name: selectedAgency!.name,
category: category: selectedCategory,
selectedCategory,
privateEntity: isPrivate); privateEntity: isPrivate);
} }
context.read<OrganizationMembershipBloc>().add(AddOrgMembership(agency: newAgency!, profileId: profileId!, token: token!)); context
.read<OrganizationMembershipBloc>()
.add(AddOrgMembership(
agency: newAgency!,
profileId: widget.profileId,
token: widget.token));
setState(() { setState(() {
showAgencyCategory = false; showAgencyCategory = false;
showIsPrivateRadio = false; showIsPrivateRadio = false;
@ -362,12 +321,4 @@ class _AddOrgMemberShipScreenState extends State<AddOrgMemberShipScreen> {
}, },
); );
} }
return Container();
},
);
}
return const Placeholder();
},
);
}
} }

View File

@ -14,6 +14,7 @@ import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/Leadings/close_leading.dart'; import 'package:unit2/widgets/Leadings/close_leading.dart';
import 'package:unit2/widgets/empty_data.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 '../../../../bloc/profile/other_information/org_membership/organization_membership_bloc.dart';
import '../../../../utils/alerts.dart'; import '../../../../utils/alerts.dart';
import '../../../../utils/global.dart'; import '../../../../utils/global.dart';
@ -65,6 +66,7 @@ class OrgMembershipsScreen extends StatelessWidget {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.dismiss(); progress!.dismiss();
} }
////ADDED STATE ////ADDED STATE
if (state is OrgMembershipAddedState) { if (state is OrgMembershipAddedState) {
if (state.response['success']) { if (state.response['success']) {
@ -73,8 +75,7 @@ class OrgMembershipsScreen extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<OrganizationMembershipBloc>().add( context.read<OrganizationMembershipBloc>().add(
LoadOrganizationMemberships( LoadOrganizationMemberships(
organizationMemberships: ));
state.orgMemberships));
}); });
} else { } else {
errorAlert(context, "Adding Failed", errorAlert(context, "Adding Failed",
@ -83,8 +84,7 @@ class OrgMembershipsScreen extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<OrganizationMembershipBloc>().add( context.read<OrganizationMembershipBloc>().add(
LoadOrganizationMemberships( LoadOrganizationMemberships(
organizationMemberships: ));
state.orgMemberships));
}); });
} }
} }
@ -96,7 +96,7 @@ class OrgMembershipsScreen extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<OrganizationMembershipBloc>().add( context.read<OrganizationMembershipBloc>().add(
LoadOrganizationMemberships( LoadOrganizationMemberships(
organizationMemberships: state.organizationMemberships)); ));
}); });
} else { } else {
errorAlert(context, "Deletion Failed", errorAlert(context, "Deletion Failed",
@ -104,7 +104,7 @@ class OrgMembershipsScreen extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<OrganizationMembershipBloc>().add( context.read<OrganizationMembershipBloc>().add(
LoadOrganizationMemberships( LoadOrganizationMemberships(
organizationMemberships: state.organizationMemberships)); ));
}); });
} }
} }
@ -161,14 +161,15 @@ class OrgMembershipsScreen extends StatelessWidget {
offset: const Offset(-10, -10), offset: const Offset(-10, -10),
elevation: 3, elevation: 3,
onSelected: (value) { onSelected: (value) {
////delete orgmembership-= = = = = = = = =>>
if (value == 1) {
confirmAlert(context, () {
final progress = final progress =
ProgressHUD.of(context); ProgressHUD.of(context);
progress! progress!
.showWithText("Loading..."); .showWithText("Loading...");
////delete orgmembership-= = = = = = = = =>> context.read<OrganizationMembershipBloc>().add(DeleteOrgMemberShip(profileId: profileId, token: token!, org: state.orgMemberships[index]));
if (value == 1) {
confirmAlert(context, () {
context.read<OrganizationMembershipBloc>().add(DeleteOrgMemberShip(profileId: profileId, token: token!, org: state.orgMemberships[index], organizationMemberships: state.orgMemberships));
}, "Delete?", }, "Delete?",
"Confirm Delete?"); "Confirm Delete?");
} }
@ -198,9 +199,13 @@ class OrgMembershipsScreen extends StatelessWidget {
}); });
} }
if (state is AddOrgMembershipState) { if (state is AddOrgMembershipState) {
return const AddOrgMemberShipScreen(); return AlertDialog(
content: AddOrgMemberShipScreen(profileId: profileId,token: token!,)
);
}if(state is OrganizationMembershipErrorState){ }if(state is OrganizationMembershipErrorState){
return Container(child: Text(state.message),); return SomethingWentWrong(message: state.message, onpressed: (){
context.read<OrganizationMembershipBloc>().add(GetOrganizationMembership(token: token,profileId: profileId));
});
} }
return Container(); return Container();
}, },

View File

@ -1,6 +1,4 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.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/bloc/user/user_bloc.dart';
import 'package:unit2/model/profile/other_information/skills_and_hobbies.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/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/theme-data.dart/colors.dart';
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/text_container.dart'; import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart'; import 'package:unit2/widgets/empty_data.dart';

View File

@ -4,14 +4,13 @@ import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.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/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/address_category.dart';
import 'package:unit2/model/location/barangay.dart'; import 'package:unit2/model/location/barangay.dart';
import 'package:unit2/model/profile/references.dart'; import 'package:unit2/model/profile/references.dart';
import 'package:unit2/theme-data.dart/btn-style.dart'; import 'package:unit2/theme-data.dart/btn-style.dart';
import 'package:unit2/theme-data.dart/form-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/city.dart';
import '../../../../model/location/country.dart'; import '../../../../model/location/country.dart';
import '../../../../model/location/provinces.dart'; import '../../../../model/location/provinces.dart';
@ -21,7 +20,10 @@ import '../../../../utils/location_utilities.dart';
import '../../../../utils/text_container.dart'; import '../../../../utils/text_container.dart';
class AddReferenceScreen extends StatefulWidget { 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 @override
State<AddReferenceScreen> createState() => _AddReferenceScreenState(); State<AddReferenceScreen> createState() => _AddReferenceScreenState();
@ -29,8 +31,6 @@ class AddReferenceScreen extends StatefulWidget {
class _AddReferenceScreenState extends State<AddReferenceScreen> { class _AddReferenceScreenState extends State<AddReferenceScreen> {
final formKey = GlobalKey<FormBuilderState>(); final formKey = GlobalKey<FormBuilderState>();
String? token;
String? profileId;
bool provinceCall = false; bool provinceCall = false;
bool cityCall = false; bool cityCall = false;
bool barangayCall = false; bool barangayCall = false;
@ -48,21 +48,15 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
AddressCategory? selectedCategory; AddressCategory? selectedCategory;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
token = state.userData!.user!.login!.token;
profileId = state.userData!.user!.login!.user!.profileId.toString();
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocBuilder<ReferencesBloc, ReferencesState>( return BlocBuilder<ReferencesBloc, ReferencesState>(
builder: (context, state) { builder: (context, state) {
if (state is AddReferenceState) { if (state is AddReferenceState) {
return ProgressHUD( return SingleChildScrollView(
child: SizedBox(
height: screenHeight * .95,
child: ProgressHUD(
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(vertical: 25, horizontal: 18),
vertical: 25, horizontal: 18),
child: FormBuilder( child: FormBuilder(
key: formKey, key: formKey,
child: Column( child: Column(
@ -77,10 +71,8 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"Last name *", "Last name *"), "Last name *", "Last name *"),
name: "lastname", name: "lastname",
validator: validator: FormBuilderValidators.required(
FormBuilderValidators.required( errorText: "This field is required"),
errorText:
"This field is required"),
), ),
), ),
const SizedBox( const SizedBox(
@ -93,10 +85,8 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"First name *", "First name *"), "First name *", "First name *"),
name: "firstname", name: "firstname",
validator: validator: FormBuilderValidators.required(
FormBuilderValidators.required( errorText: "This field is required"),
errorText:
"This field is required"),
), ),
), ),
], ],
@ -112,10 +102,8 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"Middle name *", "Midlle name *"), "Middle name *", "Midlle name *"),
name: "middlename", name: "middlename",
validator: validator: FormBuilderValidators.required(
FormBuilderValidators.required( errorText: "This field is required"),
errorText:
"This field is required"),
), ),
), ),
const SizedBox( const SizedBox(
@ -124,20 +112,16 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
////CATEGORY ////CATEGORY
Flexible( Flexible(
flex: 1, flex: 1,
child: FormBuilderDropdown< child: FormBuilderDropdown<AddressCategory>(
AddressCategory>(
name: 'category', name: 'category',
validator: validator:
FormBuilderValidators.required( FormBuilderValidators.required(errorText: ""),
errorText: ""), decoration:
decoration: normalTextFieldStyle( normalTextFieldStyle("Category", "Category"),
"Category", "Category"), items: state.categories
items: state.categories.map< .map<DropdownMenuItem<AddressCategory>>(
DropdownMenuItem<
AddressCategory>>(
(AddressCategory cat) { (AddressCategory cat) {
return DropdownMenuItem< return DropdownMenuItem<AddressCategory>(
AddressCategory>(
value: cat, value: cat,
child: Text(cat.name!), child: Text(cat.name!),
); );
@ -181,34 +165,28 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
////REGION DROPDOWN ////REGION DROPDOWN
FormBuilderDropdown<Region?>( FormBuilderDropdown<Region?>(
autovalidateMode: autovalidateMode:
AutovalidateMode AutovalidateMode.onUserInteraction,
.onUserInteraction, validator: FormBuilderValidators.required(
validator: FormBuilderValidators errorText: "This field is required"),
.required( onChanged: (Region? region) async {
errorText: if(selectedRegion != region){
"This field is required"),
onChanged:
(Region? region) async {
setState(() { setState(() {
provinceCall = true; provinceCall = true;
}); });
selectedRegion = region; selectedRegion = region;
getProvinces(); getProvinces();
}
}, },
initialValue: null, initialValue: null,
decoration: decoration: normalTextFieldStyle(
normalTextFieldStyle(
"Region*", "Region"), "Region*", "Region"),
name: 'region', name: 'region',
items: state.regions.map< items: state.regions
DropdownMenuItem< .map<DropdownMenuItem<Region>>(
Region>>(
(Region region) { (Region region) {
return DropdownMenuItem< return DropdownMenuItem<Region>(
Region>(
value: region, value: region,
child: Text( child: Text(region.description!));
region.description!));
}).toList(), }).toList(),
), ),
const SizedBox( const SizedBox(
@ -220,47 +198,37 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
child: ModalProgressHUD( child: ModalProgressHUD(
color: Colors.transparent, color: Colors.transparent,
inAsyncCall: provinceCall, inAsyncCall: provinceCall,
child: DropdownButtonFormField< child: DropdownButtonFormField<Province?>(
Province?>( autovalidateMode: AutovalidateMode
autovalidateMode:
AutovalidateMode
.onUserInteraction, .onUserInteraction,
validator: (value) => validator: (value) =>
value == null value == null ? 'required' : null,
? 'required'
: null,
isExpanded: true, isExpanded: true,
value: selectedProvince, value: selectedProvince,
onChanged: onChanged: (Province? province) {
(Province? province) { if(selectedProvince != province){
setState(() { setState(() {
cityCall = true; cityCall = true;
}); });
selectedProvince = selectedProvince = province;
province;
getCities(); getCities();
}
}, },
items: provinces == null items: provinces == null
? [] ? []
: provinces!.map< : provinces!.map<
DropdownMenuItem< DropdownMenuItem<
Province>>( Province>>(
(Province (Province province) {
province) {
return DropdownMenuItem( return DropdownMenuItem(
value: value: province,
province, child: FittedBox(
child: child: Text(province
FittedBox(
child: Text(
province
.description!), .description!),
)); ));
}).toList(), }).toList(),
decoration: decoration: normalTextFieldStyle(
normalTextFieldStyle( "Province*", "Province")),
"Province*",
"Province")),
), ),
), ),
////CITY MUNICIPALITY ////CITY MUNICIPALITY
@ -269,40 +237,35 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
child: ModalProgressHUD( child: ModalProgressHUD(
color: Colors.white, color: Colors.white,
inAsyncCall: cityCall, inAsyncCall: cityCall,
child: child: DropdownButtonFormField<
DropdownButtonFormField<
CityMunicipality>( CityMunicipality>(
validator: FormBuilderValidators validator:
.required( FormBuilderValidators.required(
errorText: errorText:
"This field is required"), "This field is required"),
isExpanded: true, isExpanded: true,
onChanged: onChanged: (CityMunicipality? city) {
(CityMunicipality? if(selectedMunicipality != city){
city) {
setState(() { setState(() {
barangayCall = true; barangayCall = true;
}); });
selectedMunicipality = selectedMunicipality = city;
city;
getBarangays(); getBarangays();
}
}, },
decoration: decoration: normalTextFieldStyle(
normalTextFieldStyle( "Municipality*", "Municipality"),
"Municipality*",
"Municipality"),
value: selectedMunicipality, value: selectedMunicipality,
items: citymuns == null items: citymuns == null
? [] ? []
: citymuns!.map< : citymuns!.map<
DropdownMenuItem< DropdownMenuItem<
CityMunicipality>>( CityMunicipality>>(
(CityMunicipality (CityMunicipality c) {
c) {
return DropdownMenuItem( return DropdownMenuItem(
value: c, value: c,
child: Text(c child:
.description!)); Text(c.description!));
}).toList(), }).toList(),
), ),
), ),
@ -313,35 +276,24 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
child: ModalProgressHUD( child: ModalProgressHUD(
color: Colors.white, color: Colors.white,
inAsyncCall: barangayCall, inAsyncCall: barangayCall,
child: child: DropdownButtonFormField<Barangay>(
DropdownButtonFormField<
Barangay>(
validator: FormBuilderValidators
.required(
errorText:
"This field is required"),
isExpanded: true, isExpanded: true,
onChanged: onChanged: (Barangay? baragay) {
(Barangay? baragay) { selectedBarangay = baragay;
selectedBarangay =
baragay;
}, },
decoration: decoration: normalTextFieldStyle(
normalTextFieldStyle( "Barangay*", "Barangay"),
"Barangay*",
"Barangay"),
value: selectedBarangay, value: selectedBarangay,
items: barangays == null items: barangays == null
? [] ? []
: barangays!.map< : barangays!.map<
DropdownMenuItem< DropdownMenuItem<Barangay>>(
Barangay>>( (Barangay barangay) {
(Barangay
barangay) {
return DropdownMenuItem( return DropdownMenuItem(
value: barangay, value: barangay,
child: Text(barangay child: Text(
.description!)); barangay.description!));
}).toList(), }).toList(),
), ),
), ),
@ -353,20 +305,15 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
height: 60, height: 60,
child: FormBuilderDropdown<Country>( child: FormBuilderDropdown<Country>(
initialValue: null, initialValue: null,
validator: FormBuilderValidators validator: FormBuilderValidators.required(
.required( errorText: "This field is required"),
errorText: items: state.countries
"This field is required"), .map<DropdownMenuItem<Country>>(
items: state.countries.map<
DropdownMenuItem<
Country>>(
(Country country) { (Country country) {
return DropdownMenuItem< return DropdownMenuItem<Country>(
Country>(
value: country, value: country,
child: FittedBox( child: FittedBox(
child: Text( child: Text(country.name!)));
country.name!)));
}).toList(), }).toList(),
name: 'country', name: 'country',
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
@ -392,47 +339,35 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
width: double.infinity, width: double.infinity,
height: 60, height: 60,
child: ElevatedButton( child: ElevatedButton(
style: mainBtnStyle( style:
primary, Colors.transparent, second), mainBtnStyle(primary, Colors.transparent, second),
child: const Text(submit), child: const Text(submit),
onPressed: () { onPressed: () {
PersonalReference? personalReference; PersonalReference? personalReference;
if (formKey.currentState! if (formKey.currentState!.saveAndValidate()) {
.saveAndValidate()) { String lastname =
String lastname = formKey formKey.currentState!.value['lastname'];
.currentState!.value['lastname']; String firstname =
String firstname = formKey formKey.currentState!.value['firstname'];
.currentState!.value['firstname']; String middlename =
String middlename = formKey formKey.currentState!.value['middlename'];
.currentState! String mobile =
.value['middlename']; formKey.currentState!.value['mobile'];
String mobile = formKey
.currentState!.value['mobile'];
Region? region = selectedRegion; Region? region = selectedRegion;
Province? province = Province( Province? province = Province(
code: selectedProvince?.code, code: selectedProvince?.code,
description: description: selectedProvince?.description,
selectedProvince?.description,
region: region, region: region,
psgcCode: psgcCode: selectedProvince?.psgcCode,
selectedProvince?.psgcCode, shortname: selectedProvince?.shortname);
shortname: CityMunicipality? city = CityMunicipality(
selectedProvince?.shortname); code: selectedMunicipality?.code,
CityMunicipality? city =
CityMunicipality(
code: selectedMunicipality
?.code,
description: description:
selectedMunicipality selectedMunicipality?.description,
?.description,
province: province, province: province,
psgcCode: selectedMunicipality psgcCode: selectedMunicipality?.psgcCode,
?.psgcCode, zipcode: selectedMunicipality?.zipcode);
zipcode: selectedMunicipality
?.zipcode);
Address address = Address( Address address = Address(
id: null, id: null,
@ -443,13 +378,11 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
cityMunicipality: city); cityMunicipality: city);
if (selectedCountry != null) { if (selectedCountry != null) {
personalReference = personalReference = PersonalReference(
PersonalReference(
id: null, id: null,
address: Address( address: Address(
id: null, id: null,
addressCategory: addressCategory: selectedCategory,
selectedCategory,
country: selectedCountry, country: selectedCountry,
barangay: null, barangay: null,
cityMunicipality: null, cityMunicipality: null,
@ -459,8 +392,7 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
firstName: firstname, firstName: firstname,
middleName: middlename); middleName: middlename);
} else { } else {
personalReference = personalReference = PersonalReference(
PersonalReference(
id: null, id: null,
address: address, address: address,
lastName: lastname, lastName: lastname,
@ -468,14 +400,12 @@ class _AddReferenceScreenState extends State<AddReferenceScreen> {
firstName: firstname, firstName: firstname,
middleName: middlename); middleName: middlename);
} }
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait..."); progress!.showWithText("Please wait...");
context.read<ReferencesBloc>().add( context.read<ReferencesBloc>().add(AddReference(
AddReference( profileId: widget.profileId,
profileId:
int.parse(profileId!),
reference: personalReference, reference: personalReference,
token: token!)); token: widget.token));
} }
}, },
), ),
@ -486,14 +416,8 @@ progress!.showWithText("Please wait...");
], ],
)), )),
), ),
); ),
} ),
return Container();
},
);
}
return Container();
},
); );
} }
return Container(); return Container();

View File

@ -4,9 +4,7 @@ import 'package:flutter_form_builder/flutter_form_builder.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:form_builder_validators/form_builder_validators.dart'; import 'package:form_builder_validators/form_builder_validators.dart';
import 'package:modal_progress_hud_nsn/modal_progress_hud_nsn.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/profile/references/references_bloc.dart';
import '../../../../bloc/user/user_bloc.dart';
import '../../../../model/location/address_category.dart'; import '../../../../model/location/address_category.dart';
import '../../../../model/location/barangay.dart'; import '../../../../model/location/barangay.dart';
import '../../../../model/location/city.dart'; import '../../../../model/location/city.dart';
@ -21,7 +19,9 @@ import '../../../../utils/location_utilities.dart';
import '../../../../utils/text_container.dart'; import '../../../../utils/text_container.dart';
class EditReferenceScreen extends StatefulWidget { 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 @override
State<EditReferenceScreen> createState() => _EditReferenceScreenState(); State<EditReferenceScreen> createState() => _EditReferenceScreenState();
@ -29,8 +29,6 @@ class EditReferenceScreen extends StatefulWidget {
class _EditReferenceScreenState extends State<EditReferenceScreen> { class _EditReferenceScreenState extends State<EditReferenceScreen> {
final formKey = GlobalKey<FormBuilderState>(); final formKey = GlobalKey<FormBuilderState>();
String? token;
String? profileId;
bool provinceCall = false; bool provinceCall = false;
bool cityCall = false; bool cityCall = false;
bool barangayCall = false; bool barangayCall = false;
@ -48,14 +46,7 @@ class _EditReferenceScreenState extends State<EditReferenceScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
token = state.userData!.user!.login!.token;
profileId = state.userData!.user!.login!.user!.profileId.toString();
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocBuilder<ReferencesBloc, ReferencesState>( return BlocBuilder<ReferencesBloc, ReferencesState>(
buildWhen: (previous, current) => false, buildWhen: (previous, current) => false,
builder: (context, state) { builder: (context, state) {
@ -525,6 +516,10 @@ class _EditReferenceScreenState extends State<EditReferenceScreen> {
PersonalReference? personalReference; PersonalReference? personalReference;
if (formKey.currentState! if (formKey.currentState!
.saveAndValidate()) { .saveAndValidate()) {
final progress =
ProgressHUD.of(context);
progress!.showWithText(
"Please wait...");
String lastname = formKey String lastname = formKey
.currentState!.value['lastname']; .currentState!.value['lastname'];
String firstname = formKey String firstname = formKey
@ -607,9 +602,9 @@ class _EditReferenceScreenState extends State<EditReferenceScreen> {
context.read<ReferencesBloc>().add( context.read<ReferencesBloc>().add(
EditReference( EditReference(
profileId: profileId:
int.parse(profileId!), widget.profileId,
reference: personalReference, reference: personalReference,
token: token!)); token: widget.token));
} }
}, },
), ),
@ -624,14 +619,7 @@ class _EditReferenceScreenState extends State<EditReferenceScreen> {
} }
return Container(); return Container();
}, },
);
}
return Container();
},
);
}
return Container();
},
); );
} }
} }

View File

@ -26,25 +26,37 @@ class ReferencesScreen extends StatelessWidget {
int? profileId; int? profileId;
String? token; String? token;
return Scaffold( return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar( appBar: AppBar(
title: context.watch<ReferencesBloc>().state is AddReferenceState?const Text("Add Personal Reference"):context.watch<ReferencesBloc>().state is EditReferenceState?const Text("Edit Personal Reference"):const Text("Personal References"), title: context.watch<ReferencesBloc>().state is AddReferenceState
? const Text("Add Personal Reference")
: context.watch<ReferencesBloc>().state is EditReferenceState
? const Text("Edit Personal Reference")
: const Text("Personal References"),
centerTitle: true, centerTitle: true,
backgroundColor: primary, backgroundColor: primary,
////if state is adding or editing state show close button ////if state is adding or editing state show close button
actions: (context.watch<ReferencesBloc>().state is AddReferenceState || context.watch<ReferencesBloc>().state is EditReferenceState)? actions: (context.watch<ReferencesBloc>().state
[ is AddReferenceState ||
context.watch<ReferencesBloc>().state is EditReferenceState)
? [
//// close button //// close button
CloseLeading(onPressed: (){ CloseLeading(onPressed: () {
context.read<ReferencesBloc>().add(GetReferences(profileId: profileId!, token: token!)); context.read<ReferencesBloc>().add(
GetReferences(profileId: profileId!, token: token!));
}), }),
]: ]
:
//// if state is loaded state show add button //// if state is loaded state show add button
context.watch<ReferencesBloc>().state is ReferencesLoadedState?[ context.watch<ReferencesBloc>().state is ReferencesLoadedState
AddLeading(onPressed: (){ ? [
context.read<ReferencesBloc>().add(ShowAddReferenceForm()); AddLeading(onPressed: () {
context
.read<ReferencesBloc>()
.add(ShowAddReferenceForm());
}), }),
]:[] ]
), : []),
body: ProgressHUD( body: ProgressHUD(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
backgroundColor: Colors.black87, backgroundColor: Colors.black87,
@ -83,7 +95,7 @@ class ReferencesScreen extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ReferencesBloc>().add( context.read<ReferencesBloc>().add(
LoadReferences( LoadReferences(
references: state.personalRefs)); ));
}); });
} else { } else {
errorAlert(context, "Adding Failed", errorAlert(context, "Adding Failed",
@ -92,7 +104,7 @@ class ReferencesScreen extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ReferencesBloc>().add( context.read<ReferencesBloc>().add(
LoadReferences( LoadReferences(
references: state.personalRefs)); ));
}); });
} }
} }
@ -104,7 +116,7 @@ class ReferencesScreen extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ReferencesBloc>().add( context.read<ReferencesBloc>().add(
LoadReferences( LoadReferences(
references: state.personalRefs)); ));
}); });
} else { } else {
errorAlert(context, "Update Failed", errorAlert(context, "Update Failed",
@ -113,7 +125,7 @@ class ReferencesScreen extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ReferencesBloc>().add( context.read<ReferencesBloc>().add(
LoadReferences( LoadReferences(
references: state.personalRefs)); ));
}); });
} }
} }
@ -127,7 +139,7 @@ class ReferencesScreen extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ReferencesBloc>().add( context.read<ReferencesBloc>().add(
LoadReferences( LoadReferences(
references: state.references)); ));
}); });
} else { } else {
errorAlert(context, "Deletion Failed", errorAlert(context, "Deletion Failed",
@ -135,7 +147,7 @@ class ReferencesScreen extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ReferencesBloc>().add( context.read<ReferencesBloc>().add(
LoadReferences( LoadReferences(
references: state.references)); ));
}); });
} }
} }
@ -212,12 +224,14 @@ class ReferencesScreen extends StatelessWidget {
offset: const Offset(-10, -10), offset: const Offset(-10, -10),
elevation: 3, elevation: 3,
onSelected: (value) { onSelected: (value) {
////delete eligibilty-= = = = = = = = =>> ////delete eligibilty-= = = = = = = = =>>
if (value == 2) { if (value == 2) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
confirmAlert(context, () { confirmAlert(context, () {
final progress =
ProgressHUD.of(context);
progress!.showWithText(
"Please wait...");
context context
.read< .read<
ReferencesBloc>() ReferencesBloc>()
@ -236,6 +250,10 @@ progress!.showWithText("Please wait...");
} }
if (value == 1) { if (value == 1) {
////edit reference-= = = = = = = = =>> ////edit reference-= = = = = = = = =>>
final progress =
ProgressHUD.of(context);
progress!.showWithText(
"Please wait...");
context context
.read<ReferencesBloc>() .read<ReferencesBloc>()
.add(ShowEditReferenceForm( .add(ShowEditReferenceForm(
@ -276,14 +294,16 @@ progress!.showWithText("Please wait...");
} }
} }
if (state is AddReferenceState) { if (state is AddReferenceState) {
return const AddReferenceScreen(); return AddReferenceScreen(profileId: profileId!, token: token!,);
} }
if (state is EditReferenceState) { if (state is EditReferenceState) {
return const EditReferenceScreen(); return EditReferenceScreen(profileId: profileId!,token: token!,);
} }
if (state is ReferencesErrorState) { if (state is ReferencesErrorState) {
return SomethingWentWrong( return SomethingWentWrong(
message: state.message, onpressed: () {}); message: state.message, onpressed: () {
context.read<ReferencesBloc>().add(GetReferences(profileId: profileId!, token: token!));
});
} }
return Container(); return Container();
}, },

View File

@ -24,7 +24,9 @@ import 'package:unit2/utils/validators.dart';
import '../../../../model/utils/position.dart'; import '../../../../model/utils/position.dart';
class AddWorkHistoryScreen extends StatefulWidget { 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 @override
State<AddWorkHistoryScreen> createState() => _AddWorkHistoryScreenState(); State<AddWorkHistoryScreen> createState() => _AddWorkHistoryScreenState();
@ -65,14 +67,7 @@ class _AddWorkHistoryScreenState extends State<AddWorkHistoryScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
profileId = state.userData!.user!.login!.user!.profileId;
token = state.userData!.user!.login!.token;
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocConsumer<WorkHistoryBloc, WorkHistoryState>( return BlocConsumer<WorkHistoryBloc, WorkHistoryState>(
listener: (context, state) { listener: (context, state) {
if (state is AddWorkHistoryState) { if (state is AddWorkHistoryState) {
@ -121,6 +116,7 @@ class _AddWorkHistoryScreenState extends State<AddWorkHistoryScreen> {
positionFocusNode.unfocus(); positionFocusNode.unfocus();
}); });
}, },
////EMPTY WIDGET
emptyWidget: Container( emptyWidget: Container(
decoration: box1(), decoration: box1(),
height: 100, height: 100,
@ -139,6 +135,7 @@ class _AddWorkHistoryScreenState extends State<AddWorkHistoryScreen> {
), ),
TextButton( TextButton(
onPressed: () { onPressed: () {
////ADD POSITION DIALOG
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext builder: (BuildContext
@ -638,12 +635,7 @@ class _AddWorkHistoryScreenState extends State<AddWorkHistoryScreen> {
Flexible( Flexible(
flex: 1, flex: 1,
child: DateTimePicker( child: DateTimePicker(
validator: (value) { validator: FormBuilderValidators.required(errorText: "This field is required"),
if (value == null) {
return "This field is required";
}
return null;
},
use24HourFormat: false, use24HourFormat: false,
icon: const Icon( icon: const Icon(
Icons.date_range), Icons.date_range),
@ -684,9 +676,7 @@ class _AddWorkHistoryScreenState extends State<AddWorkHistoryScreen> {
.copyWith(), .copyWith(),
) )
: DateTimePicker( : DateTimePicker(
validator: (val) { validator: FormBuilderValidators.required(errorText: "This field is required"),
return null;
},
controller: controller:
toDateController, toDateController,
firstDate: DateTime(1970), firstDate: DateTime(1970),
@ -723,17 +713,12 @@ class _AddWorkHistoryScreenState extends State<AddWorkHistoryScreen> {
style: mainBtnStyle( style: mainBtnStyle(
primary, Colors.transparent, second), primary, Colors.transparent, second),
onPressed: () { 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()) { if (_formKey.currentState!.validate()) {
final progress =
ProgressHUD.of(context);
progress!.showWithText(
"Loading...");
WorkHistory workHistory = WorkHistory( WorkHistory workHistory = WorkHistory(
position: selectedPosition, position: selectedPosition,
id: null, id: null,
@ -783,14 +768,4 @@ class _AddWorkHistoryScreenState extends State<AddWorkHistoryScreen> {
return Container(); return Container();
}); });
} }
return Container();
},
);
}
return const Center(
child: Text("Add Work History"),
);
},
);
}
} }

View File

@ -23,7 +23,10 @@ import '../../../../utils/text_container.dart';
import '../../../../utils/validators.dart'; import '../../../../utils/validators.dart';
class EditWorkHistoryScreen extends StatefulWidget { 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 @override
State<EditWorkHistoryScreen> createState() => _EditWorkHistoryScreenState(); State<EditWorkHistoryScreen> createState() => _EditWorkHistoryScreenState();
@ -73,36 +76,20 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BlocBuilder<UserBloc, UserState>( return BlocBuilder<UserBloc, UserState>(builder: (context, state) {
return BlocBuilder<WorkHistoryBloc, WorkHistoryState>(
builder: (context, state) { builder: (context, state) {
if (state is UserLoggedIn) {
profileId = state.userData!.user!.login!.user!.profileId;
token = state.userData!.user!.login!.token;
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocConsumer<WorkHistoryBloc, WorkHistoryState>(
listener: (context, state) {
if (state is AddWorkHistoryState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
}, builder: (context, state) {
if (state is EditWorkHistoryState) { if (state is EditWorkHistoryState) {
oldPositionController.text = oldPositionController.text = state.workHistory.position!.title!;
state.workHistory.position!.title!;
oldAppointmentStatusController.text = oldAppointmentStatusController.text =
state.workHistory.appointmentStatus!; state.workHistory.appointmentStatus!;
oldAgencyController.text = state.workHistory.agency!.name!; oldAgencyController.text = state.workHistory.agency!.name!;
currentlyEmployed = currentlyEmployed = state.workHistory.toDate == null ? true : false;
state.workHistory.toDate == null ? true : false;
showSalaryGradeAndSalaryStep = showSalaryGradeAndSalaryStep =
!state.workHistory.agency!.privateEntity!; !state.workHistory.agency!.privateEntity!;
fromDateController.text = fromDateController.text = state.workHistory.fromDate.toString();
state.workHistory.fromDate.toString();
toDateController.text = state.workHistory.toDate.toString(); toDateController.text = state.workHistory.toDate.toString();
currentlyEmployed = currentlyEmployed = state.workHistory.toDate == null ? true : false;
state.workHistory.toDate == null ? true : false;
return SingleChildScrollView( return SingleChildScrollView(
child: SizedBox( child: SizedBox(
@ -121,24 +108,21 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
itemHeight: 50, itemHeight: 50,
suggestionsDecoration: box1(), suggestionsDecoration: box1(),
suggestions: state.agencyPositions suggestions: state.agencyPositions
.map((Position position) => .map((Position position) => SearchFieldListItem(
SearchFieldListItem(position.title!, position.title!,
item: position, item: position,
child: Padding( child: Padding(
padding: const EdgeInsets padding: const EdgeInsets.symmetric(
.symmetric(
horizontal: 10), horizontal: 10),
child: ListTile( child: ListTile(
title: title: Text(position.title!),
Text(position.title!),
)))) ))))
.toList(), .toList(),
focusNode: positionFocusNode, focusNode: positionFocusNode,
searchInputDecoration: searchInputDecoration:
normalTextFieldStyle("Position *", "") normalTextFieldStyle("Position *", "").copyWith(
.copyWith( suffixIcon:
suffixIcon: const Icon( const Icon(Icons.arrow_drop_down)),
Icons.arrow_drop_down)),
onSuggestionTap: (position) { onSuggestionTap: (position) {
setState(() { setState(() {
selectedPosition = position.item; selectedPosition = position.item;
@ -149,10 +133,8 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
decoration: box1(), decoration: box1(),
height: 100, height: 100,
child: Column( child: Column(
mainAxisAlignment: mainAxisAlignment: MainAxisAlignment.center,
MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
crossAxisAlignment:
CrossAxisAlignment.center,
children: [ children: [
const SizedBox( const SizedBox(
height: 20, height: 20,
@ -165,8 +147,7 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
onPressed: () { onPressed: () {
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext builder: (BuildContext context) {
context) {
return AlertDialog( return AlertDialog(
title: const Text( title: const Text(
"Add Position?"), "Add Position?"),
@ -179,42 +160,51 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
addPositionController, addPositionController,
decoration: decoration:
normalTextFieldStyle( normalTextFieldStyle(
"", "", ""),
""),
), ),
const SizedBox( const SizedBox(
height: 12, height: 12,
), ),
SizedBox( SizedBox(
width: double width:
.infinity, double.infinity,
height: 50, height: 50,
child: ElevatedButton( child:
style: mainBtnStyle(primary, Colors.transparent, second), ElevatedButton(
onPressed: () { style: mainBtnStyle(
primary,
Colors
.transparent,
second),
onPressed:
() {
setState( setState(
() { () {
Position Position
newAgencyPosition = newAgencyPosition =
Position(id: null, title: addPositionController.text.toUpperCase()); Position(
state.agencyPositions.insert(0, id: null,
title: addPositionController.text.toUpperCase());
state.agencyPositions.insert(
0,
newAgencyPosition); newAgencyPosition);
selectedPosition = selectedPosition =
newAgencyPosition; newAgencyPosition;
addPositionController.text = addPositionController.text =
""; "";
Navigator.pop(context); Navigator.pop(
context);
}); });
}, },
child: const Text("Add"))), child: const Text(
"Add"))),
], ],
), ),
), ),
); );
}); });
}, },
child: child: const Text("Add position"))
const Text("Add position"))
]), ]),
), ),
validator: (position) { validator: (position) {
@ -247,11 +237,11 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
selectedStatus = status.item; selectedStatus = status.item;
appointmentStatusNode.unfocus(); appointmentStatusNode.unfocus();
}, },
searchInputDecoration: normalTextFieldStyle( searchInputDecoration:
"Appointment Status", "") normalTextFieldStyle("Appointment Status", "")
.copyWith( .copyWith(
suffixIcon: const Icon( suffixIcon:
Icons.arrow_drop_down)), const Icon(Icons.arrow_drop_down)),
), ),
const SizedBox( const SizedBox(
@ -268,45 +258,38 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
focusNode: agencyFocusNode, focusNode: agencyFocusNode,
suggestions: state.agencies suggestions: state.agencies
.map((Agency agency) => .map((Agency agency) =>
SearchFieldListItem( SearchFieldListItem(agency.name!,
agency.name!,
item: agency, item: agency,
child: ListTile( child: ListTile(
title: Text( title: Text(
agency.name!, agency.name!,
overflow: TextOverflow overflow: TextOverflow.ellipsis,
.ellipsis,
), ),
subtitle: Text( subtitle: Text(
agency.privateEntity == agency.privateEntity == true
true
? "Private" ? "Private"
: "Government"), : "Government"),
))) )))
.toList(), .toList(),
searchInputDecoration: searchInputDecoration: normalTextFieldStyle(
normalTextFieldStyle("Agency *", "") "Agency *", "")
.copyWith( .copyWith(
suffixIcon: const Icon( suffixIcon:
Icons.arrow_drop_down)), const Icon(Icons.arrow_drop_down)),
onSuggestionTap: (agency) { onSuggestionTap: (agency) {
setState(() { setState(() {
selectedAgency = agency.item; selectedAgency = agency.item;
if (selectedAgency!.privateEntity == if (selectedAgency!.privateEntity == null) {
null) {
showIsPrivateRadio = true; showIsPrivateRadio = true;
} else { } else {
showIsPrivateRadio = false; showIsPrivateRadio = false;
} }
if (selectedAgency!.privateEntity == if (selectedAgency!.privateEntity == true) {
true) { showSalaryGradeAndSalaryStep = false;
showSalaryGradeAndSalaryStep =
false;
} }
if (selectedAgency!.privateEntity == if (selectedAgency!.privateEntity ==
false) { false) {
showSalaryGradeAndSalaryStep = showSalaryGradeAndSalaryStep = true;
true;
} }
agencyFocusNode.unfocus(); agencyFocusNode.unfocus();
}); });
@ -337,8 +320,8 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
onPressed: () { onPressed: () {
showDialog( showDialog(
context: context, context: context,
builder: (BuildContext builder:
context) { (BuildContext context) {
return AlertDialog( return AlertDialog(
title: const Text( title: const Text(
"Add Position"), "Add Position"),
@ -351,42 +334,55 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
addAgencyController, addAgencyController,
decoration: decoration:
normalTextFieldStyle( normalTextFieldStyle(
"", "", ""),
""),
), ),
const SizedBox( const SizedBox(
height: height: 12,
12,
), ),
SizedBox( SizedBox(
width: double width: double
.infinity, .infinity,
height: height: 50,
50, child:
child: ElevatedButton( ElevatedButton(
style: mainBtnStyle(primary, Colors.transparent, second), style: mainBtnStyle(
onPressed: () { primary,
setState(() { Colors
Agency newAgency = Agency(id: null, name: addAgencyController.text.toUpperCase(), category: null, privateEntity: null); .transparent,
state.agencies.insert(0, newAgency); second),
selectedAgency = newAgency; onPressed:
addAgencyController.text = ""; () {
showAgencyCategory = true; 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;
showIsPrivateRadio = true; showIsPrivateRadio =
true;
Navigator.pop(context); Navigator.pop(context);
}); });
}, },
child: const Text("Add"))), child: const Text(
"Add"))),
], ],
), ),
), ),
); );
}); });
}, },
child: const Text( child: const Text("Add Agency"))
"Add Agency"))
]), ]),
), ),
), ),
@ -398,21 +394,17 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
SizedBox( SizedBox(
child: showAgencyCategory child: showAgencyCategory
? SearchField( ? SearchField(
focusNode: focusNode: agencyCategoryFocusNode,
agencyCategoryFocusNode,
itemHeight: 70, itemHeight: 70,
suggestions: state suggestions: state.agencyCategory
.agencyCategory
.map((Category category) => .map((Category category) =>
SearchFieldListItem( SearchFieldListItem(
category.name!, category.name!,
item: category, item: category,
child: ListTile( child: ListTile(
title: Text( title:
category Text(category.name!),
.name!), subtitle: Text(category
subtitle: Text(
category
.industryClass! .industryClass!
.name!), .name!),
))) )))
@ -421,20 +413,17 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
height: 100, height: 100,
decoration: box1(), decoration: box1(),
child: const Center( child: const Center(
child: Text( child:
"No result found ...")), Text("No result found ...")),
), ),
onSuggestionTap: onSuggestionTap: (agencyCategory) {
(agencyCategory) {
setState(() { setState(() {
selectedAgencyCategory = selectedAgencyCategory =
agencyCategory.item; agencyCategory.item;
agencyCategoryFocusNode agencyCategoryFocusNode.unfocus();
.unfocus();
selectedAgency = Agency( selectedAgency = Agency(
id: null, id: null,
name: selectedAgency! name: selectedAgency!.name,
.name,
category: category:
selectedAgencyCategory, selectedAgencyCategory,
privateEntity: null); privateEntity: null);
@ -444,9 +433,8 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
normalTextFieldStyle( normalTextFieldStyle(
"Category *", "") "Category *", "")
.copyWith( .copyWith(
suffixIcon: suffixIcon: const Icon(
const Icon(Icons Icons.arrow_drop_down)),
.arrow_drop_down)),
validator: (value) { validator: (value) {
if (value!.isEmpty) { if (value!.isEmpty) {
return "This field is required"; return "This field is required";
@ -467,15 +455,13 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
children: [ children: [
Text( Text(
"Is this private sector? ", "Is this private sector? ",
style: Theme.of( style: Theme.of(context)
context)
.textTheme .textTheme
.headlineSmall! .headlineSmall!
.copyWith( .copyWith(fontSize: 24),
fontSize: 24),
), ),
const Icon(FontAwesome const Icon(
.help_circled) FontAwesome.help_circled)
], ],
), ),
), ),
@ -483,8 +469,7 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
////onvhange private sector ////onvhange private sector
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
if (value.toString() == if (value.toString() == "YES") {
"YES") {
isPrivate = true; isPrivate = true;
showSalaryGradeAndSalaryStep = showSalaryGradeAndSalaryStep =
false; false;
@ -495,24 +480,20 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
} }
selectedAgency = Agency( selectedAgency = Agency(
id: null, id: null,
name: selectedAgency! name: selectedAgency!.name,
.name,
category: category:
selectedAgencyCategory, selectedAgencyCategory,
privateEntity: privateEntity: value == "YES"
value == "YES"
? true ? true
: false); : false);
agencyFocusNode.unfocus(); agencyFocusNode.unfocus();
agencyCategoryFocusNode agencyCategoryFocusNode.unfocus();
.unfocus();
}); });
}, },
name: 'isPrivate', name: 'isPrivate',
validator: validator:
FormBuilderValidators FormBuilderValidators.required(),
.required(),
options: ["YES", "NO"] options: ["YES", "NO"]
.map((lang) => .map((lang) =>
FormBuilderFieldOption( FormBuilderFieldOption(
@ -521,9 +502,7 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
) )
: const SizedBox()), : const SizedBox()),
SizedBox( SizedBox(
height: showSalaryGradeAndSalaryStep height: showSalaryGradeAndSalaryStep ? 12 : 0,
? 12
: 0,
), ),
////SALARY GRADE AND SALARY GRADE STEP ////SALARY GRADE AND SALARY GRADE STEP
SizedBox( SizedBox(
@ -535,17 +514,13 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
////SALARY GRADE ////SALARY GRADE
Flexible( Flexible(
flex: 1, flex: 1,
child: child: FormBuilderTextField(
FormBuilderTextField(
initialValue: state initialValue: state
.workHistory .workHistory.salaryGrade
.salaryGrade
?.toString(), ?.toString(),
name: name: 'salary_grade',
'salary_grade',
keyboardType: keyboardType:
TextInputType TextInputType.number,
.number,
decoration: decoration:
normalTextFieldStyle( normalTextFieldStyle(
"Salary Grade (SG)", "Salary Grade (SG)",
@ -563,16 +538,13 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
//// SALARY STEP //// SALARY STEP
Flexible( Flexible(
flex: 1, flex: 1,
child: child: FormBuilderTextField(
FormBuilderTextField(
initialValue: state initialValue: state
.workHistory .workHistory.sgStep
.sgStep
?.toString(), ?.toString(),
name: 'salary_step', name: 'salary_step',
keyboardType: keyboardType:
TextInputType TextInputType.number,
.number,
decoration: decoration:
normalTextFieldStyle( normalTextFieldStyle(
"SG Step (SG)", "SG Step (SG)",
@ -597,8 +569,8 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
), ),
////MONTHLY SALARY ////MONTHLY SALARY
FormBuilderTextField( FormBuilderTextField(
initialValue: state.workHistory.monthlySalary initialValue:
.toString(), state.workHistory.monthlySalary.toString(),
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
salary = value; salary = value;
@ -606,8 +578,8 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
}, },
validator: numericRequired, validator: numericRequired,
name: "salary", name: "salary",
decoration: normalTextFieldStyle( decoration:
"Monthly Salary *", "") normalTextFieldStyle("Monthly Salary *", "")
.copyWith(prefix: const Text("")), .copyWith(prefix: const Text("")),
), ),
@ -632,11 +604,9 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
} }
}); });
}, },
decoration: decoration: normalTextFieldStyle("", ''),
normalTextFieldStyle("", ''),
name: 'overseas', name: 'overseas',
title: title: const Text("Currently Employed?"),
const Text("Currently Employed?"),
), ),
const SizedBox( const SizedBox(
height: 12, height: 12,
@ -649,28 +619,21 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
Flexible( Flexible(
flex: 1, flex: 1,
child: DateTimePicker( child: DateTimePicker(
validator: (value) { validator:
if (value == null) { FormBuilderValidators.required(
return "This field is required"; errorText:
} "This field is required"),
return null;
},
use24HourFormat: false, use24HourFormat: false,
icon: const Icon( icon: const Icon(Icons.date_range),
Icons.date_range), controller: fromDateController,
controller:
fromDateController,
firstDate: DateTime(1970), firstDate: DateTime(1970),
lastDate: DateTime(2100), lastDate: DateTime(2100),
timeHintText: timeHintText:
"Date of Examination/Conferment", "Date of Examination/Conferment",
decoration: decoration: normalTextFieldStyle(
normalTextFieldStyle( "From *", "From *")
"From *",
"From *")
.copyWith( .copyWith(
prefixIcon: prefixIcon: const Icon(
const Icon(
Icons.date_range, Icons.date_range,
color: Colors.black87, color: Colors.black87,
)), )),
@ -687,35 +650,29 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
enabled: false, enabled: false,
initialValue: "PRESENT", initialValue: "PRESENT",
style: const TextStyle( style: const TextStyle(
color: color: Colors.black45),
Colors.black45), decoration: normalTextFieldStyle(
decoration:
normalTextFieldStyle(
"", "") "", "")
.copyWith( .copyWith(
prefixIcon: prefixIcon: const Icon(
const Icon(
Icons.date_range, Icons.date_range,
color: Colors.black45, color: Colors.black45,
)), )),
) )
: DateTimePicker( : DateTimePicker(
validator: (val) { validator: FormBuilderValidators
return null; .required(
}, errorText:
controller: "This field is required"),
toDateController, controller: toDateController,
firstDate: DateTime(1970), firstDate: DateTime(1970),
lastDate: DateTime(2100), lastDate: DateTime(2100),
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"To *", "To *") "To *", "To *")
.copyWith( .copyWith(
prefixIcon: prefixIcon: const Icon(
const Icon( Icons.date_range,
Icons color: Colors.black87,
.date_range,
color: Colors
.black87,
), ),
prefixText: prefixText:
currentlyEmployed currentlyEmployed
@ -739,37 +696,33 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
style: mainBtnStyle( style: mainBtnStyle(
primary, Colors.transparent, second), primary, Colors.transparent, second),
onPressed: () { onPressed: () {
if (_formKey.currentState! if (_formKey.currentState!.saveAndValidate()) {
.saveAndValidate()) { final progress = ProgressHUD.of(context);
salary = _formKey progress!.showWithText("Loading...");
.currentState!.value['salary']; salary =
_formKey.currentState!.value['salary'];
selectedPosition ??= selectedPosition ??=
state.workHistory.position; state.workHistory.position;
salaryGrade = _formKey.currentState! salaryGrade = _formKey
.value['salary_grade']; .currentState!.value['salary_grade'];
salaryGradeStep = _formKey salaryGradeStep = _formKey
.currentState! .currentState!.value['salary_step'];
.value['salary_step']; selectedAgency ??= state.workHistory.agency;
selectedAgency ??=
state.workHistory.agency;
selectedStatus ??= AppoinemtStatus( selectedStatus ??= AppoinemtStatus(
value: state.workHistory value:
.appointmentStatus!, state.workHistory.appointmentStatus!,
label: state.workHistory label:
.appointmentStatus!); state.workHistory.appointmentStatus!);
WorkHistory newWorkHistory = WorkHistory newWorkHistory = WorkHistory(
WorkHistory(
id: state.workHistory.id, id: state.workHistory.id,
position: selectedPosition, position: selectedPosition,
agency: selectedAgency, agency: selectedAgency,
fromDate: fromDateController fromDate: fromDateController.text.isEmpty
.text.isEmpty
? null ? null
: DateTime.parse( : DateTime.parse(
fromDateController.text), fromDateController.text),
toDate: toDateController toDate: toDateController.text.isEmpty ||
.text.isEmpty ||
toDateController.text toDateController.text
.toUpperCase() == .toUpperCase() ==
"PRESENT" || "PRESENT" ||
@ -777,12 +730,9 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
.toLowerCase() == .toLowerCase() ==
'null' 'null'
? null ? null
: DateTime.parse( : DateTime.parse(toDateController.text),
toDateController.text), monthlySalary: double.parse(salary!),
monthlySalary: appointmentStatus: selectedStatus!.value,
double.parse(salary!),
appointmentStatus:
selectedStatus!.value,
salaryGrade: salaryGrade == null salaryGrade: salaryGrade == null
? null ? null
: int.parse(salaryGrade!), : int.parse(salaryGrade!),
@ -792,10 +742,8 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
); );
context.read<WorkHistoryBloc>().add( context.read<WorkHistoryBloc>().add(
UpdateWorkHistory( UpdateWorkHistory(
oldWorkHistory: oldWorkHistory: state.workHistory,
state.workHistory, profileId: profileId.toString(),
profileId:
profileId.toString(),
token: token!, token: token!,
workHistory: newWorkHistory)); workHistory: newWorkHistory));
} }
@ -812,17 +760,11 @@ class _EditWorkHistoryScreenState extends State<EditWorkHistoryScreen> {
), ),
); );
} }
return Container();
});
}
return Container();
},
);
}
return const Center( return const Center(
child: Text("Add Work History"), child: Text("Add Work History"),
); );
}, },
); );
});
} }
} }

View File

@ -1,5 +1,4 @@
import 'dart:io'; import 'dart:io';
import 'package:app_popup_menu/app_popup_menu.dart'; import 'package:app_popup_menu/app_popup_menu.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.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/theme-data.dart/colors.dart';
import 'package:unit2/utils/text_container.dart'; import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/Leadings/add_leading.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/empty_data.dart';
import 'package:unit2/widgets/error_state.dart'; import 'package:unit2/widgets/error_state.dart';
@ -36,11 +36,15 @@ class WorkHistoryScreen extends StatelessWidget {
title: const Text(workHistoryScreenTitle), title: const Text(workHistoryScreenTitle),
backgroundColor: primary, backgroundColor: primary,
centerTitle: true, centerTitle: true,
actions: [ actions: context.watch<WorkHistoryBloc>().state is WorkHistoryLoaded?[
AddLeading(onPressed: () { AddLeading(onPressed: () {
context.read<WorkHistoryBloc>().add(ShowAddWorkHistoryForm()); context.read<WorkHistoryBloc>().add(ShowAddWorkHistoryForm());
}) })
], ]:(context.watch<WorkHistoryBloc>().state is AddWorkHistoryState || context.watch<WorkHistoryBloc>().state is EditWorkHistoryState)?[
CloseLeading(onPressed: (){
context.read<WorkHistoryBloc>().add(LoadWorkHistories());
})
]:[],
), ),
body: body:
//UserBloc //UserBloc
@ -68,7 +72,9 @@ class WorkHistoryScreen extends StatelessWidget {
} }
if (state is WorkHistoryLoaded || if (state is WorkHistoryLoaded ||
state is WorkHistoryErrorState || 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); final progress = ProgressHUD.of(context);
progress!.dismiss(); progress!.dismiss();
} }
@ -78,55 +84,59 @@ class WorkHistoryScreen extends StatelessWidget {
successAlert(context, "Deletion Successfull", successAlert(context, "Deletion Successfull",
"Work has been deleted successfully", () { "Work has been deleted successfully", () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<WorkHistoryBloc>().add( context
LoadWorkHistories( .read<WorkHistoryBloc>()
workHistories: state.workHistories)); .add(LoadWorkHistories());
}); });
} else { } else {
errorAlert(context, "Deletion Failed", errorAlert(context, "Deletion Failed",
"Error deleting Work History", () { "Error deleting Work History", () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<WorkHistoryBloc>().add( context
LoadWorkHistories( .read<WorkHistoryBloc>()
workHistories: state.workHistories)); .add(LoadWorkHistories());
}); });
} }
} }
////ADDED STATE ////ADDED STATE
if(state is WorkHistoryAddedState){ if (state is WorkHistoryAddedState) {
if (state.response['success']) { if (state.response['success']) {
successAlert(context, "Adding Successfull!", successAlert(context, "Adding Successfull!",
state.response['message'], () { state.response['message'], () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<WorkHistoryBloc>().add(LoadWorkHistories( context
workHistories: state.workExperiences)); .read<WorkHistoryBloc>()
.add(LoadWorkHistories());
}); });
} else { } else {
errorAlert(context, "Adding Failed", errorAlert(context, "Adding Failed",
"Something went wrong. Please try again.", "Something went wrong. Please try again.",
() { () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<WorkHistoryBloc>().add(LoadWorkHistories( context
workHistories: state.workExperiences)); .read<WorkHistoryBloc>()
.add(LoadWorkHistories());
}); });
} }
} }
//// EDITED STATE //// EDITED STATE
if(state is WorkHistoryEditedState){ if (state is WorkHistoryEditedState) {
if (state.response['success']) { if (state.response['success']) {
successAlert(context, "Update Successfull!", successAlert(context, "Update Successfull!",
state.response['message'], () { state.response['message'], () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<WorkHistoryBloc>().add(LoadWorkHistories( context
workHistories: state.workExperiences)); .read<WorkHistoryBloc>()
.add(LoadWorkHistories());
}); });
} else { } else {
errorAlert(context, "Update Failed", errorAlert(context, "Update Failed",
"Something went wrong. Please try again.", "Something went wrong. Please try again.",
() { () {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<WorkHistoryBloc>().add(LoadWorkHistories( context
workHistories: state.workExperiences)); .read<WorkHistoryBloc>()
.add(LoadWorkHistories());
}); });
} }
} }
@ -207,31 +217,41 @@ class WorkHistoryScreen extends StatelessWidget {
offset: const Offset(-10, -10), offset: const Offset(-10, -10),
elevation: 3, elevation: 3,
onSelected: (value) { onSelected: (value) {
final progress =
ProgressHUD.of(context);
progress!
.showWithText("Loading...");
////delete workhistory-= = = = = = = = =>> ////delete workhistory-= = = = = = = = =>>
if (value == 2) { if (value == 2) {
confirmAlert(context, () { confirmAlert(context, () {
BlocProvider.of<WorkHistoryBloc>( final progress =
ProgressHUD.of(context);
progress!.showWithText(
"Loading...");
BlocProvider.of<
WorkHistoryBloc>(
context) context)
.add(DeleteWorkHistory( .add(DeleteWorkHistory(
profileId: profileId: profileId,
profileId,
token: token!, token: token!,
workHistory: state workHistory:
.workExperiences[ state.workExperiences[
index], index],
workHistories: state ));
.workExperiences));
}, "Delete?", }, "Delete?",
"Confirm Delete?"); "Confirm Delete?");
} }
if (value == 1) { if (value == 1) {
////edit eligibilty-= = = = = = = = =>> ////edit eligibilty-= = = = = = = = =>>
WorkHistory workHistory = state.workExperiences[index]; final progress =
context.read<WorkHistoryBloc>().add(ShowEditWorkHistoryForm(workHistory: workHistory)); ProgressHUD.of(context);
progress!.showWithText(
"Loading...");
WorkHistory workHistory =
state.workExperiences[
index];
context
.read<WorkHistoryBloc>()
.add(
ShowEditWorkHistoryForm(
workHistory:
workHistory));
} }
}, },
menuItems: [ menuItems: [
@ -269,14 +289,16 @@ class WorkHistoryScreen extends StatelessWidget {
} }
} }
if (state is AddWorkHistoryState) { if (state is AddWorkHistoryState) {
return const AddWorkHistoryScreen(); return AddWorkHistoryScreen(profileId: profileId, token: token!,);
} }
if(state is EditWorkHistoryState){ if (state is EditWorkHistoryState) {
return const EditWorkHistoryScreen(); return EditWorkHistoryScreen(profileId: profileId,token: token!,);
} }
if (state is WorkHistoryErrorState) { if (state is WorkHistoryErrorState) {
return SomethingWentWrong( return SomethingWentWrong(
message: state.message, onpressed: () {}); message: state.message, onpressed: () {
context.read<WorkHistoryBloc>().add(GetWorkHistories(profileId: profileId,token: token!));
});
} }
return Container(); return Container();
}, },

View File

@ -10,7 +10,8 @@ class CoverImage extends StatelessWidget {
color: Colors.grey, color: Colors.grey,
child: CachedNetworkImage( child: CachedNetworkImage(
imageUrl: 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, width: double.infinity,
height: 220, height: 220,
fit: BoxFit.cover, fit: BoxFit.cover,

View File

@ -21,12 +21,15 @@ Widget getTile(
if (title.toLowerCase() == "logout") { if (title.toLowerCase() == "logout") {
confirmAlert(context, () async{ confirmAlert(context, () async{
await CREDENTIALS!.clear(); await CREDENTIALS!.clear();
await CREDENTIALS!.deleteAll(['username','password','saved']);
Navigator.pushReplacementNamed (context,"/"); Navigator.pushReplacementNamed (context,"/");
},"Logout","Are You sure you want to logout?"); },"Logout","Are You sure you want to logout?");
}if(title.toLowerCase() == 'profile'){ }if(title.toLowerCase() == 'profile'){
ProfileArguments profileArguments = ProfileArguments(token: userData.user!.login!.token!, userID:userData.user!.login!.user!.profileId!); ProfileArguments profileArguments = ProfileArguments(token: userData.user!.login!.token!, userID:userData.user!.login!.user!.profileId!);
Navigator.pushNamed(context, route,arguments: profileArguments); Navigator.pushNamed(context, route,arguments: profileArguments);
}if(title.toLowerCase() == 'basic info'){
Navigator.pushNamed(context, '/basic-info');
} }
}, },

View File

@ -36,6 +36,7 @@ class _UniT2LoginState extends State<UniT2Login> {
bool showSuffixIcon = false; bool showSuffixIcon = false;
bool _showPassword = true; bool _showPassword = true;
String? password; String? password;
String? username;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return WillPopScope( return WillPopScope(
@ -236,7 +237,7 @@ class _UniT2LoginState extends State<UniT2Login> {
TextStyle(color: Colors.white), TextStyle(color: Colors.white),
), ),
onPressed: () { onPressed: () {
password = "nav071394";
final progress = final progress =
ProgressHUD.of(context); ProgressHUD.of(context);
@ -244,20 +245,21 @@ class _UniT2LoginState extends State<UniT2Login> {
if (_formKey.currentState! if (_formKey.currentState!
.saveAndValidate()) { .saveAndValidate()) {
password = _formKey
.currentState!
.value['password'];
username = _formKey
.currentState!
.value['username'];
progress?.showWithText( progress?.showWithText(
'Logging in...', 'Logging in...',
); );
BlocProvider.of<UserBloc>(context) BlocProvider.of<UserBloc>(context)
.add(UserLogin( .add(UserLogin(
username: "rjvincentlopeplopez",
password: "shesthequ33n", username:username,
// username: _formKey password: password
// .currentState!
// .value['username'],
// password: _formKey
// .currentState!
// .value['password'])
)); ));
} }
}, },

View File

@ -9,11 +9,11 @@ class ContactService {
static final ContactService _instance = ContactService(); static final ContactService _instance = ContactService();
static ContactService get instance => _instance; static ContactService get instance => _instance;
Future<List<ServiceProvider>> getServiceProvider( Future<List<CommService>> getServiceProvider(
{required int serviceTypeId}) async { {required int serviceTypeId}) async {
String path = Url.instance.getServiceType(); String path = Url.instance.getCommunicationProvider();
Map<String, String> params = {"service_type__id": serviceTypeId.toString()}; Map<String, String> params = {"service_type__id": serviceTypeId.toString()};
List<ServiceProvider> serviceProviders = []; List<CommService> serviceProviders = [];
Map<String, String> headers = { Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
}; };
@ -25,7 +25,7 @@ class ContactService {
if (data['data'] != null) { if (data['data'] != null) {
for (var element in data['data']) { for (var element in data['data']) {
CommService commService = CommService.fromJson(element); CommService commService = CommService.fromJson(element);
serviceProviders.add(commService.serviceProvider!); serviceProviders.add(commService);
} }
} }
} }
@ -52,7 +52,7 @@ class ContactService {
"_numbermail": contactInfo.numbermail, "_numbermail": contactInfo.numbermail,
"_active": contactInfo.active, "_active": contactInfo.active,
"_primary": contactInfo.primary, "_primary": contactInfo.primary,
"_commServiceId": contactInfo.commService!.serviceProvider!.id! "_commServiceId": contactInfo.commService!.id
}; };
Map<dynamic, dynamic> responseStatus = {}; Map<dynamic, dynamic> responseStatus = {};
try { try {
@ -71,24 +71,38 @@ class ContactService {
} }
//// add //// add
// Future<Map<dynamic, dynamic>> update( Future<Map<dynamic, dynamic>> add(
// {required int profileId, {required int profileId,
// required String token, required String token,
// required ContactInfo contactInfo}) async { required ContactInfo contactInfo}) async {
// String path = "${Url.instance.contactPath()}$profileId/"; String path = "${Url.instance.contactPath()}$profileId/";
// String authToken = "Token $token"; String authToken = "Token $token";
// Map<String, String> headers = { Map<String, String> headers = {
// 'Content-Type': 'application/json; charset=UTF-8', 'Content-Type': 'application/json; charset=UTF-8',
// 'Authorization': authToken 'Authorization': authToken
// }; };
// Map body ={ Map<dynamic, dynamic> responseStatus = {};
// "personid": profileId, Map body = {
// "_numbermail": contactInfo.numbermail, "personid": profileId,
// "_active": contactInfo.active, "_numbermail": contactInfo.numbermail,
// "_primary": contactInfo.primary, "_active": contactInfo.active,
// "_commServiceId": contactInfo "_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 ////delete
Future<bool> deleteContact( Future<bool> deleteContact(
@ -116,7 +130,7 @@ class ContactService {
try { try {
http.Response response = await Request.instance.deleteRequest( http.Response response = await Request.instance.deleteRequest(
path: path, headers: headers, body: body, param: params); path: path, headers: headers, body: body, param: params);
if (response.statusCode == 20) { if (response.statusCode == 200) {
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
success = data['success']; success = data['success'];
} }

View File

@ -4,10 +4,10 @@ class Url {
String host() { String host() {
// return '192.168.10.221:3003'; // return '192.168.10.221:3003';
// return 'agusandelnorte.gov.ph'; return 'agusandelnorte.gov.ph';
// return "192.168.10.219:3000"; // return "192.168.10.219:3000";
// return "devweb.agusandelnorte.gov.ph"; // return "devweb.agusandelnorte.gov.ph";
return 'devapi.agusandelnorte.gov.ph:3004'; // return 'devapi.agusandelnorte.gov.ph:3004';
} }
String authentication() { String authentication() {
@ -111,7 +111,7 @@ String getServiceTypes(){
String contactPath(){ String contactPath(){
return "/api/jobnet_app/profile/pds/basic/contact/"; return "/api/jobnet_app/profile/pds/basic/contact/";
} }
String getServiceType(){ String getCommunicationProvider(){
return "/api/jobnet_app/comm_services/"; return "/api/jobnet_app/comm_services/";
} }
String deleteContact (){ String deleteContact (){

View File

@ -45,8 +45,8 @@ class UniTSplashScreen extends StatelessWidget {
height: 1, height: 1,
color: Colors.black)), color: Colors.black)),
), ),
const SizedBox(height: 5,), const SizedBox(height: 150,),
SpinKitThreeBounce(color: Colors.black,size: 32,) const SpinKitCircle(color: primary,size: 42,)
// Row( // Row(
// mainAxisAlignment: MainAxisAlignment.center, // mainAxisAlignment: MainAxisAlignment.center,
// crossAxisAlignment: CrossAxisAlignment.center, // crossAxisAlignment: CrossAxisAlignment.center,