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/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: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/box_shadow.dart';
|
||||||
import 'package:unit2/theme-data.dart/colors.dart';
|
import 'package:unit2/theme-data.dart/colors.dart';
|
||||||
import 'package:unit2/utils/text_container.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';
|
import 'package:unit2/widgets/empty_data.dart';
|
||||||
|
|
||||||
class VolunataryWorkScreen extends StatelessWidget {
|
class VolunataryWorkScreen extends StatelessWidget {
|
||||||
final List<VoluntaryWork> voluntaryWorks;
|
const VolunataryWorkScreen({super.key});
|
||||||
const VolunataryWorkScreen({super.key, required this.voluntaryWorks});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -18,68 +22,133 @@ class VolunataryWorkScreen extends StatelessWidget {
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text(voluntaryScreenTitle),
|
title: const Text(voluntaryScreenTitle),
|
||||||
backgroundColor: primary,
|
backgroundColor: primary,
|
||||||
actions: [AddLeading(onPressed: (){})],
|
actions: [AddLeading(onPressed: () {})],
|
||||||
),
|
),
|
||||||
body: voluntaryWorks.isNotEmpty? ListView.builder(
|
body: ProgressHUD(
|
||||||
itemCount: voluntaryWorks.length,
|
padding: const EdgeInsets.all(24),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
|
backgroundColor: Colors.black87,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
|
||||||
String position = voluntaryWorks[index].position!.title!;
|
child: BlocBuilder<UserBloc, UserState>(
|
||||||
String agency = voluntaryWorks[index].agency!.name!;
|
builder: (context, state) {
|
||||||
String from = dteFormat2.format(voluntaryWorks[index].fromDate!);
|
if (state is UserLoggedIn) {
|
||||||
String hours = voluntaryWorks[index].totalHours.toString();
|
return BlocBuilder<ProfileBloc, ProfileState>(
|
||||||
String? to = voluntaryWorks[index].toDate == null
|
builder: (context, state) {
|
||||||
? "Present"
|
if (state is ProfileLoaded) {
|
||||||
: dteFormat2.format(voluntaryWorks[index].toDate!);
|
return BlocConsumer<VoluntaryWorkBloc,
|
||||||
return Column(
|
VoluntaryWorkState>(
|
||||||
children: [
|
listener: (context, state) {
|
||||||
Container(
|
if (state is VoluntaryWorkLoadingState) {
|
||||||
decoration: box1(),
|
final progress = ProgressHUD.of(context);
|
||||||
padding:
|
progress!.showWithText("Please wait...");
|
||||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
}
|
||||||
child: Row(
|
if (state is VoluntaryWorkLoadedState ||
|
||||||
children: [
|
state is VoluntaryWorkErrorState) {
|
||||||
Expanded(
|
final progress = ProgressHUD.of(context);
|
||||||
child: Column(
|
progress!.dismiss();
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
}
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
},
|
||||||
children: [
|
builder: (context, state) {
|
||||||
Text(
|
if (state is VoluntaryWorkLoadedState) {
|
||||||
position,
|
if (state.voluntaryWorks.isNotEmpty) {
|
||||||
style: Theme.of(context)
|
return ListView.builder(
|
||||||
.textTheme
|
itemCount: state.voluntaryWorks.length,
|
||||||
.titleMedium!
|
padding: const EdgeInsets.symmetric(
|
||||||
.copyWith(fontWeight: FontWeight.w500),
|
vertical: 8, horizontal: 10),
|
||||||
),
|
itemBuilder:
|
||||||
const SizedBox(
|
(BuildContext context, int index) {
|
||||||
height: 5,
|
String position = state
|
||||||
),
|
.voluntaryWorks[index].position!.title!;
|
||||||
Text(
|
String agency = state
|
||||||
agency,
|
.voluntaryWorks[index].agency!.name!;
|
||||||
style: Theme.of(context).textTheme.titleSmall,
|
String from = dteFormat2.format(
|
||||||
),
|
state.voluntaryWorks[index].fromDate!);
|
||||||
const Divider(),
|
String hours = state
|
||||||
const SizedBox(
|
.voluntaryWorks[index].totalHours
|
||||||
height: 3,
|
.toString();
|
||||||
),
|
String? to =
|
||||||
Text("$duration : $from to $to"),
|
state.voluntaryWorks[index].toDate ==
|
||||||
const SizedBox(
|
null
|
||||||
height: 5,
|
? "Present"
|
||||||
),
|
: dteFormat2.format(state
|
||||||
Text("$numberOfHours : $hours hours"),
|
.voluntaryWorks[index].toDate!);
|
||||||
]),
|
return Column(
|
||||||
),
|
children: [
|
||||||
IconButton(
|
Container(
|
||||||
onPressed: () {}, icon: const Icon(Icons.more_vert))
|
decoration: box1(),
|
||||||
],
|
padding: const EdgeInsets.symmetric(
|
||||||
),
|
horizontal: 12, vertical: 8),
|
||||||
),
|
child: Row(
|
||||||
const SizedBox(
|
children: [
|
||||||
height: 5,
|
Expanded(
|
||||||
),
|
child: Column(
|
||||||
],
|
mainAxisAlignment:
|
||||||
);
|
MainAxisAlignment.start,
|
||||||
}):const EmptyData(message: "You don't have any Voluntary Works added. Please click + to add."),
|
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();
|
||||||
|
},
|
||||||
|
)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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/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/references/references_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/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';
|
||||||
import 'package:unit2/screens/profile/components/basic_information/address_screen.dart';
|
import 'package:unit2/screens/profile/components/basic_information/address_screen.dart';
|
||||||
|
@ -204,12 +205,13 @@ class _ProfileInfoState extends State<ProfileInfo> {
|
||||||
icon: FontAwesome5.walking,
|
icon: FontAwesome5.walking,
|
||||||
title: "Voluntary Work & Civic Services",
|
title: "Voluntary Work & Civic Services",
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Navigator.push(context, MaterialPageRoute(
|
Navigator.push(context, MaterialPageRoute(
|
||||||
// builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
// return VolunataryWorkScreen(
|
return BlocProvider(
|
||||||
// voluntaryWorks: state
|
create: (context) => VoluntaryWorkBloc()..add(GetVoluntarWorks(profileId: profileId!, token: token!)),
|
||||||
// .profileInformation.voluntaryWorks);
|
child: const VolunataryWorkScreen(),
|
||||||
// }));
|
);
|
||||||
|
}));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const Divider(),
|
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/";
|
return "/api/jobnet_app/profile/pds/personal_reference/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
////voluntary works
|
||||||
|
String getVoluntaryWorks(){
|
||||||
|
return "/api/jobnet_app/profile/pds/voluntary_work/";
|
||||||
|
}
|
||||||
// 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