family background refactor and created its own bloc

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-03-06 16:29:55 +08:00
parent 2a57e7453b
commit 4251002cbf
11 changed files with 520 additions and 279 deletions

View File

@ -0,0 +1,24 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/sevices/profile/family_services.dart';
import '../../model/profile/family_backround.dart';
part 'family_event.dart';
part 'family_state.dart';
class FamilyBloc extends Bloc<FamilyEvent, FamilyState> {
FamilyBloc() : super(FamilyInitial()) {
List<FamilyBackground> families = [];
on<GetFamilies>((event, emit) async{
emit(FamilyLoadingState());
try{
List<FamilyBackground> family = await FamilyService.instance.getFamilies(event.profileId, event.token);
families = family;
emit(FamilyLoaded(families: families));
}catch(e){
emit(FamilyErrorState(message: e.toString()));
}
});
}
}

View File

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

View File

@ -0,0 +1,28 @@
part of 'family_bloc.dart';
abstract class FamilyState extends Equatable {
const FamilyState();
@override
List<Object> get props => [];
}
class FamilyInitial extends FamilyState {}
class FamilyLoaded extends FamilyState{
final List<FamilyBackground> families;
const FamilyLoaded({required this.families});
@override
List<Object> get props => [families];
}
class FamilyErrorState extends FamilyState{
final String message;
const FamilyErrorState({required this.message});
@override
List<Object> get props => [message];
}
class FamilyLoadingState extends FamilyState{
}

View File

@ -1,10 +0,0 @@
import 'package:unit2/model/profile/other_information/non_acedimic_recognition.dart';
import 'package:unit2/model/profile/other_information/organization_memberships.dart';
import 'package:unit2/model/profile/other_information/skills_and_hobbies.dart';
class OtherInformation{
List<SkillsHobbies> skillsAndHobbies;
List<OrganizationMembership>orgMemberships;
List<NonAcademicRecognition> nonAcademicRecognition;
OtherInformation({required this.skillsAndHobbies, required this.orgMemberships, required this.nonAcademicRecognition});
}

View File

@ -4,7 +4,6 @@ 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';
import 'package:unit2/model/profile/voluntary_works.dart';
import 'package:unit2/model/profile/work_history.dart';

View File

