wotk history refactor and create its own Bloc

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-03-02 13:28:33 +08:00
parent 5dcc1c1efb
commit fba53ce2dc
22 changed files with 1797 additions and 1455 deletions

View File

@ -0,0 +1,214 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import '../../model/location/city.dart';
import '../../model/location/country.dart';
import '../../model/location/provinces.dart';
import '../../model/location/region.dart';
import '../../model/profile/eligibility.dart';
import '../../model/utils/eligibility.dart';
import '../../sevices/profile/eligibility_services.dart';
import '../../utils/location_utilities.dart';
import '../../utils/profile_utilities.dart';
part 'eligibility_event.dart';
part 'eligibility_state.dart';
class EligibilityBloc extends Bloc<EligibilityEvent, EligibilityState> {
EligibilityBloc() : super(EligibilityInitial()) {
List<Country>? globalCountries;
List<Region>? globalRegions;
List<Eligibility>? globalEligibilities;
List<EligibityCert>? eligibilities;
////=====================================================================
on<LoadEligibility>((event, emit) {
emit(EligibilityLoadingState());
eligibilities = event.eligibilities;
emit(EligibilityLoaded(eligibilities: event.eligibilities));
});
////====================================================================
on<GetEligibilities>((event, emit) async {
try {
if (eligibilities != null) {
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()));
}
});
////====================================================================
on<ShowEditEligibilityForm>((event, emit) async {
try {
emit(EligibilityLoadingState());
if (globalCountries == null) {
List<Country> countries = await LocationUtils.instance.getCountries();
globalCountries = countries;
}
if (globalRegions == null) {
List<Region> regions = await LocationUtils.instance.getRegions();
globalRegions = regions;
}
if (globalEligibilities == null) {
List<Eligibility> eligibilities =
await ProfileUtilities.instance.getEligibilities();
globalEligibilities = eligibilities;
}
Eligibility currentEligibility = globalEligibilities!.firstWhere(
(Eligibility eligibility) =>
event.eligibityCert.eligibility!.id == eligibility.id);
bool? isOverseas = event.eligibityCert.overseas;
Country currentCountry = globalCountries!.firstWhere(
(Country country) =>
event.eligibityCert.examAddress!.country!.code == country.code);
if (event.eligibityCert.examAddress?.cityMunicipality?.province
?.region !=
null) {
Region currrentRegion = globalRegions!.firstWhere((Region region) =>
event.eligibityCert.examAddress!.cityMunicipality!.province!
.region!.code ==
region.code);
List<Province> provinces = await LocationUtils.instance
.getProvinces(regionCode: currrentRegion.code.toString());
Province currentProvince = provinces.firstWhere((Province province) =>
event.eligibityCert.examAddress!.cityMunicipality!.province!
.code ==
province.code);
List<CityMunicipality> cities = await LocationUtils.instance
.getCities(code: currentProvince.code.toString());
CityMunicipality currentCity = cities.firstWhere(
(CityMunicipality cityMunicipality) =>
event.eligibityCert.examAddress!.cityMunicipality!.code ==
cityMunicipality.code);
emit(EditEligibilityState(
currentCity: currentCity,
selectedCountry: currentCountry,
currentProvince: currentProvince,
currentRegion: currrentRegion,
currentEligibility: currentEligibility,
provinces: provinces,
cities: cities,
isOverseas: isOverseas!,
eligibityCert: event.eligibityCert,
countries: globalCountries!,
regions: globalRegions!,
eligibilities: globalEligibilities!));
} else {
emit(EditEligibilityState(
selectedCountry: currentCountry,
currentCity: null,
currentProvince: null,
currentRegion: null,
provinces: null,
cities: null,
currentEligibility: currentEligibility,
isOverseas: isOverseas!,
eligibityCert: event.eligibityCert,
countries: globalCountries!,
regions: globalRegions!,
eligibilities: globalEligibilities!));
}
} catch (e) {
emit(EligibilityErrorState(message: e.toString()));
}
});
////====================================================================
on<UpdateEligibility>((event, emit) async {
try {
emit(EligibilityLoadingState());
Map<dynamic, dynamic> status = await EligibilityService.instance.update(
eligibityCert: event.eligibityCert,
token: event.token,
profileId: int.parse(event.profileId),
oldEligibility: event.oldEligibility);
if (status['success']) {
EligibityCert newEligibility = EligibityCert.fromJson(status['data']);
eligibilities!.removeWhere(
(EligibityCert element) => element.id == event.eligibityCert.id);
eligibilities!.add(newEligibility);
emit(EligibilityEditedState(
eligibilities: eligibilities!, response: status));
} else {
emit(EligibilityEditedState(
eligibilities: eligibilities!, response: status));
}
} catch (e) {
emit(EligibilityErrorState(message: e.toString()));
}
});
on<ShowAddEligibilityForm>((event, emit) async {
emit(EligibilityLoadingState());
if (globalRegions == null) {
List<Region> regions = await LocationUtils.instance.getRegions();
globalRegions = regions;
}
if (globalEligibilities == null) {
List<Eligibility> eligibilities =
await ProfileUtilities.instance.getEligibilities();
globalEligibilities = eligibilities;
}
if (globalCountries == null) {
List<Country> countries = await LocationUtils.instance.getCountries();
globalCountries = countries;
}
emit(AddEligibilityState(
eligibilities: globalEligibilities!,
regions: globalRegions!,
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;
emit(DeletedState(success: success, eligibilities: eligibilities));
} else {
emit(DeletedState(
success: success, eligibilities: event.eligibilities));
}
} catch (e) {
emit(EligibilityErrorState(message: e.toString()));
}
});
////====================================================================
on<AddEligibility>(
(event, emit) async {
try {
emit(EligibilityLoadingState());
Map<dynamic, dynamic> status = await EligibilityService.instance.add(
eligibityCert: event.eligibityCert,
token: event.token,
profileId: int.parse(event.profileId));
if (status['success']) {
EligibityCert? eligibityCert =
EligibityCert.fromJson(status['data']);
eligibilities!.add(eligibityCert);
emit(EligibilityAddedState(
eligibilities: eligibilities!, response: status));
} else {
emit(EligibilityAddedState(
eligibilities: eligibilities!, response: status));
}
} catch (e) {
emit(EligibilityErrorState(message: e.toString()));
}
},
);
on<CallErrorState>((event, emit) {
emit(const EligibilityErrorState(
message: "Something went wrong. Please try again"));
});
}
}

View File

@ -0,0 +1,72 @@
part of 'eligibility_bloc.dart';
abstract class EligibilityEvent extends Equatable {
const EligibilityEvent();
@override
List<Object> get props => [];
}
class ShowAddEligibilityForm extends EligibilityEvent {
}
class GetEligibilities extends EligibilityEvent{
final int profileId;
final String token;
const GetEligibilities({required this.profileId, required this.token});
@override
List<Object> get props => [profileId,token];
}
class AddEligibility extends EligibilityEvent{
final EligibityCert eligibityCert;
final String profileId;
final String token;
const AddEligibility({required this.eligibityCert, required this.profileId, required this.token});
@override
List<Object> get props => [eligibityCert, profileId, token];
}
class UpdateEligibility extends EligibilityEvent{
final EligibityCert eligibityCert;
final String profileId;
final String token;
final int oldEligibility;
const UpdateEligibility({required this.eligibityCert, required this.oldEligibility,required this.profileId, required this.token});
@override
List<Object> get props =>[eligibityCert,profileId,token,oldEligibility];
}
class LoadEligibility extends EligibilityEvent {
final List<EligibityCert> eligibilities;
const LoadEligibility({required this.eligibilities});
@override
List<Object> get props => [];
}
class ShowEditEligibilityForm extends EligibilityEvent {
final EligibityCert eligibityCert;
const ShowEditEligibilityForm({required this.eligibityCert});
@override
List<Object> get props => [];
}
class DeleteEligibility extends EligibilityEvent {
final List<EligibityCert> eligibilities;
final String profileId;
final int eligibilityId;
final String token;
const DeleteEligibility(
{required this.eligibilities,
required this.eligibilityId,
required this.profileId,
required this.token});
@override
List<Object> get props => [eligibilities, profileId, eligibilityId, token];
}
class CallErrorState extends EligibilityEvent{
}

