2023-04-25 07:50:36 +00:00
|
|
|
import 'package:app_popup_menu/app_popup_menu.dart';
|
2023-02-07 01:29:38 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-03-02 06:59:40 +00:00
|
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
import 'package:flutter_progress_hud/flutter_progress_hud.dart';
|
|
|
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
2023-04-25 07:50:36 +00:00
|
|
|
import 'package:fluttericon/font_awesome_icons.dart';
|
2023-03-02 06:59:40 +00:00
|
|
|
import 'package:unit2/bloc/profile/profile_bloc.dart';
|
|
|
|
import 'package:unit2/bloc/user/user_bloc.dart';
|
2023-02-09 08:48:19 +00:00
|
|
|
|
2023-02-07 01:29:38 +00:00
|
|
|
import 'package:unit2/model/profile/educational_background.dart';
|
2023-04-25 07:50:36 +00:00
|
|
|
import 'package:unit2/screens/profile/components/education/add_modal.dart';
|
2023-02-09 08:48:19 +00:00
|
|
|
import 'package:unit2/theme-data.dart/box_shadow.dart';
|
2023-02-07 01:29:38 +00:00
|
|
|
import 'package:unit2/theme-data.dart/colors.dart';
|
2023-02-09 08:48:19 +00:00
|
|
|
import 'package:unit2/utils/text_container.dart';
|
2023-03-02 00:40:47 +00:00
|
|
|
import 'package:unit2/widgets/Leadings/add_leading.dart';
|
2023-02-10 07:39:00 +00:00
|
|
|
import 'package:unit2/widgets/empty_data.dart';
|
2023-03-02 06:59:40 +00:00
|
|
|
import 'package:unit2/widgets/error_state.dart';
|
2023-02-07 01:29:38 +00:00
|
|
|
|
2023-03-07 02:31:28 +00:00
|
|
|
import '../../../bloc/profile/education/education_bloc.dart';
|
2023-04-25 07:50:36 +00:00
|
|
|
import '../../../utils/alerts.dart';
|
2023-05-02 00:26:42 +00:00
|
|
|
import '../../../widgets/Leadings/close_leading.dart';
|
2023-04-25 07:50:36 +00:00
|
|
|
import 'education/edit_modal.dart';
|
2023-03-07 02:31:28 +00:00
|
|
|
|
2023-02-10 07:39:00 +00:00
|
|
|
class EducationScreen extends StatelessWidget {
|
2023-03-02 06:59:40 +00:00
|
|
|
const EducationScreen({super.key});
|
2023-02-07 01:29:38 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-04-25 07:50:36 +00:00
|
|
|
int profileId;
|
|
|
|
String? token;
|
2023-02-07 01:29:38 +00:00
|
|
|
return Scaffold(
|
2023-03-02 06:59:40 +00:00
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text(educationScreenTitle),
|
|
|
|
centerTitle: true,
|
|
|
|
backgroundColor: primary,
|
2023-05-02 00:26:42 +00:00
|
|
|
actions: context.watch<EducationBloc>().state is EducationalBackgroundLoadedState?[
|
2023-04-25 07:50:36 +00:00
|
|
|
AddLeading(onPressed: () {
|
|
|
|
context.read<EducationBloc>().add(ShowAddEducationForm());
|
|
|
|
})
|
2023-05-02 00:26:42 +00:00
|
|
|
]:(context.watch<EducationBloc>().state is AddEducationState || context.watch<EducationBloc>().state is EditEducationState)?[
|
|
|
|
CloseLeading(onPressed: () {
|
|
|
|
context.read<EducationBloc>().add( LoadEducations());
|
|
|
|
})
|
|
|
|
]:[],
|
2023-03-02 06:59:40 +00:00
|
|
|
),
|
|
|
|
//userbloc
|
|
|
|
body: ProgressHUD(
|
2023-03-06 05:29:38 +00:00
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
backgroundColor: Colors.black87,
|
|
|
|
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
|
2023-03-02 06:59:40 +00:00
|
|
|
child: BlocBuilder<UserBloc, UserState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
if (state is UserLoggedIn) {
|
2023-04-25 07:50:36 +00:00
|
|
|
token = state.userData!.user!.login!.token;
|
|
|
|
profileId = state.userData!.user!.login!.user!.profileId!;
|
2023-03-02 06:59:40 +00:00
|
|
|
//profilebloc
|
|
|
|
return BlocBuilder<ProfileBloc, ProfileState>(
|
|
|
|
builder: (context, state) {
|
|
|
|
if (state is ProfileLoaded) {
|
|
|
|
//education bloc
|
|
|
|
return BlocConsumer<EducationBloc, EducationState>(
|
|
|
|
listener: (context, state) {
|
2023-03-06 05:29:38 +00:00
|
|
|
if (state is EducationalBackgroundLoadingState) {
|
|
|
|
final progress = ProgressHUD.of(context);
|
|
|
|
progress!.showWithText("Please wait...");
|
|
|
|
}
|
|
|
|
if (state is EducationalBackgroundLoadedState ||
|
2023-04-25 07:50:36 +00:00
|
|
|
state is EducationalBackgroundErrorState ||
|
|
|
|
state is AddEducationState ||
|
|
|
|
state is EditEducationState ||
|
|
|
|
state is EducationDeletedState || state is EditedEducationState) {
|
2023-03-06 05:29:38 +00:00
|
|
|
final progress = ProgressHUD.of(context);
|
|
|
|
progress!.dismiss();
|
|
|
|
}
|
2023-04-25 07:50:36 +00:00
|
|
|
////ADDED STATE
|
|
|
|
if (state is EducationAddedState) {
|
|
|
|
if (state.response['success']) {
|
|
|
|
successAlert(context, "Adding Successfull!",
|
|
|
|
state.response['message'], () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context
|
|
|
|
.read<EducationBloc>()
|
|
|
|
.add(LoadEducations());
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
errorAlert(context, "Adding Failed",
|
|
|
|
"Something went wrong. Please try again.",
|
|
|
|
() {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context
|
|
|
|
.read<EducationBloc>()
|
|
|
|
.add(LoadEducations());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
////EDITED STATE
|
|
|
|
|
|
|
|
if (state is EditedEducationState) {
|
|
|
|
if (state.response['success']) {
|
|
|
|
successAlert(context, "Update Successfull!",
|
|
|
|
state.response['message'], () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context
|
|
|
|
.read<EducationBloc>()
|
|
|
|
.add(LoadEducations());
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
errorAlert(context, "Updated Failed",
|
|
|
|
"Something went wrong. Please try again.",
|
|
|
|
() {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context
|
|
|
|
.read<EducationBloc>()
|
|
|
|
.add(LoadEducations());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
////DELETED STATE
|
|
|
|
if (state is EducationDeletedState) {
|
|
|
|
if (state.success) {
|
|
|
|
successAlert(context, "Deletion Successfull",
|
|
|
|
"Educational Background has been deleted successfully",
|
|
|
|
() {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context
|
|
|
|
.read<EducationBloc>()
|
|
|
|
.add(LoadEducations());
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
errorAlert(context, "Deletion Failed",
|
|
|
|
"Error deleting Education Background", () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
context
|
|
|
|
.read<EducationBloc>()
|
|
|
|
.add(LoadEducations());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2023-03-02 06:59:40 +00:00
|
|
|
},
|
|
|
|
builder: (context, state) {
|
|
|
|
if (state is EducationalBackgroundLoadedState) {
|
|
|
|
if (state.educationalBackground.isNotEmpty) {
|
|
|
|
return ListView.builder(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 8, horizontal: 10),
|
|
|
|
itemCount: state.educationalBackground.length,
|
2023-03-06 05:29:38 +00:00
|
|
|
itemBuilder:
|
|
|
|
(BuildContext context, int index) {
|
2023-03-02 06:59:40 +00:00
|
|
|
String level = state
|
|
|
|
.educationalBackground[index]
|
|
|
|
.education!
|
|
|
|
.level!;
|
|
|
|
String periodFrom = state
|
2023-03-06 05:29:38 +00:00
|
|
|
.educationalBackground[index]
|
|
|
|
.periodFrom!;
|
2023-03-02 06:59:40 +00:00
|
|
|
String periodTo = state
|
|
|
|
.educationalBackground[index].periodTo!;
|
|
|
|
String? program = state
|
|
|
|
.educationalBackground[index]
|
|
|
|
.education!
|
|
|
|
.course ==
|
|
|
|
null
|
|
|
|
? null
|
|
|
|
: state.educationalBackground[index]
|
|
|
|
.education!.course!.program!;
|
|
|
|
List<Honor>? honors = state
|
|
|
|
.educationalBackground[index].honors!
|
|
|
|
.toList();
|
|
|
|
String school = state
|
|
|
|
.educationalBackground[index]
|
|
|
|
.education!
|
|
|
|
.school!
|
|
|
|
.name!;
|
|
|
|
return Column(
|
2023-02-09 08:48:19 +00:00
|
|
|
children: [
|
2023-03-02 06:59:40 +00:00
|
|
|
Container(
|
|
|
|
decoration: box1(),
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 12, vertical: 8),
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment:
|
2023-03-06 05:29:38 +00:00
|
|
|
CrossAxisAlignment
|
|
|
|
.start,
|
2023-03-02 06:59:40 +00:00
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
level,
|
|
|
|
style: Theme.of(
|
|
|
|
context)
|
|
|
|
.textTheme
|
|
|
|
.titleMedium!
|
|
|
|
.copyWith(
|
|
|
|
fontWeight:
|
|
|
|
FontWeight
|
|
|
|
.w500),
|
|
|
|
)),
|
|
|
|
Text(
|
|
|
|
"$periodFrom - ",
|
2023-03-06 05:29:38 +00:00
|
|
|
style: Theme.of(
|
|
|
|
context)
|
|
|
|
.textTheme
|
|
|
|
.bodyMedium,
|
2023-03-02 06:59:40 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 5,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
school,
|
|
|
|
style: Theme.of(context)
|
|
|
|
.textTheme
|
|
|
|
.titleSmall,
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
padding:
|
|
|
|
const EdgeInsets
|
|
|
|
.only(top: 8),
|
2023-03-06 05:29:38 +00:00
|
|
|
child: honors
|
|
|
|
.isNotEmpty
|
2023-03-02 06:59:40 +00:00
|
|
|
? Column(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment
|
|
|
|
.start,
|
|
|
|
crossAxisAlignment:
|
|
|
|
CrossAxisAlignment
|
|
|
|
.start,
|
|
|
|
children: [
|
|
|
|
const Text(
|
|
|
|
" : ",
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight:
|
|
|
|
FontWeight.w600),
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
children: honors
|
2023-03-06 05:29:38 +00:00
|
|
|
.map((Honor honor) =>
|
2023-03-02 06:59:40 +00:00
|
|
|
Text(" - ${honor.name!}"))
|
|
|
|
.toList(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
: const SizedBox()),
|
|
|
|
program == null
|
|
|
|
? const SizedBox()
|
|
|
|
: Column(
|
|
|
|
mainAxisAlignment:
|
|
|
|
MainAxisAlignment
|
|
|
|
.start,
|
|
|
|
crossAxisAlignment:
|
|
|
|
CrossAxisAlignment
|
|
|
|
.start,
|
|
|
|
children: [
|
|
|
|
const SizedBox(
|
|
|
|
height: 5,
|
|
|
|
),
|
|
|
|
Text(program),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
2023-04-25 07:50:36 +00:00
|
|
|
AppPopupMenu<int>(
|
|
|
|
offset: const Offset(-10, -10),
|
|
|
|
elevation: 3,
|
|
|
|
onSelected: (value) {
|
|
|
|
////delete -= = = = = = = = =>>
|
|
|
|
if (value == 2) {
|
|
|
|
confirmAlert(context, () {
|
|
|
|
final progress =
|
|
|
|
ProgressHUD.of(
|
|
|
|
context);
|
|
|
|
progress!.showWithText(
|
|
|
|
"Loading...");
|
|
|
|
context
|
|
|
|
.read<EducationBloc>()
|
|
|
|
.add(DeleteEducation(
|
|
|
|
educationalBackground:
|
|
|
|
state.educationalBackground[
|
|
|
|
index],
|
|
|
|
profileId:
|
|
|
|
profileId,
|
|
|
|
token: token!));
|
|
|
|
}, "Delete?",
|
|
|
|
"Confirm Delete?");
|
|
|
|
}
|
|
|
|
if (value == 1) {
|
|
|
|
////edit -= = = = = = = = =>>
|
|
|
|
final progress =
|
|
|
|
ProgressHUD.of(context);
|
|
|
|
progress!.showWithText(
|
|
|
|
"Loading...");
|
|
|
|
context
|
|
|
|
.read<EducationBloc>()
|
|
|
|
.add(ShowEditEducationForm(
|
|
|
|
profileId:
|
|
|
|
profileId,
|
|
|
|
token: token!,
|
|
|
|
educationalBackground:
|
|
|
|
state.educationalBackground[
|
|
|
|
index]));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
menuItems: [
|
|
|
|
popMenuItem(
|
|
|
|
text: "Edit",
|
|
|
|
value: 1,
|
|
|
|
icon: Icons.edit),
|
|
|
|
popMenuItem(
|
|
|
|
text: "Delete",
|
|
|
|
value: 2,
|
|
|
|
icon: Icons.delete),
|
|
|
|
popMenuItem(
|
|
|
|
text: "Attachment",
|
|
|
|
value: 3,
|
|
|
|
icon: FontAwesome.attach)
|
|
|
|
],
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.more_vert,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
|
|
|
tooltip: "Options",
|
|
|
|
)
|
2023-03-02 06:59:40 +00:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2023-02-09 08:48:19 +00:00
|
|
|
const SizedBox(
|
|
|
|
height: 5,
|
|
|
|
),
|
|
|
|
],
|
2023-03-02 06:59:40 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
const EmptyData(
|
|
|
|
message:
|
|
|
|
"You don't have any Educational Background added. Please click + to add.");
|
|
|
|
}
|
2023-03-06 05:29:38 +00:00
|
|
|
}
|
|
|
|
if (state is EducationalBackgroundErrorState) {
|
|
|
|
return SomethingWentWrong(
|
|
|
|
message: state.message, onpressed: () {});
|
2023-03-02 06:59:40 +00:00
|
|
|
}
|
2023-04-25 07:50:36 +00:00
|
|
|
if (state is AddEducationState) {
|
|
|
|
return AddEducationScreen(
|
|
|
|
token: token!,
|
|
|
|
profileId: profileId,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (state is EditEducationState) {
|
|
|
|
return EditEducationScreen(
|
|
|
|
token: token!,
|
|
|
|
profileId: profileId,
|
|
|
|
);
|
|
|
|
}
|
2023-03-02 06:59:40 +00:00
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Container();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
));
|
2023-02-07 01:29:38 +00:00
|
|
|
}
|
2023-04-25 07:50:36 +00:00
|
|
|
|
|
|
|
PopupMenuItem<int> popMenuItem({String? text, int? value, IconData? icon}) {
|
|
|
|
return PopupMenuItem(
|
|
|
|
value: value,
|
|
|
|
child: Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
icon,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
width: 10,
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
text!,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2023-02-07 01:29:38 +00:00
|
|
|
}
|