diff --git a/lib/bloc/voluntary_works/voluntary_work_bloc.dart b/lib/bloc/voluntary_works/voluntary_work_bloc.dart new file mode 100644 index 0000000..f12ce40 --- /dev/null +++ b/lib/bloc/voluntary_works/voluntary_work_bloc.dart @@ -0,0 +1,25 @@ +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:unit2/sevices/profile/volunatary_services.dart'; +import 'package:unit2/sevices/profile/work_history_services.dart'; + +import '../../model/profile/voluntary_works.dart'; + +part 'voluntary_work_event.dart'; +part 'voluntary_work_state.dart'; + +class VoluntaryWorkBloc extends Bloc { + VoluntaryWorkBloc() : super(VoluntaryWorkInitial()) { + List voluntaryWorks = []; + on((event, emit) async{ + emit(VoluntaryWorkLoadingState()); + try{ + List works = await VoluntaryService.instance.getVoluntaryWorks(event.profileId, event.token); + voluntaryWorks = works; + emit(VoluntaryWorkLoadedState(voluntaryWorks: voluntaryWorks)); + }catch(e){ + emit(VoluntaryWorkErrorState(message: e.toString())); + } + }); + } +} diff --git a/lib/bloc/voluntary_works/voluntary_work_event.dart b/lib/bloc/voluntary_works/voluntary_work_event.dart new file mode 100644 index 0000000..0e62010 --- /dev/null +++ b/lib/bloc/voluntary_works/voluntary_work_event.dart @@ -0,0 +1,16 @@ +part of 'voluntary_work_bloc.dart'; + +abstract class VoluntaryWorkEvent extends Equatable { + const VoluntaryWorkEvent(); + + @override + List get props => []; +} + +class GetVoluntarWorks extends VoluntaryWorkEvent{ + final int profileId; + final String token; + const GetVoluntarWorks({required this.profileId, required this.token}); + @override + List get props => [profileId,token]; +} diff --git a/lib/bloc/voluntary_works/voluntary_work_state.dart b/lib/bloc/voluntary_works/voluntary_work_state.dart new file mode 100644 index 0000000..8c2c912 --- /dev/null +++ b/lib/bloc/voluntary_works/voluntary_work_state.dart @@ -0,0 +1,27 @@ +part of 'voluntary_work_bloc.dart'; + +abstract class VoluntaryWorkState extends Equatable { + const VoluntaryWorkState(); + + @override + List get props => []; +} + +class VoluntaryWorkInitial extends VoluntaryWorkState {} +class VoluntaryWorkLoadedState extends VoluntaryWorkState{ + final List voluntaryWorks; + const VoluntaryWorkLoadedState({required this.voluntaryWorks}); + @override + List get props => [voluntaryWorks]; +} + +class VoluntaryWorkErrorState extends VoluntaryWorkState{ + final String message; + const VoluntaryWorkErrorState({required this.message}); + @override + List get props => [message]; +} + +class VoluntaryWorkLoadingState extends VoluntaryWorkState{ + +} diff --git a/lib/screens/profile/components/voluntary_works_screen.dart b/lib/screens/profile/components/voluntary_works_screen.dart index 17c33b8..18b89f5 100644 --- a/lib/screens/profile/components/voluntary_works_screen.dart +++ b/lib/screens/profile/components/voluntary_works_screen.dart @@ -1,6 +1,11 @@ import 'package:flutter/material.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/model/profile/voluntary_works.dart'; +import 'package:unit2/bloc/profile/profile_bloc.dart'; +import 'package:unit2/bloc/user/user_bloc.dart'; +import 'package:unit2/bloc/voluntary_works/voluntary_work_bloc.dart'; import 'package:unit2/theme-data.dart/box_shadow.dart'; import 'package:unit2/theme-data.dart/colors.dart'; import 'package:unit2/utils/text_container.dart'; @@ -8,8 +13,7 @@ import 'package:unit2/widgets/Leadings/add_leading.dart'; import 'package:unit2/widgets/empty_data.dart'; class VolunataryWorkScreen extends StatelessWidget { - final List voluntaryWorks; - const VolunataryWorkScreen({super.key, required this.voluntaryWorks}); + const VolunataryWorkScreen({super.key}); @override Widget build(BuildContext context) { @@ -18,68 +22,133 @@ class VolunataryWorkScreen extends StatelessWidget { appBar: AppBar( title: const Text(voluntaryScreenTitle), backgroundColor: primary, - actions: [AddLeading(onPressed: (){})], + actions: [AddLeading(onPressed: () {})], ), - body: voluntaryWorks.isNotEmpty? ListView.builder( - itemCount: voluntaryWorks.length, - padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10), - itemBuilder: (BuildContext context, int index) { - String position = voluntaryWorks[index].position!.title!; - String agency = voluntaryWorks[index].agency!.name!; - String from = dteFormat2.format(voluntaryWorks[index].fromDate!); - String hours = voluntaryWorks[index].totalHours.toString(); - String? to = voluntaryWorks[index].toDate == null - ? "Present" - : dteFormat2.format(voluntaryWorks[index].toDate!); - return Column( - children: [ - Container( - decoration: box1(), - padding: - const EdgeInsets.symmetric(horizontal: 12, vertical: 8), - child: Row( - children: [ - Expanded( - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - position, - style: Theme.of(context) - .textTheme - .titleMedium! - .copyWith(fontWeight: FontWeight.w500), - ), - const SizedBox( - height: 5, - ), - Text( - agency, - style: Theme.of(context).textTheme.titleSmall, - ), - const Divider(), - const SizedBox( - height: 3, - ), - Text("$duration : $from to $to"), - const SizedBox( - height: 5, - ), - Text("$numberOfHours : $hours hours"), - ]), - ), - IconButton( - onPressed: () {}, icon: const Icon(Icons.more_vert)) - ], - ), - ), - const SizedBox( - height: 5, - ), - ], - ); - }):const EmptyData(message: "You don't have any Voluntary Works added. Please click + to add."), + body: ProgressHUD( + padding: const EdgeInsets.all(24), + backgroundColor: Colors.black87, + indicatorWidget: const SpinKitFadingCircle(color: Colors.white), + 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 VoluntaryWorkLoadingState) { + final progress = ProgressHUD.of(context); + progress!.showWithText("Please wait..."); + } + if (state is VoluntaryWorkLoadedState || + state is VoluntaryWorkErrorState) { + final progress = ProgressHUD.of(context); + progress!.dismiss(); + } + }, + builder: (context, state) { + if (state is VoluntaryWorkLoadedState) { + if (state.voluntaryWorks.isNotEmpty) { + return ListView.builder( + itemCount: state.voluntaryWorks.length, + padding: const EdgeInsets.symmetric( + vertical: 8, horizontal: 10), + itemBuilder: + (BuildContext context, int index) { + String position = state + .voluntaryWorks[index].position!.title!; + String agency = state + .voluntaryWorks[index].agency!.name!; + String from = dteFormat2.format( + state.voluntaryWorks[index].fromDate!); + String hours = state + .voluntaryWorks[index].totalHours + .toString(); + String? to = + state.voluntaryWorks[index].toDate == + null + ? "Present" + : dteFormat2.format(state + .voluntaryWorks[index].toDate!); + return Column( + children: [ + Container( + decoration: box1(), + padding: const EdgeInsets.symmetric( + horizontal: 12, vertical: 8), + child: Row( + children: [ + Expanded( + child: Column( + mainAxisAlignment: + MainAxisAlignment.start, + crossAxisAlignment: + CrossAxisAlignment + .start, + children: [ + Text( + position, + style: Theme.of(context) + .textTheme + .titleMedium! + .copyWith( + fontWeight: + FontWeight + .w500), + ), + const SizedBox( + height: 5, + ), + Text( + agency, + style: Theme.of(context) + .textTheme + .titleSmall, + ), + const Divider(), + const SizedBox( + height: 3, + ), + Text( + "$duration : $from to $to"), + const SizedBox( + height: 5, + ), + Text( + "$numberOfHours : $hours hours"), + ]), + ), + IconButton( + onPressed: () {}, + icon: const Icon( + Icons.more_vert)) + ], + ), + ), + const SizedBox( + height: 5, + ), + ], + ); + }); + } else { + return const EmptyData( + message: + "You don't have any Voluntary Works added. Please click + to add."); + } + } + return Container(); + }, + ); + } + return Container(); + }, + ); + } + return Container(); + }, + )), ); } } diff --git a/lib/screens/profile/profile.dart b/lib/screens/profile/profile.dart index 951b2e7..f6256d2 100644 --- a/lib/screens/profile/profile.dart +++ b/lib/screens/profile/profile.dart @@ -13,6 +13,7 @@ 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/references/references_bloc.dart'; +import 'package:unit2/bloc/voluntary_works/voluntary_work_bloc.dart'; import 'package:unit2/bloc/workHistory/workHistory_bloc.dart'; import 'package:unit2/model/login_data/employee_info/employee_info.dart'; import 'package:unit2/screens/profile/components/basic_information/address_screen.dart'; @@ -204,12 +205,13 @@ class _ProfileInfoState extends State { icon: FontAwesome5.walking, title: "Voluntary Work & Civic Services", onTap: () { - // Navigator.push(context, MaterialPageRoute( - // builder: (BuildContext context) { - // return VolunataryWorkScreen( - // voluntaryWorks: state - // .profileInformation.voluntaryWorks); - // })); + Navigator.push(context, MaterialPageRoute( + builder: (BuildContext context) { + return BlocProvider( + create: (context) => VoluntaryWorkBloc()..add(GetVoluntarWorks(profileId: profileId!, token: token!)), + child: const VolunataryWorkScreen(), + ); + })); }, ), const Divider(), diff --git a/lib/sevices/profile/volunatary_services.dart b/lib/sevices/profile/volunatary_services.dart new file mode 100644 index 0000000..41d4974 --- /dev/null +++ b/lib/sevices/profile/volunatary_services.dart @@ -0,0 +1,39 @@ + +import 'dart:convert'; + +import 'package:http/http.dart' as http; +import 'package:unit2/utils/request.dart'; +import '../../model/profile/voluntary_works.dart'; +import '../../utils/urls.dart'; + +class VoluntaryService{ + static final VoluntaryService _instance = VoluntaryService(); + static VoluntaryService get instance => _instance; + + Future< List> getVoluntaryWorks(int profileId, String token)async{ + List voluntaryWorks = []; + String authToken = "Token $token"; + String path = "${Url.instance.getVoluntaryWorks()}$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 work){ + VoluntaryWork voluntaryWork = VoluntaryWork.fromJson(work); + voluntaryWorks.add(voluntaryWork); + }); + } + } + }catch(e){ + throw(e.toString()); + } + +return voluntaryWorks; + } +} \ No newline at end of file diff --git a/lib/utils/urls.dart b/lib/utils/urls.dart index 412a4b2..1908f93 100644 --- a/lib/utils/urls.dart +++ b/lib/utils/urls.dart @@ -62,6 +62,11 @@ String getRefences(){ return "/api/jobnet_app/profile/pds/personal_reference/"; } + +////voluntary works +String getVoluntaryWorks(){ + return "/api/jobnet_app/profile/pds/voluntary_work/"; +} // location utils path String getCounties(){ return "/api/jobnet_app/countries/";