View File

@ -0,0 +1,96 @@
part of 'eligibility_bloc.dart';
abstract class EligibilityState extends Equatable {
const EligibilityState();
@override
List<Object> get props => [];
}
class EligibilityInitial extends EligibilityState {}
class EditEligibilityState extends EligibilityState {
final EligibityCert eligibityCert;
final List<Eligibility> eligibilities;
final List<Country> countries;
final List<Region> regions;
final List<Province>? provinces;
final List<CityMunicipality>? cities;
final bool isOverseas;
final Eligibility currentEligibility;
final Region? currentRegion;
final Province? currentProvince;
final CityMunicipality? currentCity;
final Country selectedCountry;
const EditEligibilityState({
required this.provinces,
required this.cities,
required this.currentProvince,
required this.currentCity,
required this.currentRegion,
required this.currentEligibility,
required this.isOverseas,
required this.eligibityCert,
required this.eligibilities,
required this.countries,
required this.regions,
required this.selectedCountry,
});
@override
List<Object> get props =>
[isOverseas, eligibityCert, eligibilities, regions, countries];
}
class DeletedState extends EligibilityState {
final List<EligibityCert> eligibilities;
final bool success;
const DeletedState({required this.eligibilities, required this.success});
@override
List<Object> get props => [success, eligibilities];
}
class AddEligibilityState extends EligibilityState {
final List<Eligibility> eligibilities;
final List<Country> countries;
final List<Region> regions;
const AddEligibilityState({
required this.eligibilities,
required this.countries,
required this.regions,
});
@override
List<Object> get props => [eligibilities,countries,regions];
}
class EligibilityEditedState extends EligibilityState{
final List<EligibityCert> eligibilities;
final Map<dynamic,dynamic> response;
const EligibilityEditedState({required this.eligibilities, required this.response});
@override
List<Object> get props =>[eligibilities, response];
}
class EligibilityAddedState extends EligibilityState{
final List<EligibityCert> eligibilities;
final Map<dynamic,dynamic> response;
const EligibilityAddedState({required this.eligibilities, required this.response});
@override
List<Object> get props =>[eligibilities,response];
}
class EligibilityLoadingState extends EligibilityState{
}
class EligibilityErrorState extends EligibilityState{
final String message;
const EligibilityErrorState({required this.message});
@override
List<Object> get props =>[message];
}
class EligibilityLoaded extends EligibilityState {
final List<EligibityCert> eligibilities;
const EligibilityLoaded({required this.eligibilities});
@override
List<Object> get props => [eligibilities];
}

View File

@ -1,27 +1,13 @@
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/eligibility.dart';
import 'package:unit2/model/profile/profileInfomation.dart'; import 'package:unit2/model/profile/profileInfomation.dart';
import 'package:unit2/model/utils/eligibility.dart';
import 'package:unit2/sevices/profile/eligibility_services.dart';
import 'package:unit2/sevices/profile/profile_service.dart'; import 'package:unit2/sevices/profile/profile_service.dart';
import 'package:unit2/utils/location_utilities.dart';
import 'package:unit2/utils/profile_utilities.dart';
import '../../model/location/country.dart';
import '../../model/location/region.dart';
import '../../model/location/provinces.dart';
import '../../model/location/city.dart';
part 'profile_event.dart'; part 'profile_event.dart';
part 'profile_state.dart'; part 'profile_state.dart';
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> { class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
ProfileBloc() : super(ProfileInitial()) { ProfileBloc() : super(ProfileInitial()) {
ProfileInformation? globalProfileInformation; ProfileInformation? globalProfileInformation;
List<Country>? globalCountries;
List<Region>? globalRegions;
List<Eligibility>? globalEligibilities;
List<EligibityCert>? eligibilities;
////=========================================================================
on<LoadProfile>((event, emit) async { on<LoadProfile>((event, emit) async {
try { try {
emit(ProfileLoading()); emit(ProfileLoading());
@ -34,198 +20,6 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
} }
}); });
on<CallErrorState>((event, emit) {
emit(const ProfileErrorState(
mesage: "Something went wrong. Please try again"));
});
////=====================================================================
on<LoadEligibility>((event, emit) {
emit(ProfileLoading());
eligibilities = event.eligibilities;
emit(EligibilityLoaded(eligibilities: event.eligibilities));
});
////====================================================================
on<GetEligibilities>((event,emit)async{
print(eligibilities?.length);
try{
if(eligibilities != null){
emit(EligibilityLoaded(eligibilities: eligibilities!));
}else{
emit(ProfileLoading());
eligibilities = await EligibilityService.instance.getEligibilities(event.profileId, event.token);
emit(EligibilityLoaded(eligibilities: eligibilities!));
}
}catch(e){
emit(ProfileErrorState(mesage: e.toString()));
}
});
////====================================================================
on<ShowEditEligibilityForm>((event, emit) async {
try {
emit(ProfileLoading());
if (globalCountries == null) {
List<Country> countries = await LocationUtils.instance.getCountries();
globalCountries = countries;
}
if (globalRegions == null) {
List<Region> regions = await LocationUtils.instance.getRegions();
globalRegions = regions;
}
if (globalEligibilities == null) {
List<Eligibility> eligibilities =
await ProfileUtilities.instance.getEligibilities();
globalEligibilities = eligibilities;
}
Eligibility currentEligibility = globalEligibilities!.firstWhere(
(Eligibility eligibility) =>
event.eligibityCert.eligibility!.id == eligibility.id);
bool? isOverseas = event.eligibityCert.overseas;
Country currentCountry = globalCountries!.firstWhere(
(Country country) =>
event.eligibityCert.examAddress!.country!.code == country.code);
if (event.eligibityCert.examAddress?.cityMunicipality?.province
?.region !=
null) {
Region currrentRegion = globalRegions!.firstWhere((Region region) =>
event.eligibityCert.examAddress!.cityMunicipality!.province!
.region!.code ==
region.code);
List<Province> provinces = await LocationUtils.instance
.getProvinces(regionCode: currrentRegion.code.toString());
Province currentProvince = provinces.firstWhere((Province province) =>
event.eligibityCert.examAddress!.cityMunicipality!.province!
.code ==
province.code);
List<CityMunicipality> cities = await LocationUtils.instance
.getCities(code: currentProvince.code.toString());
CityMunicipality currentCity = cities.firstWhere(
(CityMunicipality cityMunicipality) =>
event.eligibityCert.examAddress!.cityMunicipality!.code ==
cityMunicipality.code);
emit(EditEligibilityState(
currentCity: currentCity,
selectedCountry: currentCountry,
currentProvince: currentProvince,
currentRegion: currrentRegion,
currentEligibility: currentEligibility,
provinces: provinces,
cities: cities,
isOverseas: isOverseas!,
eligibityCert: event.eligibityCert,
countries: globalCountries!,
regions: globalRegions!,
eligibilities: globalEligibilities!));
} else {
emit(EditEligibilityState(
selectedCountry: currentCountry,
currentCity: null,
currentProvince: null,
currentRegion: null,
provinces: null,
cities: null,
currentEligibility: currentEligibility,
isOverseas: isOverseas!,
eligibityCert: event.eligibityCert,
countries: globalCountries!,
regions: globalRegions!,
eligibilities: globalEligibilities!));
}
} catch (e) {
emit(ProfileErrorState(mesage: e.toString()));
}
});
////====================================================================
on<UpdateEligibility>((event, emit) async {
try {
emit(ProfileLoading());
Map<dynamic, dynamic> status = await EligibilityService.instance.update(
eligibityCert: event.eligibityCert,
token: event.token,
profileId: int.parse(event.profileId),
oldEligibility: event.oldEligibility);
if (status['success']) {
EligibityCert newEligibility = EligibityCert.fromJson(status['data']);
eligibilities!.removeWhere(
(EligibityCert element) => element.id == event.eligibityCert.id);
eligibilities!.add(newEligibility);
emit(EligibilityEditedState(
eligibilities: eligibilities!, response: status));
} else {
emit(EligibilityEditedState(
eligibilities: eligibilities!, response: status));
}
} catch (e) {
emit(ProfileErrorState(mesage: e.toString()));
}
});
on<ShowAddEligibilityForm>((event, emit) async {
emit(ProfileLoading());
if (globalRegions == null) {
List<Region> regions = await LocationUtils.instance.getRegions();
globalRegions = regions;
}
if (globalEligibilities == null) {
List<Eligibility> eligibilities =
await ProfileUtilities.instance.getEligibilities();
globalEligibilities = eligibilities;
}
if (globalCountries == null) {
List<Country> countries = await LocationUtils.instance.getCountries();
globalCountries = countries;
}
emit(AddEligibilityState(
eligibilities: globalEligibilities!,
regions: globalRegions!,
countries: globalCountries!));
});
////====================================================================
on<DeleteEligibility>((event, emit) async {
emit(ProfileLoading());
try {
final bool success = await EligibilityService.instance.delete(
eligibilityId: event.eligibilityId,
profileId: int.parse(event.profileId),
token: event.token);
if (success) {
event.eligibilities.removeWhere(
((EligibityCert element) => element.id == event.eligibilityId));
List<EligibityCert> eligibilities = event.eligibilities;
emit(DeletedState(success: success, eligibilities: eligibilities));
} else {
emit(DeletedState(
success: success, eligibilities: event.eligibilities));
}
} catch (e) {
emit(ProfileErrorState(mesage: e.toString()));
}
});
////====================================================================
on<AddEligibility>(
(event, emit) async {
try {
emit(ProfileLoading());
Map<dynamic, dynamic> status = await EligibilityService.instance.add(
eligibityCert: event.eligibityCert,
token: event.token,
profileId: int.parse(event.profileId));
if (status['success']) {
EligibityCert? eligibityCert =
EligibityCert.fromJson(status['data']);
eligibilities!.add(eligibityCert);
emit(EligibilityAddedState(
eligibilities: eligibilities!, response: status));
} else {
emit(EligibilityAddedState(
eligibilities: eligibilities!, response: status));
}
} catch (e) {
emit(ProfileErrorState(mesage: e.toString()));
}
},
);
} }
} }

