From 58e1167613536650a07f27b9d3942b0fb5723454 Mon Sep 17 00:00:00 2001 From: PGAN-MIS Date: Mon, 27 Mar 2023 16:59:08 +0800 Subject: [PATCH] Implemented crud operation API for organization membership screen --- .../non_academic_recognition_bloc.dart | 27 ++ .../non_academic_recognition_event.dart | 38 +- .../non_academic_recognition_state.dart | 33 ++ .../organization_membership_bloc.dart | 64 ++- .../organization_membership_event.dart | 35 +- .../organization_membership_state.dart | 20 + .../profile/workHistory/workHistory_bloc.dart | 10 +- .../non_acedimic_recognition.dart | 33 +- .../non_academic/add_modal.dart | 343 ++++++++++++++++ .../non_academic_recognition_screen.dart | 13 +- .../org_membership/add_modal.dart | 373 ++++++++++++++++++ .../org_membership_screen.dart | 131 +++++- .../components/work_history/add_modal.dart | 2 +- .../profile/non_academic_services.dart | 72 +++- .../profile/orgmembership_services.dart | 53 +++ .../profile/work_history_services.dart | 48 --- lib/utils/profile_utilities.dart | 55 +++ lib/utils/urls.dart | 4 +- 18 files changed, 1250 insertions(+), 104 deletions(-) create mode 100644 lib/screens/profile/components/other_information/non_academic/add_modal.dart create mode 100644 lib/screens/profile/components/other_information/org_membership/add_modal.dart diff --git a/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_bloc.dart b/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_bloc.dart index 690015a..c4728f8 100644 --- a/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_bloc.dart +++ b/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_bloc.dart @@ -3,6 +3,9 @@ import 'package:equatable/equatable.dart'; import 'package:unit2/sevices/profile/non_academic_services.dart'; import '../../../../model/profile/other_information/non_acedimic_recognition.dart'; +import '../../../../model/utils/agency.dart'; +import '../../../../model/utils/category.dart'; +import '../../../../utils/profile_utilities.dart'; part 'non_academic_recognition_event.dart'; @@ -11,6 +14,9 @@ part 'non_academic_recognition_state.dart'; class NonAcademicRecognitionBloc extends Bloc { NonAcademicRecognitionBloc() : super(NonAcademicRecognitionInitial()) { List nonAcademicRecognitions = []; + List agencies = []; + List agencyCategory = []; + ////GET on((event, emit)async { emit(NonAcademicRecognitionLoadingState()); try{ @@ -21,5 +27,26 @@ class NonAcademicRecognitionBloc extends Bloc((event, emit)async{ + emit(NonAcademicRecognitionLoadingState()); + try{ + if(agencies.isEmpty){ + List newAgencies = await ProfileUtilities.instance.getAgecies(); + agencies = newAgencies; + } + if(agencyCategory.isEmpty){ + ListnewAgencyCategories = await ProfileUtilities.instance.agencyCategory(); + agencyCategory = newAgencyCategories; + } + emit(AddNonAcademeRecognitionState(agencies: agencies, agencyCategories: agencyCategory)); + }catch(e){ + emit(NonAcademicRecognitionErrorState(message: e.toString())); + } + },); + ////ADD + on((event,emit){ + emit(NonAcademicRecognitionLoadingState()); + }); } } diff --git a/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_event.dart b/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_event.dart index c262400..793ddd3 100644 --- a/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_event.dart +++ b/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_event.dart @@ -6,7 +6,7 @@ abstract class NonAcademicRecognitionEvent extends Equatable { @override List get props => []; } - +//// GET EVENT class GetNonAcademicRecognition extends NonAcademicRecognitionEvent{ final int profileId; final String token; @@ -14,3 +14,39 @@ class GetNonAcademicRecognition extends NonAcademicRecognitionEvent{ @override List get props => [profileId,token]; } +////LOAD EVENT +class LoadNonAcademeRecognition extends NonAcademicRecognitionEvent{ + final List nonAcademicRecognitions; + const LoadNonAcademeRecognition({required this.nonAcademicRecognitions}); + @override + List get props => [nonAcademicRecognitions]; +} + +////SHOW ADD FORM EVENT +class ShowAddNonAcademeRecognitionForm extends NonAcademicRecognitionEvent{ + +} + +//// ADD EVENT +class AddNonAcademeRecognition extends NonAcademicRecognitionEvent{ + final int profileId; + final String token; + final NonAcademicRecognition nonAcademicRecognition; + const AddNonAcademeRecognition({required this.nonAcademicRecognition, required this.profileId, required this.token}); + @override + List get props => [nonAcademicRecognition,profileId,token]; + +} + +//// DELETE EVENT +class DeleteNonAcademeRecognition extends NonAcademicRecognitionEvent{ + final int profileId; + final String token; + final int id; + final String title; + const DeleteNonAcademeRecognition({required this.id,required this.profileId, required this.title,required this.token}); + @override + List get props => [profileId,token,id,title]; + +} + diff --git a/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_state.dart b/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_state.dart index 7d4ada6..dbb737b 100644 --- a/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_state.dart +++ b/lib/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_state.dart @@ -9,16 +9,49 @@ abstract class NonAcademicRecognitionState extends Equatable { class NonAcademicRecognitionInitial extends NonAcademicRecognitionState {} + +////LOADING STATE class NonAcademicRecognitionLoadingState extends NonAcademicRecognitionState{ } +////LOADED STATE class NonAcademicRecognitionLoadedState extends NonAcademicRecognitionState{ final List nonAcademicRecognition; const NonAcademicRecognitionLoadedState({required this.nonAcademicRecognition}); @override List get props => []; } +////DELETED STATE +class NonAcademeRecognitionDeletedState extends NonAcademicRecognitionState{ + final List nonAcademicRecognition; + final bool success; + const NonAcademeRecognitionDeletedState({required this.nonAcademicRecognition, required this.success}); + @override + List get props => [nonAcademicRecognition,success]; +} +////ADDED STATE +class NonAcademeRecognitionAddedState extends NonAcademicRecognitionState{ + final List nonAcademicRecognition; + final Map response; + const NonAcademeRecognitionAddedState({required this.nonAcademicRecognition, required this.response}); + @override + List get props => [nonAcademicRecognition,response]; +} + +////ADDING STATE +class AddNonAcademeRecognitionState extends NonAcademicRecognitionState{ + final List agencies; +final List agencyCategories; +const AddNonAcademeRecognitionState({required this.agencies, required this.agencyCategories}); + @override + List get props => [agencies,agencyCategories]; + +} + + + +////ERROR STATE class NonAcademicRecognitionErrorState extends NonAcademicRecognitionState{ final String message; const NonAcademicRecognitionErrorState({required this.message}); diff --git a/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart b/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart index cb27502..41da2ed 100644 --- a/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart +++ b/lib/bloc/profile/other_information/org_membership/organization_membership_bloc.dart @@ -1,6 +1,10 @@ import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; +import 'package:unit2/model/profile/work_history.dart'; +import 'package:unit2/model/utils/agency.dart'; +import 'package:unit2/model/utils/category.dart'; import 'package:unit2/sevices/profile/orgmembership_services.dart'; +import 'package:unit2/utils/profile_utilities.dart'; import '../../../../model/profile/other_information/organization_memberships.dart'; @@ -8,17 +12,75 @@ part 'organization_membership_event.dart'; part 'organization_membership_state.dart'; class OrganizationMembershipBloc extends Bloc { + List agencies = []; + List agencyCategory = []; OrganizationMembershipBloc() : super(OrganizationMembershipInitial()) { List organizationMemberships=[]; on((event, emit) async{ emit(OrgmembershipLoadingState()); try{ - List orgs = await OrganizationMembershipServices.instance.getOrgMemberships(event.profileId, event.token); + if(organizationMemberships.isEmpty){ + List orgs = await OrganizationMembershipServices.instance.getOrgMemberships(event.profileId!, event.token!); organizationMemberships = orgs; + } + emit(OrganizationMembershipLoaded(orgMemberships: organizationMemberships)); }catch(e){ OrganizationMembershipErrorState(message: e.toString()); } }); + on((event,emit){ + emit(OrganizationMembershipLoaded(orgMemberships: event.organizationMemberships)); + }); + + ////SHOW ADD ORG MEMBERSHIP FORM + on((event,emit)async{ + emit(OrgmembershipLoadingState()); + try{ + if(agencies.isEmpty){ + List newAgencies = await ProfileUtilities.instance.getAgecies(); + agencies = newAgencies; + } + if(agencyCategory.isEmpty){ + ListnewAgencyCategories = await ProfileUtilities.instance.agencyCategory(); + agencyCategory = newAgencyCategories; + } + emit(AddOrgMembershipState(agencies: agencies, agencyCategories: agencyCategory)); + }catch(e){ + emit(OrganizationMembershipErrorState(message: e.toString())); + } + }); + //// ADD ORGMEMBERSHIP + on((event,emit)async{ + emit(OrgmembershipLoadingState()); + try{ + Map status= await OrganizationMembershipServices.instance.add(agency: event.agency, token: event.token, profileId: event.profileId.toString()); + if(status["success"]){ + OrganizationMembership organizationMembership = OrganizationMembership.fromJson(status["data"]); + organizationMemberships.add(organizationMembership); + emit(OrgMembershipAddedState(orgMemberships: organizationMemberships, response: status)); + }else{ + emit(OrgMembershipAddedState(orgMemberships: organizationMemberships, response: status)); + } + }catch(e){ + emit(OrganizationMembershipErrorState(message: e.toString())); + } + }); + ////DELETE ORGMEMBERSHIP + on((event,emit)async{ + emit(OrgmembershipLoadingState()); + try{ + final bool success = await OrganizationMembershipServices.instance.delete(agency: event.org.agency!, profileId: event.profileId, token: event.token); + if(success){ + event.organizationMemberships.removeWhere((element) => element.agency!.id == event.org.agency!.id ); + List orgmemberships = event.organizationMemberships; + emit(OrgMembershipDeletedState(organizationMemberships: orgmemberships, success: success)); + }else{ + emit(OrgMembershipDeletedState(organizationMemberships: organizationMemberships, success: success)); + } + }catch(e){ + emit(OrganizationMembershipErrorState(message: e.toString())); + } + }); } } diff --git a/lib/bloc/profile/other_information/org_membership/organization_membership_event.dart b/lib/bloc/profile/other_information/org_membership/organization_membership_event.dart index 9375837..2be3627 100644 --- a/lib/bloc/profile/other_information/org_membership/organization_membership_event.dart +++ b/lib/bloc/profile/other_information/org_membership/organization_membership_event.dart @@ -7,10 +7,39 @@ abstract class OrganizationMembershipEvent extends Equatable { List get props => []; } +class LoadOrganizationMemberships extends OrganizationMembershipEvent{ + final List organizationMemberships; + const LoadOrganizationMemberships({required this.organizationMemberships}); + + @override + List get props => [organizationMemberships]; +} + class GetOrganizationMembership extends OrganizationMembershipEvent{ + final int? profileId; + final String? token; + const GetOrganizationMembership({ this.profileId, this.token}); + +} +class ShowAddOrgMembershipForm extends OrganizationMembershipEvent{ + +} +class AddOrgMembership extends OrganizationMembershipEvent{ final int profileId; final String token; - const GetOrganizationMembership({required this.profileId, required this.token}); - @override - List get props => [profileId,token]; + final Agency agency; + const AddOrgMembership({required this.agency, required this.profileId, required this.token}); + @override + List get props => [profileId,token,agency]; +} + +class DeleteOrgMemberShip extends OrganizationMembershipEvent{ + final int profileId; + final String token; + final OrganizationMembership org; + final List organizationMemberships; + const DeleteOrgMemberShip({required this.profileId, required this.token, required this.org, required this.organizationMemberships}); + @override + List get props => [profileId,token,org,organizationMemberships]; + } diff --git a/lib/bloc/profile/other_information/org_membership/organization_membership_state.dart b/lib/bloc/profile/other_information/org_membership/organization_membership_state.dart index c922624..f84adb7 100644 --- a/lib/bloc/profile/other_information/org_membership/organization_membership_state.dart +++ b/lib/bloc/profile/other_information/org_membership/organization_membership_state.dart @@ -26,3 +26,23 @@ class OrganizationMembershipErrorState extends OrganizationMembershipState{ class OrgmembershipLoadingState extends OrganizationMembershipState{ } +class OrgMembershipDeletedState extends OrganizationMembershipState{ + final List organizationMemberships; + final bool success; + const OrgMembershipDeletedState({required this.organizationMemberships, required this.success}); + @override + List get props => [organizationMemberships,success]; +} +class OrgMembershipAddedState extends OrganizationMembershipState{ + final List orgMemberships; + final Map response; + const OrgMembershipAddedState({required this.orgMemberships, required this.response}); + @override + List get props => [orgMemberships,response]; +} + +class AddOrgMembershipState extends OrganizationMembershipState{ +final List agencies; +final List agencyCategories; +const AddOrgMembershipState({required this.agencies, required this.agencyCategories}); +} diff --git a/lib/bloc/profile/workHistory/workHistory_bloc.dart b/lib/bloc/profile/workHistory/workHistory_bloc.dart index c645ad0..4f42748 100644 --- a/lib/bloc/profile/workHistory/workHistory_bloc.dart +++ b/lib/bloc/profile/workHistory/workHistory_bloc.dart @@ -6,6 +6,7 @@ import 'package:unit2/model/utils/agency.dart'; import 'package:unit2/model/utils/agency_position.dart'; import 'package:unit2/model/utils/position.dart'; import 'package:unit2/sevices/profile/work_history_services.dart'; +import 'package:unit2/utils/profile_utilities.dart'; import '../../../model/utils/category.dart'; @@ -37,6 +38,7 @@ class WorkHistoryBloc extends Bloc { workExperiences = event.workHistories; emit(WorkHistoryLoaded(workExperiences: workExperiences)); }); + ////DELETE on((event, emit) async { emit(WorkHistoryLoadingState()); try { @@ -116,14 +118,14 @@ on((event, emit)async{ /////AGENCIES------------------------------------------ if (agencies.isEmpty) { List newAgencies = - await WorkHistoryService.instance.getAgecies(); + await ProfileUtilities.instance.getAgecies(); agencies = newAgencies; } /////Category Agency------------------------------------------ if (agencyCategory.isEmpty) { List categoryAgencies = - await WorkHistoryService.instance.agencyCategory(); + await ProfileUtilities.instance.agencyCategory(); agencyCategory = categoryAgencies; } /////////------------------------------------- @@ -154,12 +156,12 @@ on((event, emit)async{ /////AGENCIES------------------------------------------ List newAgencies = - await WorkHistoryService.instance.getAgecies(); + await ProfileUtilities.instance.getAgecies(); agencies = newAgencies; /////Category Agency------------------------------------------ List categoryAgencies = - await WorkHistoryService.instance.agencyCategory(); + await ProfileUtilities.instance.agencyCategory(); agencyCategory = categoryAgencies; /////////------------------------------------- List status = diff --git a/lib/model/profile/other_information/non_acedimic_recognition.dart b/lib/model/profile/other_information/non_acedimic_recognition.dart index 9e4b6a7..7d277e0 100644 --- a/lib/model/profile/other_information/non_acedimic_recognition.dart +++ b/lib/model/profile/other_information/non_acedimic_recognition.dart @@ -4,7 +4,7 @@ import 'dart:convert'; -import '../../utils/category.dart'; +import 'package:unit2/model/utils/agency.dart'; NonAcademicRecognition nonAcademicRecognitionFromJson(String str) => NonAcademicRecognition.fromJson(json.decode(str)); @@ -19,12 +19,12 @@ class NonAcademicRecognition { final int? id; final String? title; - final Presenter? presenter; + final Agency? presenter; factory NonAcademicRecognition.fromJson(Map json) => NonAcademicRecognition( id: json["id"], title: json["title"], - presenter: json["presenter"] == null ? null : Presenter.fromJson(json["presenter"]), + presenter: json["presenter"] == null ? null : Agency.fromJson(json["presenter"]), ); Map toJson() => { @@ -34,31 +34,4 @@ class NonAcademicRecognition { }; } -class Presenter { - Presenter({ - this.id, - this.name, - this.category, - this.privateEntity, - }); - - final int? id; - final String? name; - final Category? category; - final bool? privateEntity; - - factory Presenter.fromJson(Map json) => Presenter( - id: json["id"], - name: json["name"], - category: json["category"] == null ? null : Category.fromJson(json["category"]), - privateEntity: json["private_entity"], - ); - - Map toJson() => { - "id": id, - "name": name, - "category": category?.toJson(), - "private_entity": privateEntity, - }; -} diff --git a/lib/screens/profile/components/other_information/non_academic/add_modal.dart b/lib/screens/profile/components/other_information/non_academic/add_modal.dart new file mode 100644 index 0000000..856f105 --- /dev/null +++ b/lib/screens/profile/components/other_information/non_academic/add_modal.dart @@ -0,0 +1,343 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter/src/widgets/placeholder.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_form_builder/flutter_form_builder.dart'; +import 'package:fluttericon/font_awesome_icons.dart'; +import 'package:form_builder_validators/form_builder_validators.dart'; +import 'package:searchfield/searchfield.dart'; +import 'package:unit2/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_bloc.dart'; +import 'package:unit2/bloc/profile/profile_bloc.dart'; +import 'package:unit2/bloc/user/user_bloc.dart'; +import 'package:unit2/model/profile/other_information/non_acedimic_recognition.dart'; +import 'package:unit2/theme-data.dart/form-style.dart'; +import 'package:unit2/utils/global.dart'; + +import '../../../../../model/utils/agency.dart'; +import '../../../../../model/utils/category.dart'; +import '../../../../../theme-data.dart/box_shadow.dart'; +import '../../../../../theme-data.dart/btn-style.dart'; +import '../../../../../theme-data.dart/colors.dart'; + +class AddNonAcademicRecognitionScreen extends StatefulWidget { + const AddNonAcademicRecognitionScreen({super.key}); + + @override + State createState() => + _AddNonAcademicRecognitionScreenState(); +} + +class _AddNonAcademicRecognitionScreenState + extends State { + bool showAgencyCategory = false; + final agencyFocusNode = FocusNode(); + + final agencyCategoryFocusNode = FocusNode(); + final addAgencyController = TextEditingController(); + Agency? selectedAgency; + Category? selectedCategory; + Agency? newAgency; + bool showIsPrivateRadio = false; + bool? isPrivate = false; + NonAcademicRecognition? nonAcademicRecognition; + final _formKey = GlobalKey(); + int? profileId; + String? token; + @override + Widget build(BuildContext context) { + return BlocBuilder( + builder: (context, state) { + if (state is UserLoggedIn) { + return BlocBuilder( + builder: (context, state) { + if (state is ProfileLoaded) { + return BlocBuilder( + builder: (context, state) { + if (state is AddNonAcademeRecognitionState) { + return SizedBox( + height: blockSizeVertical * 90, + child: SingleChildScrollView( + child: FormBuilder(child: Padding( + padding: const EdgeInsets.symmetric(vertical: 25,horizontal: 18), + child: Column( + children: [ + FormBuilderTextField(name: 'title', + decoration: normalTextFieldStyle("Recognition / Award Title *", "Recognition / Award Title"), + validator: FormBuilderValidators.required(errorText: "this field is required"), + ), + const SizedBox(height: 12,), + StatefulBuilder( + builder: (context, setState) { + //// AGENCY SEARCHFIELD + return Column( + children: [ + SearchField( + itemHeight: 70, + suggestions: state.agencies + .map((Agency agency) => + SearchFieldListItem( + agency.name!, + item: agency, + child: ListTile( + title: Text( + agency.name! + .toUpperCase(), + overflow: + TextOverflow + .ellipsis, + ), + subtitle: Text(agency + .privateEntity == + true + ? "Private" + : agency.privateEntity == + false + ? "Government" + : ""), + ))) + .toList(), + validator: FormBuilderValidators + .required( + errorText: + "This field is required"), + focusNode: agencyFocusNode, + searchInputDecoration: + normalTextFieldStyle( + "Agency *", "") + .copyWith( + suffixIcon: + const Icon(Icons + .arrow_drop_down)), + ////agency suggestion tap + onSuggestionTap: (agency) { + setState(() { + selectedAgency = agency.item; + agencyFocusNode.unfocus(); + if (selectedAgency + ?.category == + null) { + showAgencyCategory = true; + showIsPrivateRadio = true; + } else { + showAgencyCategory = false; + showIsPrivateRadio = false; + } + }); + }, + emptyWidget: Container( + decoration: box1(), + height: 100, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + const SizedBox( + height: 20, + ), + const Text( + "No result found..."), + const SizedBox( + height: 10, + ), + TextButton( + //// Add agency onpressed + onPressed: () { + showDialog( + context: + context, + builder: + (BuildContext + context) { + return AlertDialog( + title: const Text( + "Add Agency?"), + content: + SizedBox( + height: + 130, + child: + Column( + children: [ + TextFormField( + controller: + addAgencyController, + decoration: + normalTextFieldStyle("", ""), + ), + const SizedBox( + height: + 12, + ), + SizedBox( + width: double.infinity, + height: 50, + child: ElevatedButton( + style: mainBtnStyle(primary, Colors.transparent, second), + //// onpressed + onPressed: () { + setState(() { + newAgency = Agency(id: null, name: addAgencyController.text.toUpperCase(), category: null, privateEntity: null); + state.agencies.insert(0, newAgency!); + addAgencyController.clear(); + Navigator.pop(context); + }); + }, + child: const Text("Add"))), + ], + ), + ), + ); + }); + }, + child: const Text( + "Add position")) + ]), + ), + ), + const SizedBox( + height: 8, + ), + SizedBox( + child: showAgencyCategory + ? SearchField( + focusNode: + agencyCategoryFocusNode, + itemHeight: 70, + suggestions: state + .agencyCategories + .map((Category + category) => + SearchFieldListItem( + category + .name!, + item: + category, + child: + ListTile( + title: Text( + category + .name!), + subtitle: Text(category + .industryClass! + .name!), + ))) + .toList(), + emptyWidget: Container( + height: 100, + decoration: box1(), + child: const Center( + child: Text( + "No result found ...")), + ), + ////agency controller suggestion tap + onSuggestionTap: + (agencyCategory) { + setState(() { + selectedCategory = + agencyCategory + .item; + + agencyCategoryFocusNode + .unfocus(); + }); + }, + searchInputDecoration: + normalTextFieldStyle( + "Category *", + "") + .copyWith( + suffixIcon: + const Icon( + Icons + .arrow_drop_down)), + validator: + FormBuilderValidators + .required( + errorText: + "This field is required"), + ) + : const SizedBox(), + ), + + ////PRVIATE SECTOR + SizedBox( + child: showIsPrivateRadio + ? FormBuilderRadioGroup( + decoration: + InputDecoration( + border: + InputBorder.none, + label: Row( + children: [ + Text( + "Is this private sector? ", + style: Theme.of( + context) + .textTheme + .headlineSmall! + .copyWith( + fontSize: + 24), + ), + const Icon(FontAwesome + .help_circled) + ], + ), + ), + + ////onvhange private sector + onChanged: (value) { + setState(() { + if (value + .toString() == + "YES") { + isPrivate = true; + } else { + isPrivate = false; + } + }); + }, + + name: 'isPrivate', + validator: + FormBuilderValidators + .required( + errorText: + "This field is required"), + options: ["YES", "NO"] + .map((lang) => + FormBuilderFieldOption( + value: + lang)) + .toList( + growable: + false), + ) + : const SizedBox()), + ], + ); + }) + ], + ), + )), + ) + ); + } + return Container(); + }, + ); + } + return Container(); + }, + ); + } + return Container(); + }, + ); + } +} diff --git a/lib/screens/profile/components/other_information/non_academic_recognition_screen.dart b/lib/screens/profile/components/other_information/non_academic_recognition_screen.dart index e4cb52e..06e4b9b 100644 --- a/lib/screens/profile/components/other_information/non_academic_recognition_screen.dart +++ b/lib/screens/profile/components/other_information/non_academic_recognition_screen.dart @@ -4,6 +4,7 @@ import 'package:flutter_progress_hud/flutter_progress_hud.dart'; import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; +import 'package:unit2/screens/profile/components/other_information/non_academic/add_modal.dart'; import 'package:unit2/theme-data.dart/box_shadow.dart'; import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/utils/global.dart'; @@ -20,12 +21,16 @@ class NonAcademicRecognitionScreen extends StatelessWidget { @override Widget build(BuildContext context) { + int? profileId; + String? token; return Scaffold( appBar: AppBar( title: const Text(nonAcademicRecTitle), centerTitle: true, backgroundColor: primary, - actions: [AddLeading(onPressed: () {})], + actions: [AddLeading(onPressed: () { + context.read().add(ShowAddNonAcademeRecognitionForm()); + })], ), body: ProgressHUD( padding: const EdgeInsets.all(24), @@ -34,6 +39,8 @@ class NonAcademicRecognitionScreen extends StatelessWidget { child: BlocBuilder( builder: (context, state) { if (state is UserLoggedIn) { + token = state.userData!.user!.login!.token; + profileId = state.userData!.user!.login!.user!.profileId!; return BlocBuilder( builder: (context, state) { if (state is ProfileLoaded) { @@ -45,7 +52,7 @@ class NonAcademicRecognitionScreen extends StatelessWidget { progress!.showWithText("Please wait..."); } if (state is NonAcademicRecognitionLoadedState || - state is NonAcademicRecognitionErrorState) { + state is NonAcademicRecognitionErrorState || state is AddNonAcademeRecognitionState) { final progress = ProgressHUD.of(context); progress!.dismiss(); } @@ -116,6 +123,8 @@ class NonAcademicRecognitionScreen extends StatelessWidget { message: "You don't have any Non Academic Recognition added. Please click + to add"); } + }if(state is AddNonAcademeRecognitionState){ + return const AddNonAcademicRecognitionScreen(); } return Container(); }, diff --git a/lib/screens/profile/components/other_information/org_membership/add_modal.dart b/lib/screens/profile/components/other_information/org_membership/add_modal.dart new file mode 100644 index 0000000..0e019f7 --- /dev/null +++ b/lib/screens/profile/components/other_information/org_membership/add_modal.dart @@ -0,0 +1,373 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_form_builder/flutter_form_builder.dart'; +import 'package:fluttericon/font_awesome_icons.dart'; +import 'package:form_builder_validators/form_builder_validators.dart'; +import 'package:searchfield/searchfield.dart'; +import 'package:unit2/bloc/profile/other_information/org_membership/organization_membership_bloc.dart'; +import 'package:unit2/bloc/profile/profile_bloc.dart'; +import 'package:unit2/bloc/user/user_bloc.dart'; +import 'package:unit2/model/utils/agency.dart'; +import 'package:unit2/utils/text_container.dart'; + +import '../../../../../model/utils/category.dart'; +import '../../../../../theme-data.dart/box_shadow.dart'; +import '../../../../../theme-data.dart/btn-style.dart'; +import '../../../../../theme-data.dart/colors.dart'; +import '../../../../../theme-data.dart/form-style.dart'; + +class AddOrgMemberShipScreen extends StatefulWidget { + const AddOrgMemberShipScreen({super.key}); + + @override + State createState() => _AddOrgMemberShipScreenState(); +} + +bool showAgencyCategory = false; +final agencyFocusNode = FocusNode(); + +final agencyCategoryFocusNode = FocusNode(); +final addAgencyController = TextEditingController(); +Agency? selectedAgency; +Category? selectedCategory; +Agency? newAgency; +bool showIsPrivateRadio = false; +bool? isPrivate = false; +final _formKey = GlobalKey(); + int? profileId; + String? token; +class _AddOrgMemberShipScreenState extends State { + @override + Widget build(BuildContext context) { + return BlocBuilder( + builder: (context, state) { + if (state is UserLoggedIn) { + token = state.userData!.user!.login!.token; + profileId = state.userData!.user!.login!.user!.profileId; + return BlocBuilder( + builder: (context, state) { + if (state is ProfileLoaded) { + return BlocBuilder( + builder: (context, state) { + if (state is AddOrgMembershipState) { + return SingleChildScrollView( + child: FormBuilder( + key: _formKey, + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 25, horizontal: 18), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: + CrossAxisAlignment.center, + children: [ + const SizedBox( + height: 100, + ), + StatefulBuilder( + builder: (context, setState) { + //// AGENCY SEARCHFIELD + return Column( + children: [ + SearchField( + itemHeight: 70, + suggestions: state.agencies + .map((Agency agency) => + SearchFieldListItem( + agency.name!, + item: agency, + child: ListTile( + title: Text( + agency.name! + .toUpperCase(), + overflow: + TextOverflow + .ellipsis, + ), + subtitle: Text(agency + .privateEntity == + true + ? "Private" + : agency.privateEntity == + false + ? "Government" + : ""), + ))) + .toList(), + validator: FormBuilderValidators + .required( + errorText: + "This field is required"), + focusNode: agencyFocusNode, + searchInputDecoration: + normalTextFieldStyle( + "Agency *", "") + .copyWith( + suffixIcon: + const Icon(Icons + .arrow_drop_down)), + ////agency suggestion tap + onSuggestionTap: (agency) { + setState(() { + selectedAgency = agency.item; + agencyFocusNode.unfocus(); + if (selectedAgency + ?.category == + null) { + showAgencyCategory = true; + showIsPrivateRadio = true; + } else { + showAgencyCategory = false; + showIsPrivateRadio = false; + } + }); + }, + emptyWidget: Container( + decoration: box1(), + height: 100, + child: Column( + mainAxisAlignment: + MainAxisAlignment + .center, + crossAxisAlignment: + CrossAxisAlignment + .center, + children: [ + const SizedBox( + height: 20, + ), + const Text( + "No result found..."), + const SizedBox( + height: 10, + ), + TextButton( + //// Add agency onpressed + onPressed: () { + showDialog( + context: + context, + builder: + (BuildContext + context) { + return AlertDialog( + title: const Text( + "Add Agency?"), + content: + SizedBox( + height: + 130, + child: + Column( + children: [ + TextFormField( + controller: + addAgencyController, + decoration: + normalTextFieldStyle("", ""), + ), + const SizedBox( + height: + 12, + ), + SizedBox( + width: double.infinity, + height: 50, + child: ElevatedButton( + style: mainBtnStyle(primary, Colors.transparent, second), + //// onpressed + onPressed: () { + setState(() { + newAgency = Agency(id: null, name: addAgencyController.text.toUpperCase(), category: null, privateEntity: null); + state.agencies.insert(0, newAgency!); + addAgencyController.clear(); + Navigator.pop(context); + }); + }, + child: const Text("Add"))), + ], + ), + ), + ); + }); + }, + child: const Text( + "Add position")) + ]), + ), + ), + const SizedBox( + height: 8, + ), + SizedBox( + child: showAgencyCategory + ? SearchField( + focusNode: + agencyCategoryFocusNode, + itemHeight: 70, + suggestions: state + .agencyCategories + .map((Category + category) => + SearchFieldListItem( + category + .name!, + item: + category, + child: + ListTile( + title: Text( + category + .name!), + subtitle: Text(category + .industryClass! + .name!), + ))) + .toList(), + emptyWidget: Container( + height: 100, + decoration: box1(), + child: const Center( + child: Text( + "No result found ...")), + ), + ////agency controller suggestion tap + onSuggestionTap: + (agencyCategory) { + setState(() { + selectedCategory = + agencyCategory + .item; + + agencyCategoryFocusNode + .unfocus(); + }); + }, + searchInputDecoration: + normalTextFieldStyle( + "Category *", + "") + .copyWith( + suffixIcon: + const Icon( + Icons + .arrow_drop_down)), + validator: + FormBuilderValidators + .required( + errorText: + "This field is required"), + ) + : const SizedBox(), + ), + + ////PRVIATE SECTOR + SizedBox( + child: showIsPrivateRadio + ? FormBuilderRadioGroup( + decoration: + InputDecoration( + border: + InputBorder.none, + label: Row( + children: [ + Text( + "Is this private sector? ", + style: Theme.of( + context) + .textTheme + .headlineSmall! + .copyWith( + fontSize: + 24), + ), + const Icon(FontAwesome + .help_circled) + ], + ), + ), + + ////onvhange private sector + onChanged: (value) { + setState(() { + if (value + .toString() == + "YES") { + isPrivate = true; + } else { + isPrivate = false; + } + }); + }, + + name: 'isPrivate', + validator: + FormBuilderValidators + .required( + errorText: + "This field is required"), + options: ["YES", "NO"] + .map((lang) => + FormBuilderFieldOption( + value: + lang)) + .toList( + growable: + false), + ) + : const SizedBox()), + ], + ); + }), + ////SHOW CATEGORY AGENCY + + const SizedBox( + height: 24, + ), + SizedBox( + height: 60, + width: double.infinity, + child: ElevatedButton( + style: mainBtnStyle(primary, + Colors.transparent, second), + onPressed: () { + if (_formKey.currentState! + .saveAndValidate()) { + if(selectedAgency?.privateEntity != null){ + newAgency = selectedAgency; + }else{ + newAgency = Agency( + id: selectedAgency?.id, + name: selectedAgency!.name, + category: + selectedCategory, + privateEntity: isPrivate); + } + + context.read().add(AddOrgMembership(agency: newAgency!, profileId: profileId!, token: token!)); + setState(() { + showAgencyCategory = false; + showIsPrivateRadio = false; + }); + } + }, + child: const Text(submit)), + ) + ]), + )), + ); + } + return Container(); + }, + ); + } + return Container(); + }, + ); + } + return const Placeholder(); + }, + ); + } +} diff --git a/lib/screens/profile/components/other_information/org_membership_screen.dart b/lib/screens/profile/components/other_information/org_membership_screen.dart index df8cc9e..7ade0c0 100644 --- a/lib/screens/profile/components/other_information/org_membership_screen.dart +++ b/lib/screens/profile/components/other_information/org_membership_screen.dart @@ -1,16 +1,21 @@ +import 'package:app_popup_menu/app_popup_menu.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:fluttericon/font_awesome_icons.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/user/user_bloc.dart'; import 'package:unit2/model/profile/other_information/organization_memberships.dart'; +import 'package:unit2/screens/profile/components/other_information/org_membership/add_modal.dart'; import 'package:unit2/theme-data.dart/box_shadow.dart'; import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/utils/text_container.dart'; import 'package:unit2/widgets/Leadings/add_leading.dart'; +import 'package:unit2/widgets/Leadings/close_leading.dart'; import 'package:unit2/widgets/empty_data.dart'; import '../../../../bloc/profile/other_information/org_membership/organization_membership_bloc.dart'; +import '../../../../utils/alerts.dart'; import '../../../../utils/global.dart'; class OrgMembershipsScreen extends StatelessWidget { @@ -18,12 +23,22 @@ class OrgMembershipsScreen extends StatelessWidget { @override Widget build(BuildContext context) { + String? token; + int profileId; return Scaffold( appBar: AppBar( title: const Text(orgMembershipTitle), backgroundColor: primary, centerTitle: true, - actions: [AddLeading(onPressed: () {})], + actions: context.watch().state is OrganizationMembershipLoaded?[ + AddLeading(onPressed: () { + context + .read() + .add(ShowAddOrgMembershipForm()); + }) + ]: context.watch().state is AddOrgMembershipState ?[CloseLeading(onPressed: (){ + context.read().add(const GetOrganizationMembership()); + })]:[] ), body: ProgressHUD( padding: const EdgeInsets.all(24), @@ -32,20 +47,68 @@ class OrgMembershipsScreen extends StatelessWidget { child: BlocBuilder( builder: (context, state) { if (state is UserLoggedIn) { + token = state.userData!.user!.login!.token; + profileId = state.userData!.user!.login!.user!.profileId!; return BlocBuilder( builder: (context, state) { if (state is ProfileLoaded) { return BlocConsumer( listener: (context, state) { - if(state is OrgmembershipLoadingState){ + if (state is OrgmembershipLoadingState) { final progress = ProgressHUD.of(context); progress!.showWithText("Please wait..."); - } - if(state is OrganizationMembershipLoaded || state is OrganizationMembershipErrorState){ + } + if (state is OrganizationMembershipLoaded || + state is OrganizationMembershipErrorState || + state is AddOrgMembershipState || state is OrgMembershipDeletedState) { final progress = ProgressHUD.of(context); progress!.dismiss(); - } + } + ////ADDED STATE + if (state is OrgMembershipAddedState) { + if (state.response['success']) { + successAlert(context, "Adding Successfull!", + state.response['message'], () { + Navigator.of(context).pop(); + context.read().add( + LoadOrganizationMemberships( + organizationMemberships: + state.orgMemberships)); + }); + } else { + errorAlert(context, "Adding Failed", + "Something went wrong. Please try again.", + () { + Navigator.of(context).pop(); + context.read().add( + LoadOrganizationMemberships( + organizationMemberships: + state.orgMemberships)); + }); + } + } + ////DELETED STATE + if (state is OrgMembershipDeletedState) { + if (state.success) { + successAlert(context, "Deletion Successfull", + "Work has been deleted successfully", () { + Navigator.of(context).pop(); + context.read().add( + LoadOrganizationMemberships( + organizationMemberships: state.organizationMemberships)); + }); + } else { + errorAlert(context, "Deletion Failed", + "Error deleting Work History", () { + Navigator.of(context).pop(); + context.read().add( + LoadOrganizationMemberships( + organizationMemberships: state.organizationMemberships)); + }); + } + } + }, builder: (context, state) { if (state is OrganizationMembershipLoaded) { @@ -55,8 +118,7 @@ class OrgMembershipsScreen extends StatelessWidget { vertical: 8, horizontal: 10), itemBuilder: (BuildContext context, int index) { String entity = state.orgMemberships[index] - .agency! - .privateEntity == + .agency!.privateEntity == false ? governmentText.toUpperCase() : privateText.toUpperCase(); @@ -95,12 +157,37 @@ class OrgMembershipsScreen extends StatelessWidget { ), ], )), - IconButton( - onPressed: () {}, + AppPopupMenu( + offset: const Offset(-10, -10), + elevation: 3, + onSelected: (value) { + final progress = + ProgressHUD.of(context); + progress! + .showWithText("Loading..."); + ////delete orgmembership-= = = = = = = = =>> + if (value == 1) { + confirmAlert(context, () { + context.read().add(DeleteOrgMemberShip(profileId: profileId, token: token!, org: state.orgMemberships[index], organizationMemberships: state.orgMemberships)); + }, "Delete?", + "Confirm Delete?"); + } + + }, + menuItems: [ + + popMenuItem( + text: "Delete", + value: 1, + icon: Icons.delete), + + ], icon: const Icon( Icons.more_vert, color: Colors.grey, - )) + ), + tooltip: "Options", + ) ]), ), const SizedBox( @@ -110,6 +197,11 @@ class OrgMembershipsScreen extends StatelessWidget { ); }); } + if (state is AddOrgMembershipState) { + return const AddOrgMemberShipScreen(); + }if(state is OrganizationMembershipErrorState){ + return Container(child: Text(state.message),); + } return Container(); }, ); @@ -124,5 +216,24 @@ class OrgMembershipsScreen extends StatelessWidget { )); } } +PopupMenuItem popMenuItem({String? text, int? value, IconData? icon}) { + return PopupMenuItem( + value: value, + child: Row( + children: [ + Icon( + icon, + ), + const SizedBox( + width: 10, + ), + Text( + text!, + ), + ], + ), + ); +} + // const EmptyData(message: "You don't have any Organization Membership added. Please click + to add."), diff --git a/lib/screens/profile/components/work_history/add_modal.dart b/lib/screens/profile/components/work_history/add_modal.dart index d8382e3..3a9be0b 100644 --- a/lib/screens/profile/components/work_history/add_modal.dart +++ b/lib/screens/profile/components/work_history/add_modal.dart @@ -256,7 +256,7 @@ class _AddWorkHistoryScreenState extends State { agency.privateEntity == true ? "Private" - : "Government"), + : agency.privateEntity == false? "Government":""), ))) .toList(), searchInputDecoration: diff --git a/lib/sevices/profile/non_academic_services.dart b/lib/sevices/profile/non_academic_services.dart index 88812c7..46f2b32 100644 --- a/lib/sevices/profile/non_academic_services.dart +++ b/lib/sevices/profile/non_academic_services.dart @@ -1,6 +1,7 @@ import 'dart:convert'; import 'package:http/http.dart' as http; +import 'package:unit2/bloc/profile/other_information/non_academic_recognition.dart/non_academic_recognition_bloc.dart'; import 'package:unit2/utils/request.dart'; import '../../model/profile/other_information/non_acedimic_recognition.dart'; @@ -10,7 +11,7 @@ class NonAcademicRecognitionServices { static final NonAcademicRecognitionServices _instance = NonAcademicRecognitionServices(); static NonAcademicRecognitionServices get instance => _instance; - +////GET Future> getNonAcademicRecognition( int profileId, String token) async { List nonAcademicRecognitions = []; @@ -35,7 +36,74 @@ class NonAcademicRecognitionServices { } } catch (e) { throw e.toString(); - } +} return nonAcademicRecognitions; } + +////ADD + Future> add( + {required String token, + required int profileId, + required NonAcademicRecognition nonAcademicRecognition}) async { + String authToken = "Token $token"; + String path = "${Url.instance.getNonAcademicRecognition()}$profileId/"; + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': authToken + }; + Map body = { + "title": nonAcademicRecognition.title, + "presenter_id": nonAcademicRecognition.presenter?.id, + "_presenterName": nonAcademicRecognition.presenter!.name, + "_presenterCatId": nonAcademicRecognition.presenter!.category!.id, + "_privateEntity": nonAcademicRecognition.presenter!.privateEntity, + }; + + Map statusResponse = {}; + try { + http.Response response = await Request.instance + .postRequest(path: path, body: body, param: {}, headers: headers); + if (response.statusCode == 201) { + Map data = jsonDecode(response.body); + statusResponse = data; + } else { + statusResponse.addAll({"success": false}); + } + } catch (e) { + throw e.toString(); + } + return statusResponse; + } + +////DELETE + + Future delete( + {required String title, + required int id, + required String token, + required int profileId}) async { + String authToken = "Token $token"; + Map params = {"force_mode": "true"}; + String path = "${Url.instance.getNonAcademicRecognition()}$profileId/"; + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': authToken + }; + bool success = false; + Map body = { + "id": id, + "title": title, + }; + try { + http.Response response = await Request.instance.deleteRequest( + path: path, headers: headers, body: body, param: params); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + success = data['success']; + } + } catch (e) { + throw e.toString(); + } + return success; + } } diff --git a/lib/sevices/profile/orgmembership_services.dart b/lib/sevices/profile/orgmembership_services.dart index 6bf8fd4..424646e 100644 --- a/lib/sevices/profile/orgmembership_services.dart +++ b/lib/sevices/profile/orgmembership_services.dart @@ -5,6 +5,7 @@ import 'package:unit2/utils/request.dart'; import '../../model/profile/other_information/organization_memberships.dart'; import 'package:http/http.dart' as http; +import '../../model/utils/agency.dart'; import '../../utils/urls.dart'; class OrganizationMembershipServices { @@ -39,4 +40,56 @@ class OrganizationMembershipServices { } return orgMemberships; } + Future>add({required Agency? agency,required String token, required String profileId})async{ + String authToken = "Token $token"; + String path = "${Url.instance.getOrgMemberShips()}$profileId/"; + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': authToken + }; + Map statusResponse = {}; + Map body = { + "agency_id": agency?.id, + "_agencyName": agency!.name, + "_agencyCatId": agency.category!.id, + "_privateEntity": agency.privateEntity + }; + try{ + http.Response response = await Request.instance.postRequest(path: path,body: body,headers: headers,param: {}); + if(response.statusCode == 201){ + Map data = jsonDecode(response.body); + statusResponse = data; + }else{ + statusResponse.addAll({"success":false}); + } + }catch(e){ + throw e.toString(); + } + return statusResponse; + + } + + Future delete({required Agency agency, required int profileId, required String token})async{ + bool success = false; + Map params = {"force_mode": "true"}; + String authToken = "Token $token"; + String path = "${Url.instance.getOrgMemberShips()}$profileId/"; + Map body ={ + "agency_id": agency.id + }; + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + 'Authorization': authToken + }; + try{ + http.Response response = await Request.instance.deleteRequest(path: path, headers: headers, body: body, param: params); + if(response.statusCode == 200){ + Map data = jsonDecode(response.body); + success = data["success"]; + } + }catch(e){ + throw e.toString(); + } + return success; + } } diff --git a/lib/sevices/profile/work_history_services.dart b/lib/sevices/profile/work_history_services.dart index 92906f7..bd0f595 100644 --- a/lib/sevices/profile/work_history_services.dart +++ b/lib/sevices/profile/work_history_services.dart @@ -42,30 +42,6 @@ class WorkHistoryService { return workExperiences; } -//get agencies - Future> getAgecies() async { - List agencies = []; - String path = Url.instance.getAgencies(); - Map headers = { - 'Content-Type': 'application/json; charset=UTF-8', - }; - try { - http.Response response = await Request.instance - .getRequest(path: path, param: {}, headers: headers); - if (response.statusCode == 200) { - Map data = jsonDecode(response.body); - if (data['data'] != null) { - data['data'].forEach((var agency) { - Agency newAgency = Agency.fromJson(agency); - agencies.add(newAgency); - }); - } - } - } catch (e) { - throw e.toString(); - } - return agencies; - } //delete workhistory Future delete( @@ -107,30 +83,6 @@ class WorkHistoryService { return success!; } -//get agency category - Future> agencyCategory() async { - List agencyCategory = []; - String path = Url.instance.getAgencyCategory(); - Map headers = { - 'Content-Type': 'application/json; charset=UTF-8', - }; - try { - http.Response response = await Request.instance - .getRequest(param: {}, path: path, headers: headers); - if (response.statusCode == 200) { - Map data = jsonDecode(response.body); - if (data['data'] != null) { - data['data'].forEach((var agency) { - Category category = Category.fromJson(agency); - agencyCategory.add(category); - }); - } - } - } catch (e) { - throw e.toString(); - } - return agencyCategory; - } //edit work history Future> update({required WorkHistory oldWorkHistory, required WorkHistory newWorkHistory, required String token, required String profileId})async{ diff --git a/lib/utils/profile_utilities.dart b/lib/utils/profile_utilities.dart index 68ef45b..50ec5d3 100644 --- a/lib/utils/profile_utilities.dart +++ b/lib/utils/profile_utilities.dart @@ -7,6 +7,9 @@ import 'package:unit2/model/location/region.dart'; import 'package:unit2/model/utils/eligibility.dart'; import 'package:unit2/utils/request.dart'; import 'package:unit2/utils/urls.dart'; + +import '../model/utils/agency.dart'; +import '../model/utils/category.dart'; class ProfileUtilities { static final ProfileUtilities _instance = ProfileUtilities(); static ProfileUtilities get instance => _instance; @@ -35,4 +38,56 @@ class ProfileUtilities { return eligibilities; } + //get agencies + Future> getAgecies() async { + List agencies = []; + String path = Url.instance.getAgencies(); + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + }; + try { + http.Response response = await Request.instance + .getRequest(path: path, param: {}, headers: headers); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + if (data['data'] != null) { + data['data'].forEach((var agency) { + Agency newAgency = Agency.fromJson(agency); + agencies.add(newAgency); + }); + } + } + } catch (e) { + throw e.toString(); + } + return agencies; + } + + +//get agency category + Future> agencyCategory() async { + List agencyCategory = []; + String path = Url.instance.getAgencyCategory(); + Map headers = { + 'Content-Type': 'application/json; charset=UTF-8', + }; + try { + http.Response response = await Request.instance + .getRequest(param: {}, path: path, headers: headers); + if (response.statusCode == 200) { + Map data = jsonDecode(response.body); + if (data['data'] != null) { + data['data'].forEach((var agency) { + Category category = Category.fromJson(agency); + agencyCategory.add(category); + }); + } + } + } catch (e) { + throw e.toString(); + } + return agencyCategory; + } + + } \ No newline at end of file diff --git a/lib/utils/urls.dart b/lib/utils/urls.dart index a7972ea..578ab1b 100644 --- a/lib/utils/urls.dart +++ b/lib/utils/urls.dart @@ -4,10 +4,10 @@ class Url { String host() { // return '192.168.10.221:3003'; - return 'agusandelnorte.gov.ph'; + // return 'agusandelnorte.gov.ph'; // return "192.168.10.219:3000"; // return "devweb.agusandelnorte.gov.ph"; - // return 'devapi.agusandelnorte.gov.ph:3004'; + return 'devapi.agusandelnorte.gov.ph:3004'; } String authentication() {