Personal refences refactor and created its own bloc
parent
74c2c7ef59
commit
c83572cfb1
|
@ -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());
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -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];
|
||||||
|
}
|
|
@ -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{
|
||||||
|
|
||||||
|
}
|
|
@ -132,7 +132,7 @@ class LearningAndDevelopmentScreen extends StatelessWidget {
|
||||||
height: 5,
|
height: 5,
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
"$duration : $start to $end'",
|
"$duration: $start to $end",
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.labelMedium,
|
.labelMedium,
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/src/widgets/framework.dart';
|
import 'package:flutter/src/widgets/framework.dart';
|
||||||
import 'package:flutter/src/widgets/placeholder.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/model/profile/references.dart';
|
||||||
import 'package:unit2/theme-data.dart/box_shadow.dart';
|
import 'package:unit2/theme-data.dart/box_shadow.dart';
|
||||||
import 'package:unit2/theme-data.dart/colors.dart';
|
import 'package:unit2/theme-data.dart/colors.dart';
|
||||||
|
@ -9,78 +15,124 @@ import 'package:unit2/widgets/Leadings/add_leading.dart';
|
||||||
import 'package:unit2/widgets/empty_data.dart';
|
import 'package:unit2/widgets/empty_data.dart';
|
||||||
|
|
||||||
class ReferencesScreen extends StatelessWidget {
|
class ReferencesScreen extends StatelessWidget {
|
||||||
final List<PersonalReference> references;
|
const ReferencesScreen({super.key});
|
||||||
const ReferencesScreen({super.key, required this.references});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text(referencesScreenTitle),
|
title: const Text(referencesScreenTitle),
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
backgroundColor: primary,
|
backgroundColor: primary,
|
||||||
actions: [AddLeading(onPressed: (){})],
|
actions: [AddLeading(onPressed: () {})],
|
||||||
),
|
),
|
||||||
body: references.isNotEmpty? ListView.builder(
|
body: ProgressHUD(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
|
padding: const EdgeInsets.all(24),
|
||||||
itemCount: references.length,
|
backgroundColor: Colors.black87,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
indicatorWidget: const SpinKitFadingCircle(
|
||||||
String fullname =
|
color: Colors.white),
|
||||||
"${references[index].firstName} ${references[index].middleName} ${references[index].lastName}";
|
child: BlocBuilder<UserBloc, UserState>(
|
||||||
String addres =
|
builder: (context, state) {
|
||||||
"${references[index].address!.cityMunicipality!.description}, ${references[index].address!.cityMunicipality!.province!.description}, ${references[0].address!.cityMunicipality!.province!.region!.description}";
|
//userbloc
|
||||||
String mobile = references[index].contactNo.toString();
|
if (state is UserLoggedIn) {
|
||||||
return Column(
|
return BlocBuilder<ProfileBloc, ProfileState>(
|
||||||
children: [
|
builder: (context, state) {
|
||||||
Container(
|
//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:
|
padding:
|
||||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
|
||||||
decoration: box1(),
|
itemCount: state.references.length,
|
||||||
child: Row(
|
itemBuilder: (BuildContext context, int index) {
|
||||||
children: [
|
String fullname =
|
||||||
Expanded(
|
"${state.references[index].firstName} ${state.references[index].middleName} ${state.references[index].lastName}";
|
||||||
child: Column(
|
String addres =
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
"${state.references[index].address!.cityMunicipality!.description}, ${state.references[index].address!.cityMunicipality!.province!.description}, ${state.references[0].address!.cityMunicipality!.province!.region!.description}";
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
String mobile = state.references[index].contactNo.toString();
|
||||||
children: [
|
return Column(
|
||||||
Text(fullname,
|
children: [
|
||||||
style: Theme.of(context)
|
Container(
|
||||||
.textTheme
|
padding: const EdgeInsets.symmetric(
|
||||||
.titleMedium!
|
horizontal: 12, vertical: 8),
|
||||||
.copyWith(fontWeight: FontWeight.w500)),
|
decoration: box1(),
|
||||||
const Divider(),
|
child: Row(
|
||||||
const SizedBox(
|
children: [
|
||||||
height: 5,
|
Expanded(
|
||||||
),
|
child: Column(
|
||||||
Text(addres,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
style: Theme.of(context)
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
.textTheme
|
children: [
|
||||||
.titleSmall!
|
Text(fullname,
|
||||||
.copyWith(fontWeight: FontWeight.w500)),
|
style: Theme.of(context)
|
||||||
const SizedBox(
|
.textTheme
|
||||||
height: 8,
|
.titleMedium!
|
||||||
),
|
.copyWith(
|
||||||
Text("${mobileOrPhone.toUpperCase()} : $mobile",
|
fontWeight: FontWeight.w500)),
|
||||||
style:
|
const Divider(),
|
||||||
Theme.of(context).textTheme.labelMedium!),
|
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,
|
||||||
|
))
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(
|
||||||
IconButton(
|
height: 5,
|
||||||
onPressed: () {},
|
),
|
||||||
icon: const Icon(
|
],
|
||||||
Icons.more_vert,
|
);
|
||||||
color: Colors.grey,
|
});
|
||||||
))
|
}
|
||||||
],
|
}
|
||||||
),
|
return Container();
|
||||||
),
|
},
|
||||||
const SizedBox(
|
);
|
||||||
height: 5,
|
}
|
||||||
),
|
return Container();
|
||||||
],
|
},
|
||||||
);
|
);
|
||||||
}):const EmptyData(message: "You don't have any References added. Please click + to add."),
|
}
|
||||||
);
|
return Container();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import 'package:unit2/bloc/education/education_bloc.dart';
|
||||||
import 'package:unit2/bloc/eligibility/eligibility_bloc.dart';
|
import 'package:unit2/bloc/eligibility/eligibility_bloc.dart';
|
||||||
import 'package:unit2/bloc/learningDevelopment/learning_development_bloc.dart';
|
import 'package:unit2/bloc/learningDevelopment/learning_development_bloc.dart';
|
||||||
import 'package:unit2/bloc/profile/profile_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/bloc/workHistory/workHistory_bloc.dart';
|
||||||
import 'package:unit2/model/login_data/employee_info/employee_info.dart';
|
import 'package:unit2/model/login_data/employee_info/employee_info.dart';
|
||||||
import 'package:unit2/screens/profile/components/basic_information/address_screen.dart';
|
import 'package:unit2/screens/profile/components/basic_information/address_screen.dart';
|
||||||
|
@ -230,12 +231,13 @@ class _ProfileInfoState extends State<ProfileInfo> {
|
||||||
icon: Brandico.codepen,
|
icon: Brandico.codepen,
|
||||||
title: "Personal References",
|
title: "Personal References",
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Navigator.push(context, MaterialPageRoute(
|
Navigator.push(context, MaterialPageRoute(
|
||||||
// builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
// return ReferencesScreen(
|
return BlocProvider(
|
||||||
// references:
|
create: (context) => ReferencesBloc()..add(GetReferences(profileId: profileId!, token: token!)),
|
||||||
// state.profileInformation.references);
|
child: const ReferencesScreen(),
|
||||||
// }));
|
);
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
ExpandableGroup(
|
ExpandableGroup(
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,9 +5,9 @@ class Url {
|
||||||
String host() {
|
String host() {
|
||||||
// // return '192.168.10.221:3003';
|
// // return '192.168.10.221:3003';
|
||||||
// return 'agusandelnorte.gov.ph';
|
// return 'agusandelnorte.gov.ph';
|
||||||
return "192.168.10.219:3000";
|
// return "192.168.10.219:3000";
|
||||||
// return "devweb.agusandelnorte.gov.ph";
|
// return "devweb.agusandelnorte.gov.ph";
|
||||||
// return 'devapi.agusandelnorte.gov.ph:3004';
|
return 'devapi.agusandelnorte.gov.ph:3004';
|
||||||
}
|
}
|
||||||
|
|
||||||
String authentication() {
|
String authentication() {
|
||||||
|
@ -57,6 +57,11 @@ String getLearningAndDevelopments(){
|
||||||
return "api/jobnet_app/profile/pds/learning_development/";
|
return "api/jobnet_app/profile/pds/learning_development/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// references paths
|
||||||
|
String getRefences(){
|
||||||
|
return "/api/jobnet_app/profile/pds/personal_reference/";
|
||||||
|
}
|
||||||
|
|
||||||
// location utils path
|
// location utils path
|
||||||
String getCounties(){
|
String getCounties(){
|
||||||
return "/api/jobnet_app/countries/";
|
return "/api/jobnet_app/countries/";
|
||||||
|
|
Loading…
Reference in New Issue