View File

@ -20,65 +20,5 @@ class LoadProfileInformation extends ProfileEvent {
List<Object> get props => []; List<Object> get props => [];
} }
class LoadEligibility extends ProfileEvent {
final List<EligibityCert> eligibilities;
const LoadEligibility({required this.eligibilities});
@override
List<Object> get props => [];
}
class ShowEditEligibilityForm extends ProfileEvent {
final EligibityCert eligibityCert;
const ShowEditEligibilityForm({required this.eligibityCert});
@override
List<Object> get props => [];
}
class DeleteEligibility extends ProfileEvent {
final List<EligibityCert> eligibilities;
final String profileId;
final int eligibilityId;
final String token;
const DeleteEligibility(
{required this.eligibilities,
required this.eligibilityId,
required this.profileId,
required this.token});
@override
List<Object> get props => [eligibilities, profileId, eligibilityId, token];
}
class ShowAddEligibilityForm extends ProfileEvent {
}
class GetEligibilities extends ProfileEvent{
final int profileId;
final String token;
const GetEligibilities({required this.profileId, required this.token});
@override
List<Object> get props => [profileId,token];
}
class AddEligibility extends ProfileEvent{
final EligibityCert eligibityCert;
final String profileId;
final String token;
const AddEligibility({required this.eligibityCert, required this.profileId, required this.token});
@override
List<Object> get props => [eligibityCert, profileId, token];
}
class UpdateEligibility extends ProfileEvent{
final EligibityCert eligibityCert;
final String profileId;
final String token;
final int oldEligibility;
const UpdateEligibility({required this.eligibityCert, required this.oldEligibility,required this.profileId, required this.token});
@override
List<Object> get props =>[eligibityCert,profileId,token,oldEligibility];
}
class CallErrorState extends ProfileEvent{
}

View File