@ -20,7 +20,7 @@ class ContactInformationScreen extends StatelessWidget {
backgroundColor: primary,
actions: [AddLeading(onPressed: (){})],
),
body: contacts.isEmpty? ListView.builder(
body: contacts.isNotEmpty? ListView.builder(
padding: const EdgeInsets.symmetric(vertical: 8,horizontal: 10),
itemCount: contacts.length,
itemBuilder: (BuildContext context, int index) {

View File

@ -1,4 +1,10 @@
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:unit2/bloc/family/family_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/model/profile/family_backround.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart';
@ -6,8 +12,9 @@ import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/text_container.dart';
class FamilyBackgroundScreen extends StatefulWidget {
final List<FamilyBackground> familyBackground;
const FamilyBackgroundScreen({super.key, required this.familyBackground});
const FamilyBackgroundScreen({
super.key,
});
@override
State<FamilyBackgroundScreen> createState() => _FamilyBackgroundScreenState();
@ -21,279 +28,402 @@ class _FamilyBackgroundScreenState extends State<FamilyBackgroundScreen> {
List<FamilyBackground> 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);
// get all children
var childs = widget.familyBackground
.where((element) => element.relationship!.id == 4);
if (childs.isNotEmpty) {
for (var element in childs) {
children.add(element);
}
}
//get all related persons
var relateds = widget.familyBackground
.where((element) => element.relationship!.id! > 4);
if (relateds.isNotEmpty) {
for (var element in relateds) {
otherRelated.add(element);
}
}
return Scaffold(
appBar: AppBar(
title: const Text(familyBackgroundScreenTitle),
centerTitle: true,
backgroundColor: primary,
),
body: ListView(children: [
//Father----------------------------------------------
Container(
decoration: box1(),
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(fatherText),
const SizedBox(height: 5,),
Text(
" ${father!.relatedPerson!.firstName} ${father!.relatedPerson!.middleName} ${father!.relatedPerson!.lastName} ${father!.relatedPerson!.nameExtension ?? ''},",style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500),),
Text(" $fullname",style: Theme.of(context).textTheme.bodySmall,),
Row(
children: [
Checkbox(value: false, onChanged: (value) {
setState(() {
value = !value!;
});
}),
const Text(incaseOfEmergency)
],
)
]),
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
],
),
),
const SizedBox(
height: 5,
),
body: ProgressHUD(
padding: const EdgeInsets.all(24),
backgroundColor: Colors.black87,
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
child: BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocConsumer<FamilyBloc, FamilyState>(
listener: (context, state) {
if (state is FamilyLoadingState) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if (state is FamilyLoaded || state is FamilyErrorState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
},
builder: (context, state) {
if (state is FamilyLoaded) {
father = state.families.firstWhere(
(element) => element.relationship!.id == 1);
mother = state.families.firstWhere(
(element) => element.relationship!.id == 2);
spouse = state.families.firstWhere(
(element) => element.relationship!.id == 3);
//Mother-----------------------------------------------------
Container(
decoration: box1(),
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(motherText),
const SizedBox(height: 5,),
Text(
" ${mother!.relatedPerson!.firstName} ${mother!.relatedPerson!.middleName} ${mother!.relatedPerson!.lastName} ${mother!.relatedPerson!.nameExtension ?? ''}",style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500),),
Text(" $fullname",style: Theme.of(context).textTheme.bodySmall),
Row(
children: [
Checkbox(value: false, onChanged: (value) {}),
const Text(incaseOfEmergency)
],
)
]),
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
],
),
),
const SizedBox(
height: 5,
),
//Spouse ---------------------------------------------------------
spouse != null
? Container(
decoration: box1(),
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(spouseText),
const SizedBox(height: 5,),
Text(
" ${spouse!.relatedPerson!.firstName} ${spouse!.relatedPerson!.middleName} ${spouse!.relatedPerson!.lastName} ${spouse!.relatedPerson!.nameExtension ?? ''}",style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500)),
Text(" $fullname",style: Theme.of(context).textTheme.bodySmall),
Row(
// get all children
var childs = state.families
.where((element) => element.relationship!.id == 4);
if (childs.isNotEmpty) {
for (var element in childs) {
children.add(element);
}
}
//get all related persons
var relateds = state.families
.where((element) => element.relationship!.id! > 4);
if (relateds.isNotEmpty) {
for (var element in relateds) {
otherRelated.add(element);
}
}
return ListView(children: [
//Father----------------------------------------------
Container(
decoration: box1(),
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
width: screenWidth,
child: Row(
children: [
Checkbox(value: false, onChanged: (value) {}),
const Text(incaseOfEmergency)
Expanded(
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
const Text(fatherText),
const SizedBox(
height: 5,
),
Text(
" ${father!.relatedPerson!.firstName} ${father!.relatedPerson!.middleName} ${father!.relatedPerson!.lastName} ${father!.relatedPerson!.nameExtension ?? ''},",
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight: FontWeight.w500),
),
Text(
" ",
style: Theme.of(context)
.textTheme
.bodySmall,
),
Row(
children: [
Checkbox(
value: false,
onChanged: (value) {
setState(() {
value = !value!;
});
}),
const Text(incaseOfEmergency)
],
)
]),
),
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(
height: 5,
),
),
),
const SizedBox(
height: 5,
),
// Childrens ----------------------------------
children.isNotEmpty
? Container(
decoration: box1(),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: children
.map(
(child){
int index = children.indexOf(child);
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
width: screenWidth,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
index == 0? const Text(childrenText):const SizedBox(),
const SizedBox(
height: 5,
),
Row(
children: [
Expanded(
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
" ${child.relatedPerson!.firstName} ${child.relatedPerson!.middleName} ${child.relatedPerson!.lastName} ${child.relatedPerson!.nameExtension ?? ''}",style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500)),
Text(" $fullname",style: Theme.of(context).textTheme.bodySmall),
Row(
children: [
Checkbox(
value: false,
onChanged: (value) {}),
const Text(incaseOfEmergency)
],
)
]),
),
IconButton(
onPressed: () {},
icon: const Icon(Icons.more_vert,color: Colors.grey,))
],
),
],
//Mother-----------------------------------------------------
Container(
decoration: box1(),
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(motherText),
const SizedBox(
height: 5,
),
Text(
" ${mother!.relatedPerson!.firstName} ${mother!.relatedPerson!.middleName} ${mother!.relatedPerson!.lastName} ${mother!.relatedPerson!.nameExtension ?? ''}",
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight: FontWeight.w500),
),
Text(" ",
style: Theme.of(context)
.textTheme
.bodySmall),
Row(
children: [
Checkbox(
value: false,
onChanged: (value) {}),
const Text(incaseOfEmergency)
],
)
]),
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
],
),
),
);
}
)
.toList()),
)
: const SizedBox(),
const SizedBox(
height: 5,
const SizedBox(
height: 5,
),
//Spouse ---------------------------------------------------------
spouse != null
? Container(
decoration: box1(),
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(spouseText),
const SizedBox(
height: 5,
),
Text(
" ${spouse!.relatedPerson!.firstName} ${spouse!.relatedPerson!.middleName} ${spouse!.relatedPerson!.lastName} ${spouse!.relatedPerson!.nameExtension ?? ''}",
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight.w500)),
Text(" ",
style: Theme.of(context)
.textTheme
.bodySmall),
Row(
children: [
Checkbox(
value: false,
onChanged: (value) {}),
const Text(incaseOfEmergency)
],
)
]),
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
],
),
)
: const SizedBox(),
const SizedBox(
height: 5,
),
// Childrens ----------------------------------
children.isNotEmpty
? Container(
decoration: box1(),
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: children.map((child) {
int index = children.indexOf(child);
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
width: screenWidth,
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
index == 0
? const Text(childrenText)
: const SizedBox(),
const SizedBox(
height: 5,
),
Row(
children: [
Expanded(
child: Column(
mainAxisAlignment:
MainAxisAlignment
.start,
crossAxisAlignment:
CrossAxisAlignment
.start,
children: [
Text(
" ${child.relatedPerson!.firstName} ${child.relatedPerson!.middleName} ${child.relatedPerson!.lastName} ${child.relatedPerson!.nameExtension ?? ''}",
style: Theme.of(
context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight
.w500)),
Text(" ",
style: Theme.of(
context)
.textTheme
.bodySmall),
Row(
children: [
Checkbox(
value: false,
onChanged:
(value) {}),
const Text(
incaseOfEmergency)
],
)
]),
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
],
),
],
),
);
}).toList()),
)
: const SizedBox(),
const SizedBox(
height: 5,
),
//Other related person
otherRelated.isNotEmpty
? Container(
decoration: box1(),
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: otherRelated.map((relative) {
int index2 =
otherRelated.indexOf(relative);
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
width: screenWidth,
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
index2 == 0
? const Text(otherRelatedText)
: const SizedBox(),
const SizedBox(
height: 5,
),
Row(
children: [
Expanded(
child: Column(
mainAxisAlignment:
MainAxisAlignment
.start,
crossAxisAlignment:
CrossAxisAlignment
.start,
children: [
Text(
" ${relative.relatedPerson!.firstName} ${relative.relatedPerson!.middleName} ${relative.relatedPerson!.lastName} ${relative.relatedPerson!.nameExtension ?? ''}",
style: Theme.of(
context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight
.w500)),
Text(" ",
style: Theme.of(
context)
.textTheme
.bodySmall!),
Row(
children: [
Checkbox(
value: false,
onChanged:
(value) {}),
const Text(
incaseOfEmergency)
],
)
]),
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
],
),
],
),
);
}).toList()),
)
: const SizedBox(),
]);
}
return Container();
},
);
}
return Container();
},
);
},
),
//Other related person
otherRelated.isNotEmpty
? Container(
decoration: box1(),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: otherRelated
.map(
(relative){
int index2 = otherRelated.indexOf(relative);
return Container(
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
width: screenWidth,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
index2 == 0? const Text(otherRelatedText):const SizedBox(),
const SizedBox(
height: 5,
),
Row(
children: [
Expanded(
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
" ${relative.relatedPerson!.firstName} ${relative.relatedPerson!.middleName} ${relative.relatedPerson!.lastName} ${relative.relatedPerson!.nameExtension ?? ''}",style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500)),
Text(" $fullname",style: Theme.of(context).textTheme.bodySmall!),
Row(
children: [
Checkbox(
value: false,
onChanged: (value) {}),
const Text(incaseOfEmergency)
],
)
]),
),
IconButton(
onPressed: () {},
icon: const Icon(Icons.more_vert,color: Colors.grey,))
],
),
],
),
);
}
)
.toList()),
)
: const SizedBox(),
]),
),
);
}
}

