Personal refences refactor and created its own bloc

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-03-06 08:57:39 +08:00
parent 74c2c7ef59
commit c83572cfb1
8 changed files with 246 additions and 77 deletions

View File

@ -0,0 +1,25 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:unit2/sevices/profile/references_services.dart';
import '../../model/profile/references.dart';
part 'references_event.dart';
part 'references_state.dart';
class ReferencesBloc extends Bloc<ReferencesEvent, ReferencesState> {
List<PersonalReference> references = [];
ReferencesBloc() : super(ReferencesInitial()) {
on<GetReferences>((event, emit) async{
emit(ReferencesLoadingState());
try{
List<PersonalReference> refs = await ReferencesServices.instace.getRefences(event.profileId, event.token);
references = refs;
emit(ReferencesLoadedState(references: references));
}catch(e){
ReferencesErrorState(message: e.toString());
}
});
}
}

View File

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

View File

@ -0,0 +1,29 @@
part of 'references_bloc.dart';
abstract class ReferencesState extends Equatable {
const ReferencesState();
@override
List<Object> get props => [];
}
class ReferencesInitial extends ReferencesState {}
class ReferencesLoadedState extends ReferencesState{
final List<PersonalReference> references;
const ReferencesLoadedState({required this.references});
@override
List<Object> get props => [references];
}
class ReferencesErrorState extends ReferencesState{
final String message;
const ReferencesErrorState({required this.message});
@override
List<Object> get props => [message];
}
class ReferencesLoadingState extends ReferencesState{
}

View File

@ -132,7 +132,7 @@ class LearningAndDevelopmentScreen extends StatelessWidget {
height: 5,
),
Text(
"$duration : $start to $end'",
"$duration: $start to $end",
style: Theme.of(context)
.textTheme
.labelMedium,

View File

@ -1,6 +1,12 @@
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_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/references/references_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/model/profile/references.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart';
@ -9,78 +15,124 @@ import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart';
class ReferencesScreen extends StatelessWidget {
final List<PersonalReference> references;
const ReferencesScreen({super.key, required this.references});
const ReferencesScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(referencesScreenTitle),
centerTitle: true,
backgroundColor: primary,
actions: [AddLeading(onPressed: (){})],
),
body: references.isNotEmpty? ListView.builder(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
itemCount: references.length,
itemBuilder: (BuildContext context, int index) {
String fullname =
"${references[index].firstName} ${references[index].middleName} ${references[index].lastName}";
String addres =
"${references[index].address!.cityMunicipality!.description}, ${references[index].address!.cityMunicipality!.province!.description}, ${references[0].address!.cityMunicipality!.province!.region!.description}";
String mobile = references[index].contactNo.toString();
return Column(
children: [
Container(
appBar: AppBar(
title: const Text(referencesScreenTitle),
centerTitle: true,
backgroundColor: primary,
actions: [AddLeading(onPressed: () {})],
),
body: ProgressHUD(
padding: const EdgeInsets.all(24),
backgroundColor: Colors.black87,
indicatorWidget: const SpinKitFadingCircle(
color: Colors.white),
child: BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
//userbloc
if (state is UserLoggedIn) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
//profilebloc
if (state is ProfileLoaded) {
return BlocConsumer<ReferencesBloc, ReferencesState>(
//listener
listener: (context, state) {
if(state is ReferencesLoadingState){
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if(state is ReferencesLoadedState || state is ReferencesErrorState){
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
},
//builder
builder: (context, state) {
//references bloc
if (state is ReferencesLoadedState) {
if (state.references.isNotEmpty) {
return ListView.builder(
padding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: box1(),
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(fullname,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(fontWeight: FontWeight.w500)),
const Divider(),
const SizedBox(
height: 5,
),
Text(addres,
style: Theme.of(context)
.textTheme
.titleSmall!
.copyWith(fontWeight: FontWeight.w500)),
const SizedBox(
height: 8,
),
Text("${mobileOrPhone.toUpperCase()} : $mobile",
style:
Theme.of(context).textTheme.labelMedium!),
],
const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
itemCount: state.references.length,
itemBuilder: (BuildContext context, int index) {
String fullname =
"${state.references[index].firstName} ${state.references[index].middleName} ${state.references[index].lastName}";
String addres =
"${state.references[index].address!.cityMunicipality!.description}, ${state.references[index].address!.cityMunicipality!.province!.description}, ${state.references[0].address!.cityMunicipality!.province!.region!.description}";
String mobile = state.references[index].contactNo.toString();
return Column(
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
decoration: box1(),
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(fullname,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight: FontWeight.w500)),
const Divider(),
const SizedBox(
height: 5,
),
Text(addres,
style: Theme.of(context)
.textTheme
.titleSmall!
.copyWith(
fontWeight: FontWeight.w500)),
const SizedBox(
height: 8,
),
Text("${mobileOrPhone.toUpperCase()} : $mobile",
style: Theme.of(context)
.textTheme
.labelMedium!),
],
),
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
],
),
),
),
IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
],
),
),
const SizedBox(
height: 5,
),
],
);
}):const EmptyData(message: "You don't have any References added. Please click + to add."),
);
const SizedBox(
height: 5,
),
],
);
});
}
}
return Container();
},
);
}
return Container();
},
);
}
return Container();
},
),
));
}
}

View File

@ -12,6 +12,7 @@ import 'package:unit2/bloc/education/education_bloc.dart';
import 'package:unit2/bloc/eligibility/eligibility_bloc.dart';
import 'package:unit2/bloc/learningDevelopment/learning_development_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/references/references_bloc.dart';
import 'package:unit2/bloc/workHistory/workHistory_bloc.dart';
import 'package:unit2/model/login_data/employee_info/employee_info.dart';
import 'package:unit2/screens/profile/components/basic_information/address_screen.dart';
@ -230,12 +231,13 @@ class _ProfileInfoState extends State<ProfileInfo> {
icon: Brandico.codepen,
title: "Personal References",
onTap: () {
// Navigator.push(context, MaterialPageRoute(
// builder: (BuildContext context) {
// return ReferencesScreen(
// references:
// state.profileInformation.references);
// }));
Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) {
return BlocProvider(
create: (context) => ReferencesBloc()..add(GetReferences(profileId: profileId!, token: token!)),
child: const ReferencesScreen(),
);
}));
},
),
ExpandableGroup(

View File

@ -0,0 +1,40 @@
import 'dart:convert';
import 'package:unit2/utils/request.dart';
import '../../model/profile/references.dart';
import '../../utils/urls.dart';
import 'package:http/http.dart' as http;
class ReferencesServices{
static final ReferencesServices _instance = ReferencesServices();
static ReferencesServices get instace => _instance;
Future<List<PersonalReference>> getRefences(int profileId, String token)async{
List<PersonalReference> references = [];
String authToken = "Token $token";
String path = "${Url.instance.getRefences()}$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 ref){
PersonalReference reference = PersonalReference.fromJson(ref);
references.add(reference);
});
}
}
}catch(e){
throw e.toString();
}
return references;
}
}

View File

@ -5,9 +5,9 @@ class Url {
String host() {
// // return '192.168.10.221:3003';
// return 'agusandelnorte.gov.ph';
return "192.168.10.219:3000";
// 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() {
@ -57,6 +57,11 @@ String getLearningAndDevelopments(){
return "api/jobnet_app/profile/pds/learning_development/";
}
//// references paths
String getRefences(){
return "/api/jobnet_app/profile/pds/personal_reference/";
}
// location utils path
String getCounties(){
return "/api/jobnet_app/countries/";