@ -25,77 +25,5 @@ class ProfileErrorState extends ProfileState {
class ProfileLoading extends ProfileState {} class ProfileLoading extends ProfileState {}
class EligibilityLoaded extends ProfileState {
final List<EligibityCert> eligibilities;
const EligibilityLoaded({required this.eligibilities});
@override
List<Object> get props => [eligibilities];
}
class EditEligibilityState extends ProfileState {
final EligibityCert eligibityCert;
final List<Eligibility> eligibilities;
final List<Country> countries;
final List<Region> regions;
final List<Province>? provinces;
final List<CityMunicipality>? cities;
final bool isOverseas;
final Eligibility currentEligibility;
final Region? currentRegion;
final Province? currentProvince;
final CityMunicipality? currentCity;
final Country selectedCountry;
const EditEligibilityState({
required this.provinces,
required this.cities,
required this.currentProvince,
required this.currentCity,
required this.currentRegion,
required this.currentEligibility,
required this.isOverseas,
required this.eligibityCert,
required this.eligibilities,
required this.countries,
required this.regions,
required this.selectedCountry,
});
@override
List<Object> get props =>
[isOverseas, eligibityCert, eligibilities, regions, countries];
}
class DeletedState extends ProfileState {
final List<EligibityCert> eligibilities;
final bool success;
const DeletedState({required this.eligibilities, required this.success});
@override
List<Object> get props => [success, eligibilities];
}
class AddEligibilityState extends ProfileState {
final List<Eligibility> eligibilities;
final List<Country> countries;
final List<Region> regions;
const AddEligibilityState({
required this.eligibilities,
required this.countries,
required this.regions,
});
@override
List<Object> get props => [eligibilities,countries,regions];
}
class EligibilityEditedState extends ProfileState{
final List<EligibityCert> eligibilities;
final Map<dynamic,dynamic> response;
const EligibilityEditedState({required this.eligibilities, required this.response});
@override
List<Object> get props =>[eligibilities, response];
}
class EligibilityAddedState extends ProfileState{
final List<EligibityCert> eligibilities;
final Map<dynamic,dynamic> response;
const EligibilityAddedState({required this.eligibilities, required this.response});
@override
List<Object> get props =>[eligibilities,response];
}

View File

@ -0,0 +1,23 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/model/profile/work_history.dart';
import 'package:unit2/sevices/profile/work_history_services.dart';
part 'workHistory_event.dart';
part 'workHistory_state.dart';
class WorkHistoryBloc extends Bloc<WorkHistorytEvent, WorkHistoryState> {
List<WorkHistory> workExperiences = [];
WorkHistoryBloc() : super(EducationInitial()) {
on<GetWorkHistories>((event, emit)async {
emit(WorkHistoryLoadingState());
// try{
List<WorkHistory> works = await WorkHistoryService.instance.getWorkExperiences(event.profileId, event.token);
workExperiences = works;
emit(WorkHistoryLoaded(workExperiences: workExperiences));
// }catch(e){
// emit(WorkHistoryErrorState(message: e.toString()));
// }
});
}
}

View File

@ -0,0 +1,20 @@
part of 'workHistory_bloc.dart';
abstract class WorkHistorytEvent extends Equatable {
const WorkHistorytEvent();
@override
List<Object> get props => [];
}
class GetWorkHistories extends WorkHistorytEvent{
final int profileId;
final String token;
const GetWorkHistories({required this.profileId, required this.token});
@override
List<Object> get props => [profileId, token];
}

View File

@ -0,0 +1,28 @@
part of 'workHistory_bloc.dart';
abstract class WorkHistoryState extends Equatable {
const WorkHistoryState();
@override
List<Object> get props => [];
}
class EducationInitial extends WorkHistoryState {}
class WorkHistoryLoaded extends WorkHistoryState{
final List<WorkHistory> workExperiences;
const WorkHistoryLoaded({required this.workExperiences});
@override
List<Object> get props => [workExperiences];
}
class WorkHistoryLoadingState extends WorkHistoryState{
}
class WorkHistoryErrorState extends WorkHistoryState{
final String message;
const WorkHistoryErrorState({required this.message});
@override
List<Object> get props => [message];
}

View File

@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:device_preview/device_preview.dart'; import 'package:device_preview/device_preview.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/app_router.dart'; import 'package:unit2/utils/app_router.dart';
@ -47,6 +48,9 @@ class MyApp extends StatelessWidget {
BlocProvider( BlocProvider(
create: (_) => UserBloc(), create: (_) => UserBloc(),
), ),
BlocProvider(
create: (_) => ProfileBloc(),
),
], ],
child: MaterialApp( child: MaterialApp(
navigatorKey: NavigationService.navigatorKey, navigatorKey: NavigationService.navigatorKey,

View File

@ -35,7 +35,7 @@ class WorkHistory {
final DateTime? fromDate; final DateTime? fromDate;
// final dynamic attachments; // final dynamic attachments;
final int? salaryGrade; final int? salaryGrade;
final int? monthlySalary; final double? monthlySalary;
final String? appointmentStatus; final String? appointmentStatus;
factory WorkHistory.fromJson(Map<String, dynamic> json) => WorkHistory( factory WorkHistory.fromJson(Map<String, dynamic> json) => WorkHistory(

View File

@ -6,6 +6,7 @@ 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/eligibility/eligibility_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';
import 'package:unit2/model/profile/eligibility.dart'; import 'package:unit2/model/profile/eligibility.dart';
@ -60,6 +61,9 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
token = state.userData!.user!.login!.token; token = state.userData!.user!.login!.token;
profileId = state.userData!.user!.login!.user!.profileId.toString(); profileId = state.userData!.user!.login!.user!.profileId.toString();
return BlocBuilder<ProfileBloc, ProfileState>( return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if(state is ProfileLoaded){
return BlocBuilder<EligibilityBloc, EligibilityState>(
buildWhen: (previous, current) { buildWhen: (previous, current) {
if (state is EditEligibilityState) {} if (state is EditEligibilityState) {}
return false; return false;
@ -114,7 +118,8 @@ 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(
@ -149,7 +154,8 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
flex: 1, flex: 1,
child: DateTimePicker( child: DateTimePicker(
use24HourFormat: false, use24HourFormat: false,
icon: const Icon(Icons.date_range), icon:
const Icon(Icons.date_range),
controller: examDateController, controller: examDateController,
firstDate: DateTime(1970), firstDate: DateTime(1970),
lastDate: DateTime(2100), lastDate: DateTime(2100),
@ -196,7 +202,8 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.displaySmall! .displaySmall!
.copyWith(fontSize: blockSizeVertical * 2), .copyWith(
fontSize: blockSizeVertical * 2),
), ),
const SizedBox( const SizedBox(
height: 12, height: 12,
@ -212,7 +219,8 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
overseas = value; overseas = value;
}); });
}, },
decoration: normalTextFieldStyle("", ''), decoration:
normalTextFieldStyle("", ''),
name: 'overseas', name: 'overseas',
title: const Text("Overseas Address?"), title: const Text("Overseas Address?"),
), ),
@ -236,12 +244,14 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
Country>( Country>(
value: country, value: country,
child: FittedBox( child: FittedBox(
child: Text( child: Text(country
country.name!))); .name!)));
}).toList(), }).toList(),
name: 'country', name: 'country',
decoration: normalTextFieldStyle( decoration:
"Country*", "Country"), normalTextFieldStyle(
"Country*",
"Country"),
onChanged: (Country? value) { onChanged: (Country? value) {
selectedCountry = value; selectedCountry = value;
}, },
@ -249,7 +259,8 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
: Column( : Column(
children: [ children: [
//REGION DROPDOWN //REGION DROPDOWN
FormBuilderDropdown<Region?>( FormBuilderDropdown<
Region?>(
autovalidateMode: autovalidateMode:
AutovalidateMode AutovalidateMode
.onUserInteraction, .onUserInteraction,
@ -257,18 +268,20 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
value == null value == null
? 'required' ? 'required'
: null, : null,
onChanged: onChanged: (Region?
(Region? region) async { region) async {
setState(() { setState(() {
provinceCall = true; provinceCall = true;
}); });
selectedRegion = region; selectedRegion = region;
getProvinces(); getProvinces();
}, },
initialValue: selectedRegion, initialValue:
selectedRegion,
decoration: decoration:
normalTextFieldStyle( normalTextFieldStyle(
"Region*", "Region"), "Region*",
"Region"),
name: 'region', name: 'region',
items: state.regions.map< items: state.regions.map<
DropdownMenuItem< DropdownMenuItem<
@ -288,8 +301,10 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
SizedBox( SizedBox(
height: 70, height: 70,
child: ModalProgressHUD( child: ModalProgressHUD(
color: Colors.transparent, color:
inAsyncCall: provinceCall, Colors.transparent,
inAsyncCall:
provinceCall,
child: DropdownButtonFormField< child: DropdownButtonFormField<
Province?>( Province?>(
autovalidateMode: autovalidateMode:
@ -300,8 +315,10 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
? 'required' ? 'required'
: null, : null,
isExpanded: true, isExpanded: true,
value: selectedProvince, value:
onChanged: (Province? selectedProvince,
onChanged:
(Province?
province) { province) {
setState(() { setState(() {
cityCall = true; cityCall = true;
@ -310,21 +327,20 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
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: child:
FittedBox( FittedBox(
child: Text( child:
province Text(province.description!),
.description!),
)); ));
}).toList(), }).toList(),
decoration: decoration:
@ -360,7 +376,8 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
"Municipality"), "Municipality"),
value: value:
selectedMunicipality, selectedMunicipality,
items: citymuns == null items: citymuns ==
null
? [] ? []
: citymuns!.map< : citymuns!.map<
DropdownMenuItem< DropdownMenuItem<
@ -369,8 +386,8 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
c) { c) {
return DropdownMenuItem( return DropdownMenuItem(
value: c, value: c,
child: Text(c child: Text(
.description!)); c.description!));
}).toList(), }).toList(),
), ),
), ),
@ -391,8 +408,8 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
width: screenWidth, width: screenWidth,
height: 60, height: 60,
child: ElevatedButton( child: ElevatedButton(
style: mainBtnStyle( style: mainBtnStyle(primary,
primary, Colors.transparent, second), Colors.transparent, second),
onPressed: () { onPressed: () {
//rating //rating
double? rate = rating == null double? rate = rating == null
@ -408,10 +425,12 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
: DateTime.parse( : DateTime.parse(
examDateController.text); examDateController.text);
DateTime? validityDate = DateTime? validityDate =
validityDateController.text.isEmpty validityDateController
.text.isEmpty
? null ? null
: DateTime.parse( : DateTime.parse(
validityDateController.text); validityDateController
.text);
ExamAddress examAddress = ExamAddress( ExamAddress examAddress = ExamAddress(
barangay: null, barangay: null,
@ -423,23 +442,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: selectedEligibility, eligibility:
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()) {
context.read<ProfileBloc>().add( context.read<EligibilityBloc>().add(
AddEligibility( AddEligibility(
eligibityCert: eligibityCert, eligibityCert:
eligibityCert,
profileId: profileId!, profileId: profileId!,
token: token!)); token: token!));
} }
@ -464,6 +486,10 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
}, },
); );
} }
return Container();
},
);
}
Future<void> getProvinces() async { Future<void> getProvinces() async {
try { try {
@ -477,7 +503,7 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
getCities(); getCities();
}); });
} catch (e) { } catch (e) {
context.read<ProfileBloc>().add(CallErrorState()); context.read<EligibilityBloc>().add(CallErrorState());
} }
} }
@ -491,7 +517,7 @@ class _AddEligibilityScreenState extends State<AddEligibilityScreen> {
cityCall = false; cityCall = false;
}); });
} catch (e) { } catch (e) {
context.read<ProfileBloc>().add(CallErrorState()); context.read<EligibilityBloc>().add(CallErrorState());
} }
} }
} }

