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,9 +15,7 @@ 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(
|
||||||
|
@ -21,20 +25,51 @@ class ReferencesScreen extends StatelessWidget {
|
||||||
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,
|
||||||
|
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(vertical: 8, horizontal: 10),
|
||||||
|
itemCount: state.references.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
String fullname =
|
String fullname =
|
||||||
"${references[index].firstName} ${references[index].middleName} ${references[index].lastName}";
|
"${state.references[index].firstName} ${state.references[index].middleName} ${state.references[index].lastName}";
|
||||||
String addres =
|
String addres =
|
||||||
"${references[index].address!.cityMunicipality!.description}, ${references[index].address!.cityMunicipality!.province!.description}, ${references[0].address!.cityMunicipality!.province!.region!.description}";
|
"${state.references[index].address!.cityMunicipality!.description}, ${state.references[index].address!.cityMunicipality!.province!.description}, ${state.references[0].address!.cityMunicipality!.province!.region!.description}";
|
||||||
String mobile = references[index].contactNo.toString();
|
String mobile = state.references[index].contactNo.toString();
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
padding:
|
padding: const EdgeInsets.symmetric(
|
||||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
horizontal: 12, vertical: 8),
|
||||||
decoration: box1(),
|
decoration: box1(),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
@ -47,7 +82,8 @@ class ReferencesScreen extends StatelessWidget {
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.titleMedium!
|
.titleMedium!
|
||||||
.copyWith(fontWeight: FontWeight.w500)),
|
.copyWith(
|
||||||
|
fontWeight: FontWeight.w500)),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 5,
|
height: 5,
|
||||||
|
@ -56,13 +92,15 @@ class ReferencesScreen extends StatelessWidget {
|
||||||
style: Theme.of(context)
|
style: Theme.of(context)
|
||||||
.textTheme
|
.textTheme
|
||||||
.titleSmall!
|
.titleSmall!
|
||||||
.copyWith(fontWeight: FontWeight.w500)),
|
.copyWith(
|
||||||
|
fontWeight: FontWeight.w500)),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 8,
|
height: 8,
|
||||||
),
|
),
|
||||||
Text("${mobileOrPhone.toUpperCase()} : $mobile",
|
Text("${mobileOrPhone.toUpperCase()} : $mobile",
|
||||||
style:
|
style: Theme.of(context)
|
||||||
Theme.of(context).textTheme.labelMedium!),
|
.textTheme
|
||||||
|
.labelMedium!),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -80,7 +118,21 @@ class ReferencesScreen extends StatelessWidget {
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}):const EmptyData(message: "You don't have any References added. Please click + to add."),
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Container();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return Container();
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
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