educational background refactor and create its own bloc
parent
fba53ce2dc
commit
61646bdcaa
|
@ -0,0 +1,25 @@
|
||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:unit2/model/profile/educational_background.dart';
|
||||||
|
import 'package:unit2/sevices/profile/education_services.dart';
|
||||||
|
|
||||||
|
part 'education_event.dart';
|
||||||
|
part 'education_state.dart';
|
||||||
|
|
||||||
|
class EducationBloc extends Bloc<EducationEvent, EducationState> {
|
||||||
|
List<EducationalBackground> educationalBackgrounds = [];
|
||||||
|
EducationBloc() : super(EducationInitial()) {
|
||||||
|
on<GetEducationalBackground>((event, emit) async {
|
||||||
|
emit(EducationalBackgroundLoadingState());
|
||||||
|
try {
|
||||||
|
List<EducationalBackground> educations = await EducationService.instace
|
||||||
|
.getEducationalBackground(event.profileId, event.token);
|
||||||
|
educationalBackgrounds = educations;
|
||||||
|
emit(EducationalBackgroundLoadedState(
|
||||||
|
educationalBackground: educationalBackgrounds));
|
||||||
|
} catch (e) {
|
||||||
|
emit(EducationalBackgroundErrorState(message: e.toString()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
part of 'education_bloc.dart';
|
||||||
|
|
||||||
|
abstract class EducationEvent extends Equatable {
|
||||||
|
const EducationEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
class GetEducationalBackground extends EducationEvent{
|
||||||
|
final int profileId;
|
||||||
|
final String token;
|
||||||
|
const GetEducationalBackground({required this.profileId, required this.token});
|
||||||
|
@override
|
||||||
|
List<Object> get props => [profileId,token];
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
part of 'education_bloc.dart';
|
||||||
|
|
||||||
|
abstract class EducationState extends Equatable {
|
||||||
|
const EducationState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class EducationInitial extends EducationState {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class EducationalBackgroundLoadedState extends EducationState{
|
||||||
|
final List<EducationalBackground> educationalBackground;
|
||||||
|
const EducationalBackgroundLoadedState({required this.educationalBackground});
|
||||||
|
@override
|
||||||
|
List<Object> get props => [educationalBackground];
|
||||||
|
}
|
||||||
|
|
||||||
|
class EducationalBackgroundErrorState extends EducationState{
|
||||||
|
final String message;
|
||||||
|
const EducationalBackgroundErrorState({required this.message});
|
||||||
|
@override
|
||||||
|
List<Object> get props => [message];
|
||||||
|
}
|
||||||
|
class EducationalBackgroundLoadingState extends EducationState{
|
||||||
|
|
||||||
|
}
|
|
@ -1,4 +1,10 @@
|
||||||
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:unit2/bloc/education/education_bloc.dart';
|
||||||
|
import 'package:unit2/bloc/profile/profile_bloc.dart';
|
||||||
|
import 'package:unit2/bloc/user/user_bloc.dart';
|
||||||
|
|
||||||
import 'package:unit2/model/profile/educational_background.dart';
|
import 'package:unit2/model/profile/educational_background.dart';
|
||||||
import 'package:unit2/theme-data.dart/box_shadow.dart';
|
import 'package:unit2/theme-data.dart/box_shadow.dart';
|
||||||
|
@ -6,122 +12,206 @@ import 'package:unit2/theme-data.dart/colors.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 EducationScreen extends StatelessWidget {
|
class EducationScreen extends StatelessWidget {
|
||||||
final List<EducationalBackground> educationBackgrounds;
|
|
||||||
const EducationScreen({super.key, required this.educationBackgrounds});
|
const EducationScreen({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: const Text(educationScreenTitle),
|
title: const Text(educationScreenTitle),
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
backgroundColor: primary,
|
backgroundColor: primary,
|
||||||
actions: [AddLeading(onPressed: (){})],
|
actions: [AddLeading(onPressed: () {})],
|
||||||
),
|
),
|
||||||
body: educationBackgrounds.isNotEmpty ? ListView.builder(
|
//userbloc
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
|
body: ProgressHUD(
|
||||||
itemCount: educationBackgrounds.length,
|
padding: const EdgeInsets.all(24),
|
||||||
itemBuilder: (BuildContext context, int index) {
|
backgroundColor: Colors.black87,
|
||||||
String level = educationBackgrounds[index].education!.level!;
|
indicatorWidget: const SpinKitFadingCircle(
|
||||||
String periodFrom = educationBackgrounds[index].periodFrom!;
|
color: Colors.white),
|
||||||
String periodTo = educationBackgrounds[index].periodTo!;
|
child: BlocBuilder<UserBloc, UserState>(
|
||||||
String? program =
|
builder: (context, state) {
|
||||||
educationBackgrounds[index].education!.course == null
|
if (state is UserLoggedIn) {
|
||||||
? null
|
//profilebloc
|
||||||
: educationBackgrounds[index].education!.course!
|
return BlocBuilder<ProfileBloc, ProfileState>(
|
||||||
.program!;
|
builder: (context, state) {
|
||||||
List<Honor>? honors =
|
if (state is ProfileLoaded) {
|
||||||
educationBackgrounds[index].honors!.toList();
|
//education bloc
|
||||||
String school =
|
return BlocConsumer<EducationBloc, EducationState>(
|
||||||
educationBackgrounds[index].education!.school!.name!;
|
listener: (context, state) {
|
||||||
return Column(
|
if (state is EducationalBackgroundLoadingState) {
|
||||||
children: [
|
final progress = ProgressHUD.of(context);
|
||||||
Container(
|
progress!.showWithText("Please wait...");
|
||||||
decoration: box1(),
|
}
|
||||||
padding:
|
if(state is EducationalBackgroundLoadedState || state is EducationalBackgroundErrorState){
|
||||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
final progress = ProgressHUD.of(context);
|
||||||
child: Row(
|
progress!.dismiss();
|
||||||
children: [
|
}
|
||||||
Expanded(
|
},
|
||||||
child: Column(
|
builder: (context, state) {
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
if (state is EducationalBackgroundLoadedState) {
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
if (state.educationalBackground.isNotEmpty) {
|
||||||
children: [
|
return ListView.builder(
|
||||||
Row(
|
padding: const EdgeInsets.symmetric(
|
||||||
children: [
|
vertical: 8, horizontal: 10),
|
||||||
Expanded(
|
itemCount: state.educationalBackground.length,
|
||||||
child: Text(
|
itemBuilder: (BuildContext context, int index) {
|
||||||
level,
|
String level = state
|
||||||
style: Theme.of(context)
|
.educationalBackground[index]
|
||||||
.textTheme
|
.education!
|
||||||
.titleMedium!
|
.level!;
|
||||||
.copyWith(fontWeight: FontWeight.w500),
|
String periodFrom = state
|
||||||
)),
|
.educationalBackground[index].periodFrom!;
|
||||||
Text(
|
String periodTo = state
|
||||||
"$periodFrom - $periodTo",
|
.educationalBackground[index].periodTo!;
|
||||||
style:
|
String? program = state
|
||||||
Theme.of(context).textTheme.bodyMedium,
|
.educationalBackground[index]
|
||||||
),
|
.education!
|
||||||
],
|
.course ==
|
||||||
),
|
null
|
||||||
|
? null
|
||||||
const SizedBox(height: 5,),
|
: state.educationalBackground[index]
|
||||||
Text(
|
.education!.course!.program!;
|
||||||
school,
|
List<Honor>? honors = state
|
||||||
style: Theme.of(context).textTheme.titleSmall,
|
.educationalBackground[index].honors!
|
||||||
),
|
.toList();
|
||||||
Container(
|
String school = state
|
||||||
padding: const EdgeInsets.only(top: 8),
|
.educationalBackground[index]
|
||||||
child: honors.isNotEmpty
|
.education!
|
||||||
? Column(
|
.school!
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
.name!;
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
return Column(
|
||||||
children: [
|
|
||||||
const Text("$honorsText : ",style: TextStyle(fontWeight: FontWeight.w600),),
|
|
||||||
Column(
|
|
||||||
children:
|
|
||||||
|
|
||||||
honors
|
|
||||||
.map((Honor honor) =>
|
|
||||||
Text(" - ${honor.name!}"))
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: const SizedBox()),
|
|
||||||
program == null
|
|
||||||
? const SizedBox()
|
|
||||||
: Column(
|
|
||||||
mainAxisAlignment:
|
|
||||||
MainAxisAlignment.start,
|
|
||||||
crossAxisAlignment:
|
|
||||||
CrossAxisAlignment.start,
|
|
||||||
children: [
|
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: [
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
level,
|
||||||
|
style: Theme.of(
|
||||||
|
context)
|
||||||
|
.textTheme
|
||||||
|
.titleMedium!
|
||||||
|
.copyWith(
|
||||||
|
fontWeight:
|
||||||
|
FontWeight
|
||||||
|
.w500),
|
||||||
|
)),
|
||||||
|
Text(
|
||||||
|
"$periodFrom - ",
|
||||||
|
style:
|
||||||
|
Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
school,
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.titleSmall,
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
padding:
|
||||||
|
const EdgeInsets
|
||||||
|
.only(top: 8),
|
||||||
|
child: honors.isNotEmpty
|
||||||
|
? Column(
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment
|
||||||
|
.start,
|
||||||
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment
|
||||||
|
.start,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
" : ",
|
||||||
|
style: TextStyle(
|
||||||
|
fontWeight:
|
||||||
|
FontWeight.w600),
|
||||||
|
),
|
||||||
|
Column(
|
||||||
|
children: honors
|
||||||
|
.map((Honor
|
||||||
|
honor) =>
|
||||||
|
Text(" - ${honor.name!}"))
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: const SizedBox()),
|
||||||
|
program == null
|
||||||
|
? const SizedBox()
|
||||||
|
: Column(
|
||||||
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment
|
||||||
|
.start,
|
||||||
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment
|
||||||
|
.start,
|
||||||
|
children: [
|
||||||
|
const SizedBox(
|
||||||
|
height: 5,
|
||||||
|
),
|
||||||
|
Text(program),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {},
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.more_vert,
|
||||||
|
color: Colors.grey,
|
||||||
|
))
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 5,
|
height: 5,
|
||||||
),
|
),
|
||||||
Text(program),
|
|
||||||
],
|
],
|
||||||
),
|
);
|
||||||
]),
|
});
|
||||||
),
|
} else {
|
||||||
IconButton(
|
const EmptyData(
|
||||||
onPressed: () {},
|
message:
|
||||||
icon: const Icon(
|
"You don't have any Educational Background added. Please click + to add.");
|
||||||
Icons.more_vert,
|
}
|
||||||
color: Colors.grey,
|
}if(state is EducationalBackgroundErrorState){
|
||||||
))
|
return SomethingWentWrong(message: state.message, onpressed: (){});
|
||||||
],
|
}
|
||||||
),
|
return Container();
|
||||||
),
|
},
|
||||||
const SizedBox(
|
);
|
||||||
height: 5,
|
}
|
||||||
),
|
return Container();
|
||||||
],
|
},
|
||||||
);
|
);
|
||||||
}):const EmptyData(message: "You don't have any Educational Background added. Please click + to add."),
|
}
|
||||||
);
|
return Container();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ class EligibiltyScreen extends StatelessWidget {
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
if (state is EligibilityLoadingState) {
|
if (state is EligibilityLoadingState) {
|
||||||
final progress = ProgressHUD.of(context);
|
final progress = ProgressHUD.of(context);
|
||||||
progress!.showWithText("Loading");
|
progress!.showWithText("Please wait...");
|
||||||
}
|
}
|
||||||
if (state is EligibilityLoaded ||
|
if (state is EligibilityLoaded ||
|
||||||
state is AddEligibilityState ||
|
state is AddEligibilityState ||
|
||||||
|
|
|
@ -8,6 +8,7 @@ import 'package:fluttericon/elusive_icons.dart';
|
||||||
import 'package:fluttericon/entypo_icons.dart';
|
import 'package:fluttericon/entypo_icons.dart';
|
||||||
import 'package:fluttericon/font_awesome5_icons.dart';
|
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/eligibility/eligibility_bloc.dart';
|
import 'package:unit2/bloc/eligibility/eligibility_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';
|
||||||
|
@ -17,6 +18,7 @@ import 'package:unit2/screens/profile/components/basic_information/citizenship_s
|
||||||
import 'package:unit2/screens/profile/components/basic_information/contact_information_screen.dart';
|
import 'package:unit2/screens/profile/components/basic_information/contact_information_screen.dart';
|
||||||
import 'package:unit2/screens/profile/components/basic_information/identification_information_screen.dart';
|
import 'package:unit2/screens/profile/components/basic_information/identification_information_screen.dart';
|
||||||
import 'package:unit2/screens/profile/components/basic_information/primary_information_screen.dart';
|
import 'package:unit2/screens/profile/components/basic_information/primary_information_screen.dart';
|
||||||
|
import 'package:unit2/screens/profile/components/education_screen.dart';
|
||||||
import 'package:unit2/screens/profile/components/eligibility_screen.dart';
|
import 'package:unit2/screens/profile/components/eligibility_screen.dart';
|
||||||
import 'package:unit2/screens/profile/components/family_background_screen.dart';
|
import 'package:unit2/screens/profile/components/family_background_screen.dart';
|
||||||
import 'package:unit2/screens/profile/components/learning_and_development_screen.dart';
|
import 'package:unit2/screens/profile/components/learning_and_development_screen.dart';
|
||||||
|
@ -157,13 +159,13 @@ class _ProfileInfoState extends State<ProfileInfo> {
|
||||||
icon: FontAwesome5.graduation_cap,
|
icon: FontAwesome5.graduation_cap,
|
||||||
title: "Education",
|
title: "Education",
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// Navigator.push(context, MaterialPageRoute(
|
Navigator.push(context, MaterialPageRoute(
|
||||||
// builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
// return EducationScreen(
|
return BlocProvider(
|
||||||
// educationBackgrounds: state
|
create: (context) => EducationBloc()..add(GetEducationalBackground(profileId: profileId!, token: token!)),
|
||||||
// .profileInformation
|
child: const EducationScreen(),
|
||||||
// .educationalBackgrounds);
|
);
|
||||||
// }));
|
}));
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:unit2/model/profile/educational_background.dart';
|
||||||
|
import 'package:unit2/utils/request.dart';
|
||||||
|
|
||||||
|
import '../../utils/urls.dart';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
class EducationService {
|
||||||
|
static final EducationService _instance = EducationService();
|
||||||
|
static EducationService get instace => _instance;
|
||||||
|
|
||||||
|
Future<List<EducationalBackground>> getEducationalBackground(
|
||||||
|
int profileId, String token) async {
|
||||||
|
List<EducationalBackground> educationalBackgrounds = [];
|
||||||
|
String authToken = "Token $token";
|
||||||
|
String path = "${Url.instance.getEducationalBackgrounds()}$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 education) {
|
||||||
|
EducationalBackground educationalBackground =
|
||||||
|
EducationalBackground.fromJson(education);
|
||||||
|
educationalBackgrounds.add(educationalBackground);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
throw e.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return educationalBackgrounds;
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ class WorkHistoryService{
|
||||||
'Content-Type': 'application/json; charset=UTF-8',
|
'Content-Type': 'application/json; charset=UTF-8',
|
||||||
'Authorization': authToken
|
'Authorization': authToken
|
||||||
};
|
};
|
||||||
String path= Url.instance.workHistories()+profileId.toString();
|
String path= Url.instance.getWorkHistories()+profileId.toString();
|
||||||
// try{
|
// try{
|
||||||
http.Response response =await Request.instance.getRequest(path: path, headers: headers, param: {});
|
http.Response response =await Request.instance.getRequest(path: path, headers: headers, param: {});
|
||||||
if(response.statusCode == 200){
|
if(response.statusCode == 200){
|
||||||
|
|
|
@ -42,10 +42,15 @@ String updateEligibility(){
|
||||||
return "/api/jobnet_app/profile/pds/eligibility/";
|
return "/api/jobnet_app/profile/pds/eligibility/";
|
||||||
}
|
}
|
||||||
//// work history paths
|
//// work history paths
|
||||||
String workHistories(){
|
String getWorkHistories(){
|
||||||
return "/api/jobnet_app/profile/pds/work/";
|
return "/api/jobnet_app/profile/pds/work/";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////educational background paths
|
||||||
|
String getEducationalBackgrounds(){
|
||||||
|
return "/api/jobnet_app/profile/pds/education/";
|
||||||
|
}
|
||||||
|
|
||||||
// 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