View File

@ -4,6 +4,7 @@ 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: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/eligibility/eligibility_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';
import 'package:unit2/model/location/city.dart'; import 'package:unit2/model/location/city.dart';
@ -59,6 +60,9 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
token = state.userData!.user!.login!.token; token = state.userData!.user!.login!.token;
profileId = state.userData!.user!.login!.user!.profileId.toString(); profileId = state.userData!.user!.login!.user!.profileId.toString();
return BlocBuilder<ProfileBloc, ProfileState>( return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if(state is ProfileLoaded){
return BlocBuilder<EligibilityBloc, EligibilityState>(
buildWhen: (previous, current) { buildWhen: (previous, current) {
if (state is EditEligibilityState) {} if (state is EditEligibilityState) {}
return false; return false;
@ -66,8 +70,14 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
builder: (context, state) { builder: (context, state) {
//EDIT ELIGIBILITY STATE //EDIT ELIGIBILITY STATE
if (state is EditEligibilityState) { if (state is EditEligibilityState) {
examDateController.text = state.eligibityCert.examDate == null?'': state.eligibityCert.examDate.toString(); examDateController.text =
validityDateController.text = state.eligibityCert.validityDate == null?'': state.eligibityCert.validityDate.toString(); state.eligibityCert.examDate == null
? ''
: state.eligibityCert.examDate.toString();
validityDateController.text =
state.eligibityCert.validityDate == null
? ''
: state.eligibityCert.validityDate.toString();
provinces = state.provinces; provinces = state.provinces;
citymuns = state.cities; citymuns = state.cities;
@ -105,8 +115,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
value: eligibility, value: eligibility,
child: Text(eligibility.title)); child: Text(eligibility.title));
}).toList(), }).toList(),
decoration: decoration: normalTextFieldStyle(
normalTextFieldStyle("Eligibility", "")), "Eligibility", "")),
const SizedBox( const SizedBox(
height: 20, height: 20,
), ),
@ -123,10 +133,10 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
license = value; license = value;
}, },
name: 'license_number', name: 'license_number',
initialValue: initialValue: license,
license,
decoration: normalTextFieldStyle( decoration: normalTextFieldStyle(
"license number", "license number"), "license number",
"license number"),
), ),
), ),
const SizedBox( const SizedBox(
@ -206,7 +216,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
style: Theme.of(context) style: Theme.of(context)
.textTheme .textTheme
.displaySmall! .displaySmall!
.copyWith(fontSize: blockSizeVertical * 2), .copyWith(
fontSize: blockSizeVertical * 2),
), ),
const SizedBox( const SizedBox(
height: 12, height: 12,
@ -224,7 +235,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
overseas = value; overseas = value;
}); });
}, },
decoration: normalTextFieldStyle("", ''), decoration:
normalTextFieldStyle("", ''),
name: 'overseas', name: 'overseas',
title: const Text("Overseas Address?"), title: const Text("Overseas Address?"),
), ),
@ -249,12 +261,14 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
Country>( Country>(
value: country, value: country,
child: FittedBox( child: FittedBox(
child: Text( child: Text(country
country.name!))); .name!)));
}).toList(), }).toList(),
name: 'country', name: 'country',
decoration: normalTextFieldStyle( decoration:
"Country*", "Country"), normalTextFieldStyle(
"Country*",
"Country"),
onChanged: (Country? value) { onChanged: (Country? value) {
selectedCountry = value; selectedCountry = value;
}, },
@ -269,8 +283,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
? 'required' ? 'required'
: null, : null,
isExpanded: true, isExpanded: true,
onChanged: onChanged: (Region?
(Region? region) async { region) async {
setState(() { setState(() {
provinceCall = true; provinceCall = true;
}); });
@ -303,13 +317,14 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
value: selectedRegion, value: selectedRegion,
decoration: decoration:
normalTextFieldStyle( normalTextFieldStyle(
"Region*", "Region"), "Region*",
"Region"),
items: regions == null items: regions == null
? [] ? []
: regions!.map< : regions!.map<
DropdownMenuItem< DropdownMenuItem<
Region>>( Region>>((Region
(Region region) { region) {
return DropdownMenuItem< return DropdownMenuItem<
Region>( Region>(
value: region, value: region,
@ -324,8 +339,10 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
SizedBox( SizedBox(
height: 70, height: 70,
child: ModalProgressHUD( child: ModalProgressHUD(
color: Colors.transparent, color:
inAsyncCall: provinceCall, Colors.transparent,
inAsyncCall:
provinceCall,
child: DropdownButtonFormField< child: DropdownButtonFormField<
Province?>( Province?>(
validator: (value) => validator: (value) =>
@ -333,7 +350,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
? 'required' ? 'required'
: null, : null,
isExpanded: true, isExpanded: true,
value: selectedProvince, value:
selectedProvince,
onChanged: (Province? onChanged: (Province?
province) async { province) async {
setState(() { setState(() {
@ -350,24 +368,24 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
selectedMunicipality = selectedMunicipality =
citymuns![0]; citymuns![0];
setState(() { setState(() {
cityCall = false; cityCall =
false;
}); });
}, },
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: child:
FittedBox( FittedBox(
child: Text( child:
province Text(province.description!),
.description!),
)); ));
}).toList(), }).toList(),
decoration: decoration:
@ -381,7 +399,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
SizedBox( SizedBox(
height: 70, height: 70,
child: ModalProgressHUD( child: ModalProgressHUD(
color: Colors.transparent, color:
Colors.transparent,
inAsyncCall: cityCall, inAsyncCall: cityCall,
child: child:
DropdownButtonFormField< DropdownButtonFormField<
@ -403,7 +422,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
"Municipality"), "Municipality"),
value: value:
selectedMunicipality, selectedMunicipality,
items: citymuns == null items: citymuns ==
null
? [] ? []
: citymuns!.map< : citymuns!.map<
DropdownMenuItem< DropdownMenuItem<
@ -412,8 +432,8 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
c) { c) {
return DropdownMenuItem( return DropdownMenuItem(
value: c, value: c,
child: Text(c child: Text(
.description!)); c.description!));
}).toList(), }).toList(),
), ),
), ),
@ -438,7 +458,6 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
style: mainBtnStyle( style: mainBtnStyle(
primary, Colors.transparent, second), primary, Colors.transparent, second),
onPressed: () { onPressed: () {
//rating //rating
double? rate = rating == null double? rate = rating == null
? null ? null
@ -459,14 +478,22 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
validityDateController.text.isEmpty validityDateController.text.isEmpty
? null ? null
: DateTime.parse( : DateTime.parse(
validityDateController.text); validityDateController
.text);
// exam address // exam address
ExamAddress examAddress = ExamAddress( ExamAddress examAddress = ExamAddress(
barangay: state.eligibityCert.examAddress?.barangay, barangay: state.eligibityCert
id: state.eligibityCert.examAddress?.id, .examAddress?.barangay,
addressCategory: state.eligibityCert.examAddress?.addressCategory, id: state
examAddressClass: state.eligibityCert.examAddress?.examAddressClass, .eligibityCert.examAddress?.id,
country: selectedCountry ??= Country( addressCategory: state.eligibityCert
.examAddress?.addressCategory,
examAddressClass: state
.eligibityCert
.examAddress
?.examAddressClass,
country: selectedCountry ??=
Country(
id: 175, id: 175,
name: 'Philippines', name: 'Philippines',
code: 'PH'), code: 'PH'),
@ -477,14 +504,23 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
rating: rate, rating: rate,
examDate: examDate, examDate: examDate,
attachments: null, attachments: null,
eligibility: selectedEligibility, eligibility:
selectedEligibility,
examAddress: examAddress, examAddress: examAddress,
validityDate: validityDate, validityDate: validityDate,
licenseNumber: newLicense, licenseNumber: newLicense,
overseas: overseas); overseas: overseas);
if (formKey.currentState! if (formKey.currentState!
.saveAndValidate()) { .saveAndValidate()) {
context.read<ProfileBloc>().add(UpdateEligibility(eligibityCert: eligibityCert, oldEligibility: state.eligibityCert.eligibility!.id, profileId: profileId!, token: token!)); context.read<EligibilityBloc>().add(
UpdateEligibility(
eligibityCert: eligibityCert,
oldEligibility: state
.eligibityCert
.eligibility!
.id,
profileId: profileId!,
token: token!));
} }
}, },
child: const Text(submit)), child: const Text(submit)),
@ -503,6 +539,11 @@ class _EditEligibilityScreenState extends State<EditEligibilityScreen> {
} }
return Container(); return Container();
}, },
);
}
return Container();
},
); );
} }
} }

