Learning and development refactor and create its own bloc
parent
61646bdcaa
commit
74c2c7ef59
|
@ -0,0 +1,28 @@
|
||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:unit2/sevices/profile/learningDevelopment_service.dart';
|
||||||
|
|
||||||
|
import '../../model/profile/learning_development.dart';
|
||||||
|
|
||||||
|
part 'learning_development_event.dart';
|
||||||
|
part 'learning_development_state.dart';
|
||||||
|
|
||||||
|
class LearningDevelopmentBloc
|
||||||
|
extends Bloc<LearningDevelopmentEvent, LearningDevelopmentState> {
|
||||||
|
LearningDevelopmentBloc() : super(LearningDevelopmentInitial()) {
|
||||||
|
List<LearningDevelopement> learningsAndDevelopments;
|
||||||
|
on<GetLearningDevelopments>((event, emit) async {
|
||||||
|
// try {
|
||||||
|
emit(LearningDevelopmentLoadingState());
|
||||||
|
List<LearningDevelopement> learnings = await LearningDevelopmentServices
|
||||||
|
.instance
|
||||||
|
.getLearningDevelopments(event.profileId, event.token);
|
||||||
|
learningsAndDevelopments = learnings;
|
||||||
|
emit(LearningDevelopmentLoadedState(
|
||||||
|
learningsAndDevelopment: learningsAndDevelopments));
|
||||||
|
// } catch (e) {
|
||||||
|
// emit(LeaningDevelopmentErrorState(message: e.toString()));
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
part of 'learning_development_bloc.dart';
|
||||||
|
|
||||||
|
abstract class LearningDevelopmentEvent extends Equatable {
|
||||||
|
const LearningDevelopmentEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetLearningDevelopments extends LearningDevelopmentEvent {
|
||||||
|
final int profileId;
|
||||||
|
final String token;
|
||||||
|
const GetLearningDevelopments({required this.profileId, required this.token});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [profileId, token];
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
part of 'learning_development_bloc.dart';
|
||||||
|
|
||||||
|
abstract class LearningDevelopmentState extends Equatable {
|
||||||
|
const LearningDevelopmentState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LearningDevelopmentInitial extends LearningDevelopmentState {}
|
||||||
|
|
||||||
|
class LearningDevelopmentLoadedState extends LearningDevelopmentState{
|
||||||
|
final List<LearningDevelopement> learningsAndDevelopment;
|
||||||
|
const LearningDevelopmentLoadedState({required this.learningsAndDevelopment});
|
||||||
|
@override
|
||||||
|
List<Object> get props => [learningsAndDevelopment];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LeaningDevelopmentErrorState extends LearningDevelopmentState{
|
||||||
|
final String message;
|
||||||
|
const LeaningDevelopmentErrorState({required this.message});
|
||||||
|
@override
|
||||||
|
List<Object> get props => [message];
|
||||||
|
}
|
||||||
|
|
||||||
|
class LearningDevelopmentLoadingState extends LearningDevelopmentState{
|
||||||
|
|
||||||
|
}
|
|
@ -23,7 +23,7 @@ class LearningDevelopement {
|
||||||
final dynamic attachments;
|
final dynamic attachments;
|
||||||
final EdBy? sponsoredBy;
|
final EdBy? sponsoredBy;
|
||||||
final ConductedTraining? conductedTraining;
|
final ConductedTraining? conductedTraining;
|
||||||
final int? totalHoursAttended;
|
final double? totalHoursAttended;
|
||||||
|
|
||||||
factory LearningDevelopement.fromJson(Map<String, dynamic> json) => LearningDevelopement(
|
factory LearningDevelopement.fromJson(Map<String, dynamic> json) => LearningDevelopement(
|
||||||
attachments: json["attachments"],
|
attachments: json["attachments"],
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
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:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:unit2/bloc/learningDevelopment/learning_development_bloc.dart';
|
||||||
|
import 'package:unit2/bloc/profile/profile_bloc.dart';
|
||||||
|
import 'package:unit2/bloc/user/user_bloc.dart';
|
||||||
import 'package:unit2/model/profile/learning_development.dart';
|
import 'package:unit2/model/profile/learning_development.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,62 +15,168 @@ import 'package:unit2/utils/global.dart';
|
||||||
import 'package:unit2/utils/text_container.dart';
|
import 'package:unit2/utils/text_container.dart';
|
||||||
import 'package:unit2/widgets/Leadings/add_leading.dart';
|
import 'package:unit2/widgets/Leadings/add_leading.dart';
|
||||||
import 'package:unit2/widgets/empty_data.dart';
|
import 'package:unit2/widgets/empty_data.dart';
|
||||||
|
import 'package:unit2/widgets/error_state.dart';
|
||||||
|
|
||||||
class LearningAndDevelopmentScreen extends StatelessWidget {
|
class LearningAndDevelopmentScreen extends StatelessWidget {
|
||||||
final List<LearningDevelopement> learningDevelopments;
|
|
||||||
const LearningAndDevelopmentScreen({super.key, required this.learningDevelopments});
|
|
||||||
|
|
||||||
|
|
||||||
|
const LearningAndDevelopmentScreen(
|
||||||
|
{super.key,});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
|
DateFormat dteFormat2 = DateFormat.yMMMMd('en_US');
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: const Text(learningAndDevelopmentScreenTitle),
|
appBar: AppBar(
|
||||||
|
title: const Text(learningAndDevelopmentScreenTitle),
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
backgroundColor: primary,
|
backgroundColor: primary,
|
||||||
actions: [AddLeading(onPressed: () {})],
|
actions: [AddLeading(onPressed: () {})],
|
||||||
),
|
),
|
||||||
body: learningDevelopments.isNotEmpty? ListView.builder(
|
body: ProgressHUD(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8,horizontal: 10),
|
padding: const EdgeInsets.all(24),
|
||||||
itemCount: learningDevelopments.length,
|
indicatorWidget: const SpinKitFadingCircle(
|
||||||
itemBuilder: (BuildContext context, int index){
|
color: Colors.white,
|
||||||
String training = learningDevelopments[index].conductedTraining!.title!.title!;
|
),
|
||||||
String provider = learningDevelopments[index].conductedTraining!.conductedBy!.name!;
|
backgroundColor: Colors.black87,
|
||||||
String start = dteFormat2.format(learningDevelopments[index].conductedTraining!.fromDate!);
|
child: BlocBuilder<UserBloc, UserState>(
|
||||||
String end = dteFormat2.format(learningDevelopments[index].conductedTraining!.toDate!);
|
builder: (context, state) {
|
||||||
String type = learningDevelopments[index].conductedTraining!.learningDevelopmentType!.title!;
|
if (state is UserLoggedIn) {
|
||||||
|
return BlocBuilder<ProfileBloc, ProfileState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
if (state is ProfileLoaded) {
|
||||||
|
return BlocConsumer<LearningDevelopmentBloc,
|
||||||
|
LearningDevelopmentState>(
|
||||||
|
listener: (context, state) {
|
||||||
|
if (state is LearningDevelopmentLoadingState) {
|
||||||
|
final progress = ProgressHUD.of(context);
|
||||||
|
progress!.showWithText("Please wait...");
|
||||||
|
}
|
||||||
|
if (state is LearningDevelopmentLoadedState ||
|
||||||
|
state is LeaningDevelopmentErrorState) {
|
||||||
|
final progress = ProgressHUD.of(context);
|
||||||
|
progress!.dismiss();
|
||||||
|
}
|
||||||
|
// TODO: implement listener
|
||||||
|
},
|
||||||
|
builder: (context, state) {
|
||||||
|
if (state is LearningDevelopmentLoadedState) {
|
||||||
|
if (state.learningsAndDevelopment.isNotEmpty) {
|
||||||
|
return ListView.builder(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 8, horizontal: 10),
|
||||||
|
itemCount:
|
||||||
|
state.learningsAndDevelopment.length,
|
||||||
|
itemBuilder:
|
||||||
|
(BuildContext context, int index) {
|
||||||
|
String training = state
|
||||||
|
.learningsAndDevelopment[index]
|
||||||
|
.conductedTraining!
|
||||||
|
.title!
|
||||||
|
.title!;
|
||||||
|
String provider = state
|
||||||
|
.learningsAndDevelopment[index]
|
||||||
|
.conductedTraining!
|
||||||
|
.conductedBy!
|
||||||
|
.name!;
|
||||||
|
String start = dteFormat2.format(state
|
||||||
|
.learningsAndDevelopment[index]
|
||||||
|
.conductedTraining!
|
||||||
|
.fromDate!);
|
||||||
|
String end = dteFormat2.format(state
|
||||||
|
.learningsAndDevelopment[index]
|
||||||
|
.conductedTraining!
|
||||||
|
.toDate!);
|
||||||
|
String type = state
|
||||||
|
.learningsAndDevelopment[index]
|
||||||
|
.conductedTraining!
|
||||||
|
.learningDevelopmentType!
|
||||||
|
.title!;
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
decoration: box1(),
|
decoration: box1(),
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 12, vertical: 8),
|
||||||
width: screenWidth,
|
width: screenWidth,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment:
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment
|
||||||
|
.start,
|
||||||
children: [
|
children: [
|
||||||
Text(training,style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500),),
|
Text(
|
||||||
|
training,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.titleMedium!
|
||||||
|
.copyWith(
|
||||||
|
fontWeight:
|
||||||
|
FontWeight
|
||||||
|
.w500),
|
||||||
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
const SizedBox(height: 5,),
|
const SizedBox(
|
||||||
Text(provider,style: Theme.of(context).textTheme.titleSmall,),
|
height: 5,
|
||||||
const SizedBox(height: 5,),
|
),
|
||||||
Text("$duration : $start TO $end",style: Theme.of(context).textTheme.labelMedium,),
|
Text(
|
||||||
const SizedBox(height: 5,),
|
provider,
|
||||||
Text("$type : $type",style: Theme.of(context).textTheme.labelMedium,),
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.titleSmall,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"$duration : $start to $end'",
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.labelMedium,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
|
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert)),
|
IconButton(
|
||||||
|
onPressed: () {},
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.more_vert)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8,),
|
const SizedBox(
|
||||||
|
height: 8,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}):const EmptyData(message: "You don't have any Learning and Development added. Please click + to add."),
|
});
|
||||||
|
} else {
|
||||||
|
const EmptyData(
|
||||||
|
message:
|
||||||
|
"You don't have any Learning and Development added. Please click + to add.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (state is LeaningDevelopmentErrorState) {
|
||||||
|
return (SomethingWentWrong(
|
||||||
|
message: state.message, onpressed: () {}));
|
||||||
|
}
|
||||||
|
return Container();
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
return Container();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return Container();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -10,6 +10,7 @@ import 'package:fluttericon/font_awesome5_icons.dart';
|
||||||
import 'package:fluttericon/modern_pictograms_icons.dart';
|
import 'package:fluttericon/modern_pictograms_icons.dart';
|
||||||
import 'package:unit2/bloc/education/education_bloc.dart';
|
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/profile/profile_bloc.dart';
|
import 'package:unit2/bloc/profile/profile_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';
|
||||||
|
@ -215,13 +216,13 @@ class _ProfileInfoState extends State<ProfileInfo> {
|
||||||
icon: Elusive.lightbulb,
|
icon: Elusive.lightbulb,
|
||||||
title: "Learning & Development",
|
title: "Learning & Development",
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Navigator.push(context, MaterialPageRoute(
|
Navigator.push(context, MaterialPageRoute(
|
||||||
// builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
// return LearningAndDevelopmentScreen(
|
return BlocProvider(
|
||||||
// learningDevelopments: state
|
create: (context) => LearningDevelopmentBloc()..add(GetLearningDevelopments(profileId: profileId!, token: token!)),
|
||||||
// .profileInformation
|
child: const LearningAndDevelopmentScreen(),
|
||||||
// .learningsAndDevelopment);
|
);
|
||||||
// }));
|
}));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:unit2/utils/request.dart';
|
||||||
|
|
||||||
|
import '../../model/profile/learning_development.dart';
|
||||||
|
import '../../utils/urls.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
class LearningDevelopmentServices {
|
||||||
|
static final LearningDevelopmentServices _instance =
|
||||||
|
LearningDevelopmentServices();
|
||||||
|
static LearningDevelopmentServices get instance => _instance;
|
||||||
|
|
||||||
|
Future<List<LearningDevelopement>> getLearningDevelopments(
|
||||||
|
int profileId, String token) async {
|
||||||
|
List<LearningDevelopement> learningsAndDevelopments = [];
|
||||||
|
String authToken = "Token $token";
|
||||||
|
String path = "${Url.instance.getLearningAndDevelopments()}$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 learnings) {
|
||||||
|
LearningDevelopement learningDevelopement =
|
||||||
|
LearningDevelopement.fromJson(learnings);
|
||||||
|
learningsAndDevelopments.add(learningDevelopement);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// } catch (e) {
|
||||||
|
// throw e.toString();
|
||||||
|
// }
|
||||||
|
return learningsAndDevelopments;
|
||||||
|
}
|
||||||
|
}
|
|
@ -5,8 +5,8 @@ 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';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,12 @@ String getEducationalBackgrounds(){
|
||||||
return "/api/jobnet_app/profile/pds/education/";
|
return "/api/jobnet_app/profile/pds/education/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//// learning and development paths
|
||||||
|
|
||||||
|
String getLearningAndDevelopments(){
|
||||||
|
return "api/jobnet_app/profile/pds/learning_development/";
|
||||||
|
}
|
||||||
|
|
||||||
// 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