diff --git a/lib/bloc/learningDevelopment/learning_development_bloc.dart b/lib/bloc/learningDevelopment/learning_development_bloc.dart new file mode 100644 index 0000000..4457b4d --- /dev/null +++ b/lib/bloc/learningDevelopment/learning_development_bloc.dart @@ -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 { + LearningDevelopmentBloc() : super(LearningDevelopmentInitial()) { + List learningsAndDevelopments; + on((event, emit) async { + // try { + emit(LearningDevelopmentLoadingState()); + List learnings = await LearningDevelopmentServices + .instance + .getLearningDevelopments(event.profileId, event.token); + learningsAndDevelopments = learnings; + emit(LearningDevelopmentLoadedState( + learningsAndDevelopment: learningsAndDevelopments)); + // } catch (e) { + // emit(LeaningDevelopmentErrorState(message: e.toString())); + // } + }); + } +} diff --git a/lib/bloc/learningDevelopment/learning_development_event.dart b/lib/bloc/learningDevelopment/learning_development_event.dart new file mode 100644 index 0000000..9aedc7d --- /dev/null +++ b/lib/bloc/learningDevelopment/learning_development_event.dart @@ -0,0 +1,17 @@ +part of 'learning_development_bloc.dart'; + +abstract class LearningDevelopmentEvent extends Equatable { + const LearningDevelopmentEvent(); + + @override + List get props => []; +} + +class GetLearningDevelopments extends LearningDevelopmentEvent { + final int profileId; + final String token; + const GetLearningDevelopments({required this.profileId, required this.token}); + + @override + List get props => [profileId, token]; +} diff --git a/lib/bloc/learningDevelopment/learning_development_state.dart b/lib/bloc/learningDevelopment/learning_development_state.dart new file mode 100644 index 0000000..c4b2337 --- /dev/null +++ b/lib/bloc/learningDevelopment/learning_development_state.dart @@ -0,0 +1,28 @@ +part of 'learning_development_bloc.dart'; + +abstract class LearningDevelopmentState extends Equatable { + const LearningDevelopmentState(); + + @override + List get props => []; +} + +class LearningDevelopmentInitial extends LearningDevelopmentState {} + +class LearningDevelopmentLoadedState extends LearningDevelopmentState{ + final List learningsAndDevelopment; + const LearningDevelopmentLoadedState({required this.learningsAndDevelopment}); + @override + List get props => [learningsAndDevelopment]; +} + +class LeaningDevelopmentErrorState extends LearningDevelopmentState{ + final String message; + const LeaningDevelopmentErrorState({required this.message}); + @override + List get props => [message]; +} + +class LearningDevelopmentLoadingState extends LearningDevelopmentState{ + +} diff --git a/lib/model/profile/learning_development.dart b/lib/model/profile/learning_development.dart index 11bb21b..ce7a045 100644 --- a/lib/model/profile/learning_development.dart +++ b/lib/model/profile/learning_development.dart @@ -23,7 +23,7 @@ class LearningDevelopement { final dynamic attachments; final EdBy? sponsoredBy; final ConductedTraining? conductedTraining; - final int? totalHoursAttended; + final double? totalHoursAttended; factory LearningDevelopement.fromJson(Map json) => LearningDevelopement( attachments: json["attachments"], diff --git a/lib/screens/profile/components/learning_and_development_screen.dart b/lib/screens/profile/components/learning_and_development_screen.dart index e7c9a4a..d77859c 100644 --- a/lib/screens/profile/components/learning_and_development_screen.dart +++ b/lib/screens/profile/components/learning_and_development_screen.dart @@ -1,7 +1,13 @@ 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: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/theme-data.dart/box_shadow.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/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/empty_data.dart'; +import 'package:unit2/widgets/error_state.dart'; class LearningAndDevelopmentScreen extends StatelessWidget { - final List learningDevelopments; - const LearningAndDevelopmentScreen({super.key, required this.learningDevelopments}); - + const LearningAndDevelopmentScreen( + {super.key,}); @override Widget build(BuildContext context) { - DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); - return Scaffold( - appBar: AppBar(title: const Text(learningAndDevelopmentScreenTitle), - centerTitle: true, - backgroundColor: primary, - actions: [AddLeading(onPressed: (){})], - ), - body: learningDevelopments.isNotEmpty? ListView.builder( - padding: const EdgeInsets.symmetric(vertical: 8,horizontal: 10), - itemCount: learningDevelopments.length, - itemBuilder: (BuildContext context, int index){ - String training = learningDevelopments[index].conductedTraining!.title!.title!; - String provider = learningDevelopments[index].conductedTraining!.conductedBy!.name!; - String start = dteFormat2.format(learningDevelopments[index].conductedTraining!.fromDate!); - String end = dteFormat2.format(learningDevelopments[index].conductedTraining!.toDate!); - String type = learningDevelopments[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,), - Text("$type : $type",style: Theme.of(context).textTheme.labelMedium,), - ]), - ), - IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert)), - ], - ), - ), - const SizedBox(height: 8,), - ], - ); - }):const EmptyData(message: "You don't have any Learning and Development added. Please click + to add."), - ); + DateFormat dteFormat2 = DateFormat.yMMMMd('en_US'); + return Scaffold( + appBar: AppBar( + title: const Text(learningAndDevelopmentScreenTitle), + centerTitle: true, + backgroundColor: primary, + actions: [AddLeading(onPressed: () {})], + ), + body: ProgressHUD( + padding: const EdgeInsets.all(24), + indicatorWidget: const SpinKitFadingCircle( + color: Colors.white, + ), + backgroundColor: Colors.black87, + child: BlocBuilder( + builder: (context, state) { + if (state is UserLoggedIn) { + return BlocBuilder( + builder: (context, state) { + if (state is ProfileLoaded) { + return BlocConsumer( + 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( + 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(); + }, + ), + )); } -} \ No newline at end of file +} diff --git a/lib/screens/profile/profile.dart b/lib/screens/profile/profile.dart index e6ed37b..7441db5 100644 --- a/lib/screens/profile/profile.dart +++ b/lib/screens/profile/profile.dart @@ -10,6 +10,7 @@ import 'package:fluttericon/font_awesome5_icons.dart'; import 'package:fluttericon/modern_pictograms_icons.dart'; 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/workHistory/workHistory_bloc.dart'; import 'package:unit2/model/login_data/employee_info/employee_info.dart'; @@ -215,13 +216,13 @@ class _ProfileInfoState extends State { icon: Elusive.lightbulb, title: "Learning & Development", onTap: () { - // Navigator.push(context, MaterialPageRoute( - // builder: (BuildContext context) { - // return LearningAndDevelopmentScreen( - // learningDevelopments: state - // .profileInformation - // .learningsAndDevelopment); - // })); + Navigator.push(context, MaterialPageRoute( + builder: (BuildContext context) { + return BlocProvider( + create: (context) => LearningDevelopmentBloc()..add(GetLearningDevelopments(profileId: profileId!, token: token!)), + child: const LearningAndDevelopmentScreen(), + ); + })); }, ), const Divider(), diff --git a/lib/sevices/profile/learningDevelopment_service.dart b/lib/sevices/profile/learningDevelopment_service.dart new file mode 100644 index 0000000..9cf8154 --- /dev/null +++ b/lib/sevices/profile/learningDevelopment_service.dart @@ -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> getLearningDevelopments( + int profileId, String token) async { + List learningsAndDevelopments = []; + String authToken = "Token $token"; + String path = "${Url.instance.getLearningAndDevelopments()}$profileId/"; + Map 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; + } +} diff --git a/lib/utils/urls.dart b/lib/utils/urls.dart index b3506fb..b5bd7db 100644 --- a/lib/utils/urls.dart +++ b/lib/utils/urls.dart @@ -5,8 +5,8 @@ class Url { String host() { // // return '192.168.10.221:3003'; // return 'agusandelnorte.gov.ph'; - // return "192.168.10.219:3000"; - return "devweb.agusandelnorte.gov.ph"; + return "192.168.10.219:3000"; + // return "devweb.agusandelnorte.gov.ph"; // return 'devapi.agusandelnorte.gov.ph:3004'; } @@ -51,6 +51,12 @@ String getEducationalBackgrounds(){ return "/api/jobnet_app/profile/pds/education/"; } +//// learning and development paths + +String getLearningAndDevelopments(){ + return "api/jobnet_app/profile/pds/learning_development/"; +} + // location utils path String getCounties(){ return "/api/jobnet_app/countries/";