View File

@ -4,6 +4,7 @@ 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:fluttericon/font_awesome_icons.dart';
import 'package:unit2/bloc/eligibility/eligibility_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';
import 'package:unit2/model/profile/eligibility.dart'; import 'package:unit2/model/profile/eligibility.dart';
@ -25,32 +26,33 @@ class EligibiltyScreen extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
String? token; String? token;
String? profileId; String? profileId;
List<EligibityCert>? eligibilities;
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async {
return true; return true;
}, },
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
title: context.watch<ProfileBloc>().state is AddEligibilityState title: context.watch<EligibilityBloc>().state is AddEligibilityState
? const Text("Add Eligiblity") ? const Text("Add Eligiblity")
: context.watch<ProfileBloc>().state is EditEligibilityState : context.watch<EligibilityBloc>().state is EditEligibilityState
? const Text("Edit Eligibilty") ? const Text("Edit Eligibilty")
: const Text(elibilityScreenTitle), : const Text(elibilityScreenTitle),
centerTitle: true, centerTitle: true,
backgroundColor: primary, backgroundColor: primary,
actions: (context.watch<ProfileBloc>().state is EligibilityLoaded || actions: (context.watch<EligibilityBloc>().state is EligibilityLoaded ||
context.watch<ProfileBloc>().state is ProfileLoading) context.watch<EligibilityBloc>().state is ProfileLoading)
? [ ? [
AddLeading(onPressed: () { AddLeading(onPressed: () {
context.read<ProfileBloc>().add(ShowAddEligibilityForm()); context
.read<EligibilityBloc>()
.add(ShowAddEligibilityForm());
}) })
] ]
: [ : [
CloseLeading(onPressed: () { CloseLeading(onPressed: () {
context context.read<EligibilityBloc>().add(GetEligibilities(
.read<ProfileBloc>() profileId: int.parse(profileId!), token: token!));
.add(GetEligibilities(profileId: int.parse(profileId!), token: token!));
}) })
], ],
), ),
@ -60,21 +62,23 @@ class EligibiltyScreen extends StatelessWidget {
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.toString();
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if(state is ProfileLoaded){
return ProgressHUD( return ProgressHUD(
padding: const EdgeInsets.all(24), padding: const EdgeInsets.all(24),
indicatorWidget: const SpinKitFadingCircle( indicatorWidget: const SpinKitFadingCircle(
color: Colors.white, color: Colors.white,
), ),
backgroundColor: Colors.black87, backgroundColor: Colors.black87,
child: BlocConsumer<ProfileBloc, ProfileState>( child: BlocConsumer<EligibilityBloc, EligibilityState>(
listener: (context, state) { listener: (context, state) {
if (state is ProfileLoading) { if (state is EligibilityLoadingState) {
final progress = ProgressHUD.of(context); final progress = ProgressHUD.of(context);
progress!.showWithText("Loading"); progress!.showWithText("Loading");
} }
if (state is EligibilityLoaded || if (state is EligibilityLoaded ||
state is AddEligibilityState || state is AddEligibilityState ||
state is ProfileErrorState ||
state is EditEligibilityState || state is EditEligibilityState ||
state is DeletedState || state is DeletedState ||
state is EligibilityAddedState || state is EligibilityAddedState ||
@ -86,16 +90,17 @@ class EligibiltyScreen extends StatelessWidget {
if (state is DeletedState) { if (state is DeletedState) {
if (state.success) { if (state.success) {
successAlert(context, "Deletion Successfull", successAlert(context, "Deletion Successfull",
"Eligibility has been deleted successfully", () { "Eligibility has been deleted successfully",
() {
Navigator.of(context).pop(); Navigator.of(context).pop();
context.read<ProfileBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(LoadEligibility(
eligibilities: state.eligibilities)); 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<ProfileBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(LoadEligibility(
eligibilities: state.eligibilities)); eligibilities: state.eligibilities));
}); });
} }
@ -106,14 +111,15 @@ 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<ProfileBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(LoadEligibility(
eligibilities: state.eligibilities)); 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<ProfileBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(LoadEligibility(
eligibilities: state.eligibilities)); eligibilities: state.eligibilities));
}); });
} }
@ -124,24 +130,25 @@ 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<ProfileBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(LoadEligibility(
eligibilities: state.eligibilities)); 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<ProfileBloc>().add(LoadEligibility( context.read<EligibilityBloc>().add(LoadEligibility(
eligibilities: state.eligibilities)); eligibilities: state.eligibilities));
}); });
} }
} }
}, },
builder: (context, state) { builder: (context, state) {
return BlocBuilder<ProfileBloc, ProfileState>( return BlocBuilder<EligibilityBloc, EligibilityState>(
builder: (context, state) { builder: (context, state) {
if (state is EligibilityLoaded) { if (state is EligibilityLoaded) {
eligibilities = state.eligibilities;
if (state.eligibilities.isNotEmpty) { if (state.eligibilities.isNotEmpty) {
return ListView.builder( return ListView.builder(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
@ -149,8 +156,10 @@ class EligibiltyScreen extends StatelessWidget {
itemCount: state.eligibilities.length, itemCount: state.eligibilities.length,
itemBuilder: itemBuilder:
(BuildContext context, int index) { (BuildContext context, int index) {
String title = state.eligibilities[index] String title = state
.eligibility!.title; .eligibilities[index]
.eligibility!
.title;
return Column( return Column(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.start, MainAxisAlignment.start,
@ -159,22 +168,26 @@ class EligibiltyScreen extends StatelessWidget {
children: [ children: [
Container( Container(
width: screenWidth, width: screenWidth,
padding: const EdgeInsets.symmetric( padding:
horizontal: 12, vertical: 8), const EdgeInsets.symmetric(
horizontal: 12,
vertical: 8),
decoration: box1(), decoration: box1(),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
child: Column( child: Column(
mainAxisAlignment: mainAxisAlignment:
MainAxisAlignment.start, MainAxisAlignment
.start,
crossAxisAlignment: crossAxisAlignment:
CrossAxisAlignment CrossAxisAlignment
.start, .start,
children: [ children: [
Text( Text(
title, title,
style: Theme.of(context) style: Theme.of(
context)
.textTheme .textTheme
.titleMedium! .titleMedium!
.copyWith( .copyWith(
@ -188,8 +201,8 @@ class EligibiltyScreen extends StatelessWidget {
), ),
Text( Text(
"$licenseNumber: ${state.eligibilities[index].licenseNumber == null ? 'N/A' : state.eligibilities[index].licenseNumber.toString()}", "$licenseNumber: ${state.eligibilities[index].licenseNumber == null ? 'N/A' : state.eligibilities[index].licenseNumber.toString()}",
style: style: Theme.of(
Theme.of(context) context)
.textTheme .textTheme
.titleSmall), .titleSmall),
const SizedBox( const SizedBox(
@ -197,29 +210,31 @@ class EligibiltyScreen extends StatelessWidget {
), ),
Text( Text(
"Rating : ${state.eligibilities[index].rating ?? 'N/A'}.", "Rating : ${state.eligibilities[index].rating ?? 'N/A'}.",
style: style: Theme.of(
Theme.of(context) context)
.textTheme .textTheme
.titleSmall) .titleSmall)
]), ]),
), ),
AppPopupMenu<int>( AppPopupMenu<int>(
offset: const Offset(-10, -10), offset:
const Offset(-10, -10),
elevation: 3, elevation: 3,
onSelected: (value) { onSelected: (value) {
final progress = final progress =
ProgressHUD.of(context); ProgressHUD.of(
context);
progress!.showWithText( progress!.showWithText(
"Loading..."); "Loading...");
////delete eligibilty-= = = = = = = = =>> ////delete eligibilty-= = = = = = = = =>>
if (value == 2) { if (value == 2) {
confirmAlert(context, () { confirmAlert(context,
() {
BlocProvider.of< BlocProvider.of<
ProfileBloc>( EligibilityBloc>(
context) context)
.add(DeleteEligibility( .add(DeleteEligibility(
eligibilities: eligibilities: state
state
.eligibilities, .eligibilities,
eligibilityId: state eligibilityId: state
.eligibilities[ .eligibilities[
@ -227,7 +242,8 @@ class EligibiltyScreen extends StatelessWidget {
.id!, .id!,
profileId: profileId:
profileId!, profileId!,
token: token!)); token:
token!));
}, "Delete?", }, "Delete?",
"Confirm Delete?"); "Confirm Delete?");
} }
@ -251,8 +267,9 @@ class EligibiltyScreen extends StatelessWidget {
eligibityCert.overseas = eligibityCert.overseas =
overseas; overseas;
context.read<ProfileBloc>().add( context
ShowEditEligibilityForm( .read<EligibilityBloc>()
.add(ShowEditEligibilityForm(
eligibityCert: eligibityCert:
eligibityCert)); eligibityCert));
} }
@ -269,7 +286,8 @@ class EligibiltyScreen extends StatelessWidget {
popMenuItem( popMenuItem(
text: "Attachment", text: "Attachment",
value: 3, value: 3,
icon: FontAwesome.attach) icon: FontAwesome
.attach)
], ],
icon: const Icon( icon: const Icon(
Icons.more_vert, Icons.more_vert,
@ -299,9 +317,9 @@ class EligibiltyScreen extends StatelessWidget {
if (state is AddEligibilityState) { if (state is AddEligibilityState) {
return const AddEligibilityScreen(); return const AddEligibilityScreen();
} }
if (state is ProfileErrorState) { if (state is EligibilityErrorState) {
return Center( return Center(
child: Text(state.mesage), child: Text(state.message),
); );
} }
return Container( return Container(
@ -312,6 +330,11 @@ class EligibiltyScreen extends StatelessWidget {
}, },
), ),
); );
}
return Container();
}
);
} }
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:unit2/model/profile/other_information/non_acedimic_recognition.dart'; import 'package:unit2/model/profile/other_information/non_acedimic_recognition.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart'; import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/theme-data.dart/colors.dart';

View File

@ -1,19 +1,23 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/bloc/workHistory/workHistory_bloc.dart';
import 'package:unit2/model/profile/work_history.dart'; import 'package:unit2/model/profile/work_history.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart'; import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/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';
import 'package:unit2/widgets/error_state.dart';
import '../../../utils/global.dart'; import '../../../utils/global.dart';
class WorkHistoryScreen extends StatelessWidget { class WorkHistoryScreen extends StatelessWidget {
final List<WorkHistory> workExperiences; const WorkHistoryScreen({super.key});
const WorkHistoryScreen({super.key, required this.workExperiences});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -25,39 +29,110 @@ class WorkHistoryScreen extends StatelessWidget {
centerTitle: true, centerTitle: true,
actions: [AddLeading(onPressed: () {})], actions: [AddLeading(onPressed: () {})],
), ),
body: workExperiences.isNotEmpty? ListView.builder( body:
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10), //UserBloc
itemCount: workExperiences.length, ProgressHUD(
itemBuilder: (BuildContext context, int index) { padding: const EdgeInsets.all(24),
String position = workExperiences[index].position!.title!; backgroundColor: Colors.black87,
String agency = workExperiences[index].agency!.name!; indicatorWidget: const SpinKitFadingCircle(
String from = color: Colors.white,
dteFormat2.format(workExperiences[index].fromDate!); ),
String? to = workExperiences[index].toDate == null child: BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
//ProfileBloc
if (state is ProfileLoaded) {
//WorkHistoryBloc
return BlocConsumer<WorkHistoryBloc, WorkHistoryState>(
listener: (context, state) {
if (state is WorkHistoryLoadingState) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if (state is WorkHistoryLoaded || state is WorkHistoryErrorState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
},
builder: (context, state) {
if (state is WorkHistoryLoaded) {
if (state.workExperiences.isNotEmpty) {
return ListView.builder(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 10),
itemCount: state.workExperiences.length,
itemBuilder:
(BuildContext context, int index) {
String position = state
.workExperiences[index]
.position!
.title!;
String agency = state
.workExperiences[index].agency!.name!;
String from = dteFormat2.format(
state.workExperiences[index].fromDate!);
String? to =
state.workExperiences[index].toDate ==
null
? present.toUpperCase() ? present.toUpperCase()
: dteFormat2.format(workExperiences[index].toDate!); : dteFormat2.format(
state.workExperiences[index].toDate!);
return Column( return Column(
children: [ children: [
Container( Container(
width: screenWidth, width: screenWidth,
decoration: box1(), decoration: box1(),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
child: Row(children: [ child: Row(children: [
Expanded( Expanded(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment:
crossAxisAlignment: CrossAxisAlignment.start, MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [ children: [
Text(position,style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w600),), Text(
position,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight.w600),
),
const Divider(), const Divider(),
const SizedBox(height: 8,), const SizedBox(
Text(agency,style: Theme.of(context).textTheme.titleSmall!.copyWith(fontWeight: FontWeight.w500),), height: 8,
const SizedBox(height: 5,), ),
Text("$from to $to",style: Theme.of(context).textTheme.bodyMedium,), Text(
agency,
style: Theme.of(context)
.textTheme
.titleSmall!
.copyWith(
fontWeight:
FontWeight.w500),
),
const SizedBox(
height: 5,
),
Text(
"$from $to ",
style: Theme.of(context)
.textTheme
.bodyMedium,
),
], ],
)), )),
IconButton(onPressed: () {}, icon: const Icon(Icons.more_vert,color: Colors.grey,)) IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
]), ]),
), ),
const SizedBox( const SizedBox(
@ -65,7 +140,28 @@ class WorkHistoryScreen extends StatelessWidget {
), ),
], ],
); );
}):const EmptyData(message: "You don't have any Work History added. Please click + to add ."), });
} else {
return const EmptyData(
message:
"You don't have any work experience added. Please click + to add");
}
}
if (state is WorkHistoryErrorState) {
return SomethingWentWrong(
message: state.message, onpressed: () {});
}
return Container();
},
); );
} }
return Container();
},
);
}
return Container();
},
),
));
}
} }

View File

@ -8,14 +8,15 @@ import 'package:fluttericon/elusive_icons.dart';
import 'package:fluttericon/entypo_icons.dart'; import 'package:fluttericon/entypo_icons.dart';
import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:fluttericon/modern_pictograms_icons.dart'; import 'package:fluttericon/modern_pictograms_icons.dart';
import 'package:unit2/bloc/eligibility/eligibility_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/workHistory/workHistory_bloc.dart';
import 'package:unit2/model/login_data/employee_info/employee_info.dart'; import 'package:unit2/model/login_data/employee_info/employee_info.dart';
import 'package:unit2/screens/profile/components/basic_information/address_screen.dart'; import 'package:unit2/screens/profile/components/basic_information/address_screen.dart';
import 'package:unit2/screens/profile/components/basic_information/citizenship_screen.dart'; import 'package:unit2/screens/profile/components/basic_information/citizenship_screen.dart';
import 'package:unit2/screens/profile/components/basic_information/contact_information_screen.dart'; import 'package:unit2/screens/profile/components/basic_information/contact_information_screen.dart';
import 'package:unit2/screens/profile/components/basic_information/identification_information_screen.dart'; import 'package:unit2/screens/profile/components/basic_information/identification_information_screen.dart';
import 'package:unit2/screens/profile/components/basic_information/primary_information_screen.dart'; import 'package:unit2/screens/profile/components/basic_information/primary_information_screen.dart';
import 'package:unit2/screens/profile/components/education_screen.dart';
import 'package:unit2/screens/profile/components/eligibility_screen.dart'; import 'package:unit2/screens/profile/components/eligibility_screen.dart';
import 'package:unit2/screens/profile/components/family_background_screen.dart'; import 'package:unit2/screens/profile/components/family_background_screen.dart';
import 'package:unit2/screens/profile/components/learning_and_development_screen.dart'; import 'package:unit2/screens/profile/components/learning_and_development_screen.dart';
@ -148,12 +149,7 @@ class _ProfileInfoState extends State<ProfileInfo> {
icon: Elusive.group, icon: Elusive.group,
title: "Family", title: "Family",
onTap: () { onTap: () {
// Navigator.push(context, MaterialPageRoute(
// builder: (BuildContext context) {
// return FamilyBackgroundScreen(
// familyBackground:
// state.profileInformation.families);
// }));
}, },
), ),
const Divider(), const Divider(),
@ -177,10 +173,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
onTap: () { onTap: () {
Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
return BlocProvider<ProfileBloc>.value( return BlocProvider(
value: ProfileBloc() create: (context) => EligibilityBloc()..add(GetEligibilities(profileId: profileId!, token: token!)),
..add(GetEligibilities(
profileId: profileId!, token: token!)),
child: const EligibiltyScreen(), child: const EligibiltyScreen(),
); );
})); }));
@ -191,12 +185,14 @@ class _ProfileInfoState extends State<ProfileInfo> {
icon: FontAwesome5.shopping_bag, icon: FontAwesome5.shopping_bag,
title: "Work History", title: "Work History",
onTap: () { onTap: () {
// Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
// builder: (BuildContext context) { builder: (BuildContext context) {
// return WorkHistoryScreen( return BlocProvider(
// workExperiences: state create: (context) => WorkHistoryBloc()..add(GetWorkHistories(profileId: profileId!, token: token!)),
// .profileInformation.workExperiences); child: const WorkHistoryScreen(),
// })); );
}));
}, },
), ),
const Divider(), const Divider(),

View File

@ -20,7 +20,7 @@ class EligibilityService {
}; };
// try{ try{
http.Response response = await Request.instance.getRequest(path: path,headers: headers,param: {}); http.Response response = await Request.instance.getRequest(path: path,headers: headers,param: {});
if(response.statusCode == 200){ if(response.statusCode == 200){
Map data = jsonDecode(response.body); Map data = jsonDecode(response.body);
@ -31,9 +31,9 @@ class EligibilityService {
}); });
} }
} }
// }catch(e){ }catch(e){
// throw e.toString(); throw e.toString();
// } }
return eligibilities; return eligibilities;
} }

