Learning and development refactor and create its own bloc

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-03-02 16:22:31 +08:00
parent 61646bdcaa
commit 74c2c7ef59
8 changed files with 295 additions and 62 deletions

View File

@ -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()));
// }
});
}
}

View File

@ -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];
}

View File

@ -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{
}

View File

@ -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"],

View File

@ -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(
centerTitle: true, title: const Text(learningAndDevelopmentScreenTitle),
backgroundColor: primary, centerTitle: true,
actions: [AddLeading(onPressed: (){})], backgroundColor: primary,
), actions: [AddLeading(onPressed: () {})],
body: learningDevelopments.isNotEmpty? ListView.builder( ),
padding: const EdgeInsets.symmetric(vertical: 8,horizontal: 10), body: ProgressHUD(
itemCount: learningDevelopments.length, padding: const EdgeInsets.all(24),
itemBuilder: (BuildContext context, int index){ indicatorWidget: const SpinKitFadingCircle(
String training = learningDevelopments[index].conductedTraining!.title!.title!; color: Colors.white,
String provider = learningDevelopments[index].conductedTraining!.conductedBy!.name!; ),
String start = dteFormat2.format(learningDevelopments[index].conductedTraining!.fromDate!); backgroundColor: Colors.black87,
String end = dteFormat2.format(learningDevelopments[index].conductedTraining!.toDate!); child: BlocBuilder<UserBloc, UserState>(
String type = learningDevelopments[index].conductedTraining!.learningDevelopmentType!.title!; builder: (context, state) {
return Column( if (state is UserLoggedIn) {
children: [ return BlocBuilder<ProfileBloc, ProfileState>(
Container( builder: (context, state) {
decoration: box1(), if (state is ProfileLoaded) {
padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8), return BlocConsumer<LearningDevelopmentBloc,
width: screenWidth, LearningDevelopmentState>(
child: Row( listener: (context, state) {
children: [ if (state is LearningDevelopmentLoadingState) {
Expanded( final progress = ProgressHUD.of(context);
child: Column( progress!.showWithText("Please wait...");
mainAxisAlignment: MainAxisAlignment.start, }
crossAxisAlignment: CrossAxisAlignment.start, if (state is LearningDevelopmentLoadedState ||
children: [ state is LeaningDevelopmentErrorState) {
Text(training,style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500),), final progress = ProgressHUD.of(context);
const Divider(), progress!.dismiss();
const SizedBox(height: 5,), }
Text(provider,style: Theme.of(context).textTheme.titleSmall,), // TODO: implement listener
const SizedBox(height: 5,), },
Text("$duration : $start TO $end",style: Theme.of(context).textTheme.labelMedium,), builder: (context, state) {
const SizedBox(height: 5,), if (state is LearningDevelopmentLoadedState) {
Text("$type : $type",style: Theme.of(context).textTheme.labelMedium,), if (state.learningsAndDevelopment.isNotEmpty) {
]), return ListView.builder(
), padding: const EdgeInsets.symmetric(
IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert)), vertical: 8, horizontal: 10),
], itemCount:
), state.learningsAndDevelopment.length,
), itemBuilder:
const SizedBox(height: 8,), (BuildContext context, int index) {
], String training = state
); .learningsAndDevelopment[index]
}):const EmptyData(message: "You don't have any Learning and Development added. Please click + to add."), .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(
children: [
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: [
Text(
training,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight
.w500),
),
const Divider(),
const SizedBox(
height: 5,
),
Text(
provider,
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)),
],
),
),
const SizedBox(
height: 8,
),
],
);
});
} 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();
},
),
));
} }
} }

View File

@ -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(),

View File

@ -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;
}
}

View File

@ -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/";