View File

@ -10,6 +10,7 @@ import 'package:fluttericon/font_awesome5_icons.dart';
import 'package:fluttericon/modern_pictograms_icons.dart';
import 'package:unit2/bloc/education/education_bloc.dart';
import 'package:unit2/bloc/eligibility/eligibility_bloc.dart';
import 'package:unit2/bloc/family/family_bloc.dart';
import 'package:unit2/bloc/hobbies/hoobies_bloc.dart';
import 'package:unit2/bloc/learningDevelopment/learning_development_bloc.dart';
import 'package:unit2/bloc/non_academic_recognition.dart/non_academic_recognition_bloc.dart';
@ -156,7 +157,17 @@ class _ProfileInfoState extends State<ProfileInfo> {
MainMenu(
icon: Elusive.group,
title: "Family",
onTap: () {},
onTap: () {
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) {
return BlocProvider(
create: (context) => FamilyBloc()
..add(GetFamilies(
profileId: profileId!, token: token!)),
child: const FamilyBackgroundScreen(),
);
}));
},
),
const Divider(),
MainMenu(

View File

@ -0,0 +1,38 @@
import 'dart:convert';
import 'package:unit2/utils/request.dart';
import '../../model/profile/family_backround.dart';
import '../../utils/urls.dart';
import 'package:http/http.dart' as http;
class FamilyService{
static final FamilyService _instance = FamilyService();
static FamilyService get instance => _instance;
Future< List<FamilyBackground>> getFamilies(int profileId, String token)async{
List<FamilyBackground> families = [];
String authToken = "Token $token";
String path = "${Url.instance.getFamilies()}$profileId/";
Map<String, String> headers = {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': authToken
};
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 family){
FamilyBackground familyBackground = FamilyBackground.fromJson(family);
families.add(familyBackground);
});
}
}
}catch(e){
throw e.toString();
}
return families;
}
}

View File

@ -10,7 +10,6 @@ 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';
import 'package:unit2/model/profile/profileInfomation.dart';
import 'package:unit2/model/profile/references.dart';

View File

@ -6,8 +6,8 @@ class Url {
// // return '192.168.10.221:3003';
// return 'agusandelnorte.gov.ph';
// return "192.168.10.219:3000";
// return "devweb.agusandelnorte.gov.ph";
return 'devapi.agusandelnorte.gov.ph:3004';
return "devweb.agusandelnorte.gov.ph";
// return 'devapi.agusandelnorte.gov.ph:3004';
}
String authentication() {
@ -82,6 +82,11 @@ String getNonAcademicRecognition(){
return "/api/jobnet_app/profile/pds/other/non_acad_recognition/";
}
////family paths
String getFamilies(){
return "/api/jobnet_app/profile/pds/family/";
}
// location utils path
String getCounties(){
return "/api/jobnet_app/countries/";