volunaty work & civic service refactor and created its own bloc
parent
c83572cfb1
commit
4151038ff3
|
@ -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<VoluntaryWorkEvent, VoluntaryWorkState> {
|
||||
VoluntaryWorkBloc() : super(VoluntaryWorkInitial()) {
|
||||
List<VoluntaryWork> voluntaryWorks = [];
|
||||
on<GetVoluntarWorks>((event, emit) async{
|
||||
emit(VoluntaryWorkLoadingState());
|
||||
try{
|
||||
List<VoluntaryWork> works = await VoluntaryService.instance.getVoluntaryWorks(event.profileId, event.token);
|
||||
voluntaryWorks = works;
|
||||
emit(VoluntaryWorkLoadedState(voluntaryWorks: voluntaryWorks));
|
||||
}catch(e){
|
||||
emit(VoluntaryWorkErrorState(message: e.toString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
part of 'voluntary_work_bloc.dart';
|
||||
|
||||
abstract class VoluntaryWorkEvent extends Equatable {
|
||||
const VoluntaryWorkEvent();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class GetVoluntarWorks extends VoluntaryWorkEvent{
|
||||
final int profileId;
|
||||
final String token;
|
||||
const GetVoluntarWorks({required this.profileId, required this.token});
|
||||
@override
|
||||
List<Object> get props => [profileId,token];
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
part of 'voluntary_work_bloc.dart';
|
||||
|
||||
abstract class VoluntaryWorkState extends Equatable {
|
||||
const VoluntaryWorkState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
}
|
||||
|
||||
class VoluntaryWorkInitial extends VoluntaryWorkState {}
|
||||
class VoluntaryWorkLoadedState extends VoluntaryWorkState{
|
||||
final List<VoluntaryWork> voluntaryWorks;
|
||||
const VoluntaryWorkLoadedState({required this.voluntaryWorks});
|
||||
@override
|
||||
List<Object> get props => [voluntaryWorks];
|
||||
}
|
||||
|
||||
class VoluntaryWorkErrorState extends VoluntaryWorkState{
|
||||
final String message;
|
||||
const VoluntaryWorkErrorState({required this.message});
|
||||
@override
|
||||
List<Object> get props => [message];
|
||||
}
|
||||
|
||||
class VoluntaryWorkLoadingState extends VoluntaryWorkState{
|
||||
|
||||
}
|
|
@ -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<VoluntaryWork> voluntaryWorks;
|
||||
const VolunataryWorkScreen({super.key, required this.voluntaryWorks});
|
||||
const VolunataryWorkScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -20,57 +24,105 @@ class VolunataryWorkScreen extends StatelessWidget {
|
|||
backgroundColor: primary,
|
||||
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
|
||||
body: ProgressHUD(
|
||||
padding: const EdgeInsets.all(24),
|
||||
backgroundColor: Colors.black87,
|
||||
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
|
||||
child: BlocBuilder<UserBloc, UserState>(
|
||||
builder: (context, state) {
|
||||
if (state is UserLoggedIn) {
|
||||
return BlocBuilder<ProfileBloc, ProfileState>(
|
||||
builder: (context, state) {
|
||||
if (state is ProfileLoaded) {
|
||||
return BlocConsumer<VoluntaryWorkBloc,
|
||||
VoluntaryWorkState>(
|
||||
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(voluntaryWorks[index].toDate!);
|
||||
: dteFormat2.format(state
|
||||
.voluntaryWorks[index].toDate!);
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
decoration: box1(),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment
|
||||
.start,
|
||||
children: [
|
||||
Text(
|
||||
position,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleMedium!
|
||||
.copyWith(fontWeight: FontWeight.w500),
|
||||
.copyWith(
|
||||
fontWeight:
|
||||
FontWeight
|
||||
.w500),
|
||||
),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Text(
|
||||
agency,
|
||||
style: Theme.of(context).textTheme.titleSmall,
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleSmall,
|
||||
),
|
||||
const Divider(),
|
||||
const SizedBox(
|
||||
height: 3,
|
||||
),
|
||||
Text("$duration : $from to $to"),
|
||||
Text(
|
||||
"$duration : $from to $to"),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Text("$numberOfHours : $hours hours"),
|
||||
Text(
|
||||
"$numberOfHours : $hours hours"),
|
||||
]),
|
||||
),
|
||||
IconButton(
|
||||
onPressed: () {}, icon: const Icon(Icons.more_vert))
|
||||
onPressed: () {},
|
||||
icon: const Icon(
|
||||
Icons.more_vert))
|
||||
],
|
||||
),
|
||||
),
|
||||
|
@ -79,7 +131,24 @@ class VolunataryWorkScreen extends StatelessWidget {
|
|||
),
|
||||
],
|
||||
);
|
||||
}):const EmptyData(message: "You don't have any Voluntary Works added. Please click + to add."),
|
||||
});
|
||||
} else {
|
||||
return const EmptyData(
|
||||
message:
|
||||
"You don't have any Voluntary Works added. Please click + to add.");
|
||||
}
|
||||
}
|
||||
return Container();
|
||||
},
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
},
|
||||
);
|
||||
}
|
||||
return Container();
|
||||
},
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ProfileInfo> {
|
|||
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(),
|
||||
|
|
|
@ -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<VoluntaryWork>> getVoluntaryWorks(int profileId, String token)async{
|
||||
List<VoluntaryWork> voluntaryWorks = [];
|
||||
String authToken = "Token $token";
|
||||
String path = "${Url.instance.getVoluntaryWorks()}$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 work){
|
||||
VoluntaryWork voluntaryWork = VoluntaryWork.fromJson(work);
|
||||
voluntaryWorks.add(voluntaryWork);
|
||||
});
|
||||
}
|
||||
}
|
||||
}catch(e){
|
||||
throw(e.toString());
|
||||
}
|
||||
|
||||
return voluntaryWorks;
|
||||
}
|
||||
}
|
|
@ -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/";
|
||||
|
|
Loading…
Reference in New Issue