From 7795b5883baccec091583f0f4884a140607e6762 Mon Sep 17 00:00:00 2001 From: PGAN-MIS Date: Wed, 8 Feb 2023 16:06:27 +0800 Subject: [PATCH] integrated family background API --- lib/model/profile/family_backround.dart | 310 ++++++++++++++++++ lib/model/profile/profileInfomation.dart | 4 +- .../components/family_background_screen.dart | 189 +++++++++++ lib/screens/profile/profile.dart | 7 +- .../homepage.dart/components/menu-screen.dart | 84 +++-- .../unit2/homepage.dart/module-screen.dart | 49 ++- lib/sevices/profile/profile_service.dart | 11 + 7 files changed, 584 insertions(+), 70 deletions(-) create mode 100644 lib/screens/profile/components/family_background_screen.dart diff --git a/lib/model/profile/family_backround.dart b/lib/model/profile/family_backround.dart index e69de29..9083cb7 100644 --- a/lib/model/profile/family_backround.dart +++ b/lib/model/profile/family_backround.dart @@ -0,0 +1,310 @@ +// To parse this JSON data, do +// +// final familyBackground = familyBackgroundFromJson(jsonString); + +import 'dart:convert'; +import 'dart:ffi'; + +FamilyBackground familyBackgroundFromJson(String str) => FamilyBackground.fromJson(json.decode(str)); + +String familyBackgroundToJson(FamilyBackground data) => json.encode(data.toJson()); + +class FamilyBackground { + FamilyBackground({ + this.company, + this.position, + this.relationship, + this.relatedPerson, + this.companyAddress, + this.emergencyContact, + this.incaseOfEmergency, + this.companyContactNumber, + }); + + final Company? company; + final Position? position; + final Relationship? relationship; + final RelatedPerson? relatedPerson; + final String? companyAddress; + final List? emergencyContact; + final bool? incaseOfEmergency; + final String? companyContactNumber; + + factory FamilyBackground.fromJson(Map json) => FamilyBackground( + company: json["company"] == null ? null : Company.fromJson(json["company"]), + position: json["position"] == null ? null : Position.fromJson(json["position"]), + relationship: json["relationship"] == null ? null : Relationship.fromJson(json["relationship"]), + relatedPerson: json["related_person"] == null ? null : RelatedPerson.fromJson(json["related_person"]), + companyAddress: json["company_address"], + emergencyContact: json["emergency_contact"] == null ? [] : List.from(json["emergency_contact"]!.map((x) => EmergencyContact.fromJson(x))), + incaseOfEmergency: json["incase_of_emergency"], + companyContactNumber: json["company_contact_number"], + ); + + Map toJson() => { + "company": company?.toJson(), + "position": position?.toJson(), + "relationship": relationship?.toJson(), + "related_person": relatedPerson?.toJson(), + "company_address": companyAddress, + "emergency_contact": emergencyContact == null ? [] : List.from(emergencyContact!.map((x) => x.toJson())), + "incase_of_emergency": incaseOfEmergency, + "company_contact_number": companyContactNumber, + }; +} + +class Company { + Company({ + this.id, + this.name, + this.category, + this.privateEntity, + }); + + final int? id; + final String? name; + final Category? category; + final bool? privateEntity; + + factory Company.fromJson(Map json) => Company( + 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, + }; +} + +class Category { + Category({ + this.id, + this.name, + this.industryClass, + }); + + final int? id; + final String? name; + final IndustryClass? industryClass; + + factory Category.fromJson(Map json) => Category( + id: json["id"], + name: json["name"], + industryClass: json["industry_class"] == null ? null : IndustryClass.fromJson(json["industry_class"]), + ); + + Map toJson() => { + "id": id, + "name": name, + "industry_class": industryClass?.toJson(), + }; +} + +class IndustryClass { + IndustryClass({ + this.id, + this.name, + this.description, + }); + + final int? id; + final String? name; + final String? description; + + factory IndustryClass.fromJson(Map json) => IndustryClass( + id: json["id"], + name: json["name"], + description: json["description"], + ); + + Map toJson() => { + "id": id, + "name": name, + "description": description, + }; +} + +class EmergencyContact { + EmergencyContact({ + this.telco, + this.isactive, + this.provider, + this.isprimary, + this.numbermail, + this.serviceType, + this.contactinfoid, + this.commServiceId, + }); + + final String? telco; + final bool? isactive; + final int? provider; + final bool? isprimary; + final String? numbermail; + final int? serviceType; + final int? contactinfoid; + final int? commServiceId; + + factory EmergencyContact.fromJson(Map json) => EmergencyContact( + telco: json["telco"], + isactive: json["isactive"], + provider: json["provider"], + isprimary: json["isprimary"], + numbermail: json["numbermail"], + serviceType: json["service_type"], + contactinfoid: json["contactinfoid"], + commServiceId: json["comm_service_id"], + ); + + Map toJson() => { + "telco": telco, + "isactive": isactive, + "provider": provider, + "isprimary": isprimary, + "numbermail": numbermail, + "service_type": serviceType, + "contactinfoid": contactinfoid, + "comm_service_id": commServiceId, + }; +} + +class Position { + Position({ + this.id, + this.title, + }); + + final int? id; + final String? title; + + factory Position.fromJson(Map json) => Position( + id: json["id"], + title: json["title"], + ); + + Map toJson() => { + "id": id, + "title": title, + }; +} + +class RelatedPerson { + RelatedPerson({ + this.id, + this.sex, + this.gender, + this.deceased, + this.heightM, + this.birthdate, + this.esigPath, + this.lastName, + this.weightKg, + this.bloodType, + this.firstName, + this.photoPath, + this.maidenName, + this.middleName, + this.uuidQrcode, + this.civilStatus, + this.titlePrefix, + this.titleSuffix, + this.showTitleId, + this.nameExtension, + }); + + final int? id; + final String? sex; + final String? gender; + final bool? deceased; + final double? heightM; + final DateTime? birthdate; + final String? esigPath; + final String? lastName; + final double? weightKg; + final String? bloodType; + final String? firstName; + final String? photoPath; + final dynamic maidenName; + final String? middleName; + final String? uuidQrcode; + final String? civilStatus; + final String? titlePrefix; + final String? titleSuffix; + final bool? showTitleId; + final String? nameExtension; + + factory RelatedPerson.fromJson(Map json) => RelatedPerson( + id: json["id"], + sex: json["sex"], + gender: json["gender"], + deceased: json["deceased"], + heightM: json["height_m"] == null?null:double.parse(json["height_m"].toString()), + birthdate: json["birthdate"] == null ? null : DateTime.parse(json["birthdate"]), + esigPath: json["esig_path"], + lastName: json["last_name"], + weightKg: json["weight_kg"] == null? null:double.parse(json["weight_kg"].toString()) , + bloodType: json["blood_type"], + firstName: json["first_name"], + photoPath: json["photo_path"], + maidenName: json["maiden_name"], + middleName: json["middle_name"], + uuidQrcode: json["uuid_qrcode"], + civilStatus: json["civil_status"], + titlePrefix: json["title_prefix"], + titleSuffix: json["title_suffix"], + showTitleId: json["show_title_id"], + nameExtension: json["name_extension"], + ); + + Map toJson() => { + "id": id, + "sex": sex, + "gender": gender, + "deceased": deceased, + "height_m": heightM, + "birthdate": "${birthdate!.year.toString().padLeft(4, '0')}-${birthdate!.month.toString().padLeft(2, '0')}-${birthdate!.day.toString().padLeft(2, '0')}", + "esig_path": esigPath, + "last_name": lastName, + "weight_kg": weightKg, + "blood_type": bloodType, + "first_name": firstName, + "photo_path": photoPath, + "maiden_name": maidenName, + "middle_name": middleName, + "uuid_qrcode": uuidQrcode, + "civil_status": civilStatus, + "title_prefix": titlePrefix, + "title_suffix": titleSuffix, + "show_title_id": showTitleId, + "name_extension": nameExtension, + }; +} + +class Relationship { + Relationship({ + this.id, + this.type, + this.category, + }); + + final int? id; + final String? type; + final String? category; + + factory Relationship.fromJson(Map json) => Relationship( + id: json["id"], + type: json["type"], + category: json["category"], + ); + + Map toJson() => { + "id": id, + "type": type, + "category": category, + }; +} diff --git a/lib/model/profile/profileInfomation.dart b/lib/model/profile/profileInfomation.dart index 63bd116..37987fb 100644 --- a/lib/model/profile/profileInfomation.dart +++ b/lib/model/profile/profileInfomation.dart @@ -2,6 +2,7 @@ import 'package:unit2/model/profile/basic_info.dart'; import 'package:unit2/model/profile/basic_information/primary-information.dart'; import 'package:unit2/model/profile/educational_background.dart'; import 'package:unit2/model/profile/eligibility.dart'; +import 'package:unit2/model/profile/family_backround.dart'; import 'package:unit2/model/profile/learning_development.dart'; import 'package:unit2/model/profile/other_info.dart'; import 'package:unit2/model/profile/references.dart'; @@ -15,7 +16,8 @@ class ProfileInformation{ List references; List learningsAndDevelopment; List educationalBackgrounds; + List families; ListworkExperiences; List voluntaryWorks; - ProfileInformation({required this.otherInformation, required this.voluntaryWorks, required this.workExperiences, required this.basicInfo,required this.eligibilities,required this.references, required this.learningsAndDevelopment,required this.educationalBackgrounds}); + ProfileInformation({required this.families, required this.otherInformation, required this.voluntaryWorks, required this.workExperiences, required this.basicInfo,required this.eligibilities,required this.references, required this.learningsAndDevelopment,required this.educationalBackgrounds}); } \ No newline at end of file diff --git a/lib/screens/profile/components/family_background_screen.dart b/lib/screens/profile/components/family_background_screen.dart new file mode 100644 index 0000000..7668ff7 --- /dev/null +++ b/lib/screens/profile/components/family_background_screen.dart @@ -0,0 +1,189 @@ +import 'dart:math'; + +import 'package:flutter/material.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter/src/widgets/placeholder.dart'; +import 'package:unit2/model/profile/family_backround.dart'; +import 'package:unit2/theme-data.dart/colors.dart'; +import 'package:unit2/utils/global.dart'; + +class FamilyBackgroundScreen extends StatefulWidget { + final List familyBackground; + const FamilyBackgroundScreen({super.key, required this.familyBackground}); + + @override + State createState() => _FamilyBackgroundScreenState(); +} + +class _FamilyBackgroundScreenState extends State { + FamilyBackground? father; + FamilyBackground? mother; + FamilyBackground? spouse; + List children = []; + List otherRelated = []; + @override + Widget build(BuildContext context) { + father = widget.familyBackground.firstWhere((element) => element.relationship!.id==1); + mother = widget.familyBackground.firstWhere((element) => element.relationship!.id==2); + spouse = widget.familyBackground.firstWhere((element) => element.relationship!.id==3); + var childs = widget.familyBackground.where((element) => element.relationship!.id==4); + if(childs.isNotEmpty){ + for (var element in childs) { + children.add(element); + } + } + var relateds = widget.familyBackground.where((element) => element.relationship!.id! < 4); + if(relateds.isNotEmpty){ + for (var element in childs) { + otherRelated.add(element); + } + } + return Scaffold( + appBar: AppBar(title: const Text("Addresses"), centerTitle: true, backgroundColor: primary,), + body: Column( + children: [ + //Father + Container( + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: const BorderRadius.all(Radius.circular(12))), + padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8), + width: screenWidth, + child: Row( + children: [ + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text("Father"), + Text("${father!.relatedPerson!.firstName} ${father!.relatedPerson!.middleName} ${father!.relatedPerson!.lastName} ${father!.relatedPerson!.nameExtension??''}"), + const Text("Full Name"), + Row(children: [ + Checkbox(value: false, onChanged: (value){}), + const Text("Incase of emergency") + ],) + ]), + ), + IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert)) + ], + ),), + const SizedBox(height: 5,), + //Mother + Container( + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: const BorderRadius.all(Radius.circular(12))), + padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8), + width: screenWidth, + child: Row( + children: [ + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text("Mother"), + Text("${mother!.relatedPerson!.firstName} ${mother!.relatedPerson!.middleName} ${mother!.relatedPerson!.lastName} ${mother!.relatedPerson!.nameExtension??''}"), + const Text("Full Name"), + Row(children: [ + Checkbox(value: false, onChanged: (value){}), + const Text("Incase of emergency") + ],) + ]), + ), + IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert)) + ], + ),), + const SizedBox(height: 5,), + //Spouse + spouse != null? + Container( + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: const BorderRadius.all(Radius.circular(12))), + padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8), + width: screenWidth, + child: Row( + children: [ + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text("Spouse"), + Text("${spouse!.relatedPerson!.firstName} ${spouse!.relatedPerson!.middleName} ${spouse!.relatedPerson!.lastName} ${spouse!.relatedPerson!.nameExtension??''}"), + const Text("Full Name"), + Row(children: [ + Checkbox(value: false, onChanged: (value){}), + const Text("Incase of emergency") + ],) + ]), + ), + IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert)) + ], + ),):const SizedBox(), + const SizedBox(height: 5,), + +// Childrens + children.isNotEmpty?Expanded( + child: ListView( + children: children.map((child) => Container( + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: const BorderRadius.all(Radius.circular(12))), + padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8), + width: screenWidth, + child: Row( + children: [ + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text("Children"), + Text("${child.relatedPerson!.firstName} ${child.relatedPerson!.middleName} ${child.relatedPerson!.lastName} ${child.relatedPerson!.nameExtension??''}"), + const Text("Full Name"), + Row(children: [ + Checkbox(value: false, onChanged: (value){}), + const Text("Incase of emergency") + ],) + ]), + ), + IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert)) + ], + ),),).toList()), + ):const SizedBox(), + + otherRelated.isNotEmpty?Expanded( + child: ListView( + children: otherRelated.map((relative) => Container( + decoration: BoxDecoration( + color: Colors.grey[200], + borderRadius: const BorderRadius.all(Radius.circular(12))), + padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8), + width: screenWidth, + child: Row( + children: [ + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text("Other related Person(s)"), + Text("${relative.relatedPerson!.firstName} ${relative!.relatedPerson!.middleName} ${relative!.relatedPerson!.lastName} ${relative!.relatedPerson!.nameExtension??''}"), + const Text("Full Name"), + Row(children: [ + Checkbox(value: false, onChanged: (value){}), + const Text("Incase of emergency") + ],) + ]), + ), + IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert)) + ], + ),),).toList()), + ):const SizedBox() + ]), + ); + } +} \ No newline at end of file diff --git a/lib/screens/profile/profile.dart b/lib/screens/profile/profile.dart index d9280f6..05ca514 100644 --- a/lib/screens/profile/profile.dart +++ b/lib/screens/profile/profile.dart @@ -15,6 +15,7 @@ import 'package:unit2/screens/profile/components/basic_information/identificatio import 'package:unit2/screens/profile/components/basic_information/primary_information.dart'; import 'package:unit2/screens/profile/components/education_screen.dart'; import 'package:unit2/screens/profile/components/eligibility.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/loading_screen.dart'; import 'package:unit2/screens/profile/components/other_information/non_academic_recognition.dart'; @@ -122,7 +123,11 @@ class _ProfileInfoState extends State { MainMenu( icon: Elusive.group, title: "Family", - onTap: (){}, + onTap: (){ + Navigator.push(context, MaterialPageRoute(builder: (BuildContext context){ + return FamilyBackgroundScreen(familyBackground: state.profileInformation.families); + })); + }, ), const Divider(), MainMenu( diff --git a/lib/screens/unit2/homepage.dart/components/menu-screen.dart b/lib/screens/unit2/homepage.dart/components/menu-screen.dart index 7a059ba..b06a8de 100644 --- a/lib/screens/unit2/homepage.dart/components/menu-screen.dart +++ b/lib/screens/unit2/homepage.dart/components/menu-screen.dart @@ -21,53 +21,51 @@ class _MenuScreenState extends State { widget.userData!.user!.login!.user!.firstName!.toUpperCase(); final String lastname = widget.userData!.user!.login!.user!.lastName!.toUpperCase(); - return SafeArea( - child: Drawer( - child: SingleChildScrollView( - child: SizedBox( - height: blockSizeVertical * 96, - child: Column( - // ignore: prefer_const_literals_to_create_immutables - children: [ - UserAccountsDrawerHeader( - decoration: const BoxDecoration( - color: primary, - image: DecorationImage( - image: AssetImage('assets/pngs/bg.png'), - fit: BoxFit.cover)), - accountName: Text("$firstName $lastname"), - accountEmail: null, - currentAccountPicture: CircleAvatar( - radius: 40, - backgroundColor: fifth, - child: CircleAvatar( - radius: 33, - backgroundColor: third, - child: //Icon(Icons.person, size: 40, color: fifth), - Text( - firstName[0].toUpperCase(), - style: const TextStyle(fontSize: 45.0, color: fifth), - ), + return Drawer( + child: SingleChildScrollView( + child: SizedBox( + height: blockSizeVertical * 96, + child: Column( + // ignore: prefer_const_literals_to_create_immutables + children: [ + UserAccountsDrawerHeader( + decoration: const BoxDecoration( + color: primary, + image: DecorationImage( + image: AssetImage('assets/pngs/bg.png'), + fit: BoxFit.cover)), + accountName: Text("$firstName $lastname"), + accountEmail: null, + currentAccountPicture: CircleAvatar( + radius: 40, + backgroundColor: fifth, + child: CircleAvatar( + radius: 33, + backgroundColor: third, + child: //Icon(Icons.person, size: 40, color: fifth), + Text( + firstName[0].toUpperCase(), + style: const TextStyle(fontSize: 45.0, color: fifth), ), ), ), - getTile(FontAwesome5.user, "Basic Info", '/basic-info', context, + ), + getTile(FontAwesome5.user, "Basic Info", '/basic-info', context, + widget.userData!), + const Divider(), + getTile(FontAwesome5.user_circle, "Profile", + '/profile', context, widget.userData!), + const Divider(), + getTile(FontAwesome5.life_ring, "Request SOS", '/request-sos', + context, widget.userData!), + const Divider(), + Expanded( + child: Align( + alignment: FractionalOffset.bottomLeft, + child: getTile(WebSymbols.logout, "Logout", 'login', context, widget.userData!), - const Divider(), - getTile(FontAwesome5.user_circle, "Profile", - '/profile', context, widget.userData!), - const Divider(), - getTile(FontAwesome5.life_ring, "Request SOS", '/request-sos', - context, widget.userData!), - const Divider(), - Expanded( - child: Align( - alignment: FractionalOffset.bottomLeft, - child: getTile(WebSymbols.logout, "Logout", 'login', context, - widget.userData!), - )), - ], - ), + )), + ], ), ), ), diff --git a/lib/screens/unit2/homepage.dart/module-screen.dart b/lib/screens/unit2/homepage.dart/module-screen.dart index e8aa371..df1f7d7 100644 --- a/lib/screens/unit2/homepage.dart/module-screen.dart +++ b/lib/screens/unit2/homepage.dart/module-screen.dart @@ -47,34 +47,33 @@ class _MainScreenState extends State { } }); }); - return SafeArea( - child: Scaffold( + return Scaffold( appBar: AppBar( - backgroundColor: primary, - leading: IconButton( - onPressed: () { - ZoomDrawer.of(context)!.toggle(); - }, - icon: const Icon( - Icons.menu, - color: Colors.white, - ), - ), - centerTitle: true, - title: const Text( - unit2ModuleScreen, - style: TextStyle( - fontSize: 18.0, - color: Colors.white, - ), - ), + backgroundColor: primary, + leading: IconButton( + onPressed: () { + ZoomDrawer.of(context)!.toggle(); + }, + icon: const Icon( + Icons.menu, + color: Colors.white, + ), + ), + centerTitle: true, + title: const Text( + unit2ModuleScreen, + style: TextStyle( + fontSize: 18.0, + color: Colors.white, + ), + ), ), body: state.userData!.user!.login!.user!.roles!.isNotEmpty - ? DashBoard( - roles: roles, - ) - : const NoModule(), - )); + ? DashBoard( + roles: roles, + ) + : const NoModule(), + ); } return Container(); }), diff --git a/lib/sevices/profile/profile_service.dart b/lib/sevices/profile/profile_service.dart index d6ffdfe..af76c43 100644 --- a/lib/sevices/profile/profile_service.dart +++ b/lib/sevices/profile/profile_service.dart @@ -8,6 +8,7 @@ import 'package:unit2/model/profile/basic_information/contact_information.dart'; import 'package:unit2/model/profile/basic_information/identification_information.dart'; import 'package:unit2/model/profile/educational_background.dart'; import 'package:unit2/model/profile/eligibility.dart'; +import 'package:unit2/model/profile/family_backround.dart'; import 'package:unit2/model/profile/learning_development.dart'; import 'package:unit2/model/profile/other_info.dart'; import 'package:unit2/model/profile/other_information/non_acedimic_recognition.dart'; @@ -37,6 +38,7 @@ class ProfileService { List identificationInformation = []; List contactInformation = []; List eligibilities = []; + List families = []; List citizenships = []; List learningsDevelopments = []; List educationalBackgrounds = []; @@ -89,6 +91,14 @@ class ProfileService { }); } + // get all family background + if(data['data']['family_background'] != null){ + data['data']['family_background'].forEach((var family){ + FamilyBackground familyBackground = FamilyBackground.fromJson(family); + families.add(familyBackground); + }); + } + //get all eligibilities if (data['data']['eligibilities'] != null) { data['data']['eligibilities']!.forEach((var cert) { @@ -188,6 +198,7 @@ class ProfileService { orgMemberships: orgMemberships, nonAcademicRecognition: nonAcademicRecognitions); ProfileInformation profileInformation = ProfileInformation( + families: families, otherInformation: otherInformation, workExperiences: workExperiences, basicInfo: basicInfo,