View File

@ -0,0 +1,39 @@
import 'dart:convert';
import 'package:unit2/model/profile/work_history.dart';
import 'package:http/http.dart' as http;
import 'package:unit2/utils/request.dart';
import '../../utils/urls.dart';
class WorkHistoryService{
static final WorkHistoryService _instance = WorkHistoryService();
static WorkHistoryService get instance => _instance;
Future <List<WorkHistory>> getWorkExperiences( int profileId, String token)async{
List<WorkHistory> workExperiences = [];
String authToken = "Token $token";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': authToken
};
String path= Url.instance.workHistories()+profileId.toString();
// try{
http.Response response =await Request.instance.getRequest(path: path, headers: headers, param: {});
if(response.statusCode == 200){
Map data = jsonDecode(response.body);
if(data['data'] != null){
data['data'].forEach((var workHistory){
workExperiences.add(WorkHistory.fromJson(workHistory));
});
}
}
// }catch(e){
// throw e.toString();
// }
return workExperiences;
}
}

View File

@ -34,12 +34,12 @@ class AppRouter {
return const QRLogin(); return const QRLogin();
}); });
case '/profile': case '/profile':
return MaterialPageRoute(builder: (_) {
ProfileArguments arguments = routeSettings.arguments as ProfileArguments; ProfileArguments arguments = routeSettings.arguments as ProfileArguments;
return BlocProvider( BlocProvider.of<ProfileBloc>(
create: (context) => ProfileBloc()..add(LoadProfile(token: arguments.token,userID: arguments.userID)), NavigationService.navigatorKey.currentContext!)
child: const ProfileInfo(), .add(LoadProfile(token:arguments.token ,userID:arguments.userID ));
); return MaterialPageRoute(builder: (_) {
return const ProfileInfo();
}); });
default: default:
return MaterialPageRoute(builder: (context) { return MaterialPageRoute(builder: (context) {

View File

@ -41,6 +41,10 @@ String deleteEligibility(){
String updateEligibility(){ String updateEligibility(){
return "/api/jobnet_app/profile/pds/eligibility/"; return "/api/jobnet_app/profile/pds/eligibility/";
} }
//// work history paths
String workHistories(){
return "/api/jobnet_app/profile/pds/work/";
}
// location utils path // location utils path
String getCounties(){ String getCounties(){