Edit eligibility with profile bloc

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-02-15 13:23:06 +08:00
parent b9615e3666
commit 4418107f21
8 changed files with 286 additions and 242 deletions

View File

@ -18,16 +18,18 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
ProfileInformation? profileInformation =
await ProfileService.instance.getProfile(event.token, event.userID);
_profileInformation = profileInformation;
emit(ProfileLoaded(
profileInformation: _profileInformation!));
emit(ProfileLoaded(profileInformation: _profileInformation!));
// } catch (e) {
// emit(ProfileErrorState(mesage: e.toString()));
// }
});
on<LoadEligibility>((event,emit){
on<LoadEligibility>((event, emit) {
emit(ProfileLoading());
emit(EligibilityLoaded(eligibilities: event.eligibilities));
});
on<EditEligibility>((event, emit) {
emit(EditEligibilityState(eligibityCert: event.eligibityCert));
});
}
}

View File

@ -28,3 +28,11 @@ class LoadEligibility extends ProfileEvent{
List<Object> get props => [];
}
class EditEligibility extends ProfileEvent{
final EligibityCert eligibityCert;
const EditEligibility({required this.eligibityCert});
@override
List<Object> get props => [];
}

View File

@ -34,3 +34,9 @@ class EligibilityLoaded extends ProfileState{
List<Object> get props => [eligibilities];
}
class EditEligibilityState extends ProfileState{
final EligibityCert eligibityCert;
const EditEligibilityState({required this.eligibityCert});
@override
List<Object> get props => [eligibityCert];
}

View File

@ -1,182 +1,114 @@
import 'package:app_popup_menu/app_popup_menu.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttericon/font_awesome_icons.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/model/profile/eligibility.dart';
import 'package:unit2/screens/profile/components/eligibility/edit_modal.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/alerts.dart';
import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart';
// import 'package:app_popup_menu/app_popup_menu.dart';
// import 'package:flutter/material.dart';
// import 'package:flutter/src/widgets/framework.dart';
// import 'package:flutter/src/widgets/placeholder.dart';
// import 'package:flutter_bloc/flutter_bloc.dart';
// import 'package:fluttericon/font_awesome_icons.dart';
// import 'package:unit2/bloc/profile/profile_bloc.dart';
// import 'package:unit2/bloc/user/user_bloc.dart';
// import 'package:unit2/model/profile/eligibility.dart';
// import 'package:unit2/screens/profile/components/eligibility/edit_modal.dart';
// import 'package:unit2/theme-data.dart/box_shadow.dart';
// import 'package:unit2/theme-data.dart/colors.dart';
// import 'package:unit2/utils/alerts.dart';
// import 'package:unit2/utils/global.dart';
// import 'package:unit2/utils/text_container.dart';
// import 'package:unit2/widgets/add_leading.dart';
// import 'package:unit2/widgets/empty_data.dart';
class EligibiltyScreen extends StatefulWidget {
const EligibiltyScreen({super.key,});
// class EligibiltyScreen extends StatefulWidget {
// const EligibiltyScreen({
// super.key,
// });
@override
State<EligibiltyScreen> createState() => _EligibiltyScreenState();
}
// @override
// State<EligibiltyScreen> createState() => _EligibiltyScreenState();
// }
class _EligibiltyScreenState extends State<EligibiltyScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(elibilityScreenTitle),
centerTitle: true,
backgroundColor: primary,
actions: context.read()[AddLeading(
onPressed: () => () {},
)],
),
body: BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if(state is EligibilityLoaded){
return ListView.builder(
padding:
const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
itemCount: state.eligibilities.length,
itemBuilder: (BuildContext context, int index) {
String title =
state.eligibilities[index].eligibility!.title!;
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: screenWidth,
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
decoration: box1(),
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
title,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight: FontWeight.w500),
),
const Divider(),
const SizedBox(
height: 5,
),
Text(
"$licenseNumber: ${state.eligibilities[index].licenseNumber == null ? 'N/A' : state.eligibilities[index].licenseNumber.toString()}",
style: Theme.of(context)
.textTheme
.titleSmall),
const SizedBox(
height: 3,
),
Text(
" : ${state.eligibilities[index].rating ?? 'N/A'}.",
style: Theme.of(context)
.textTheme
.titleSmall)
]),
),
AppPopupMenu<int>(
offset: const Offset(-10, -10),
elevation: 3,
onSelected: (value) {
// if (value == 1) {
// confirmAlert(context, () => null,
// "Delete?", "Confirm Delete?");
// }
// if (value == 2) {
// context.read<ProfileBloc>().add(
// EditEligibility(
// eligibityCert: widget
// .eligibilities[index]));
// }
},
menuItems: [
PopupMenuItem(
value: 1,
child: Row(
children: const [
Icon(
Icons.delete,
),
SizedBox(
width: 10,
),
Text(
'Delete',
),
],
),
),
PopupMenuItem(
value: 2,
child: Row(
children: const [
Icon(
Icons.edit,
),
SizedBox(
width: 10,
),
Text(
'Edit',
),
],
),
),
PopupMenuItem(
value: 2,
child: Row(
children: const [
Icon(
FontAwesome.attach,
),
SizedBox(
width: 10,
),
Text(
'Attachment',
),
],
),
),
],
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
),
tooltip: "Options",
)
],
),
),
const SizedBox(
height: 5,
)
],
);
});
}
return Container();
},
);
},
));
}
}
// class _EligibiltyScreenState extends State<EligibiltyScreen> {
// @override
// Widget build(BuildContext context) {
// return Scaffold(
// appBar: AppBar(
// title: const Text(elibilityScreenTitle),
// centerTitle: true,
// backgroundColor: primary,
// actions: context.read()[AddLeading(
// onPressed: () => () {},
// )],
// ),
// body: BlocBuilder<UserBloc, UserState>(
// builder: (context, state) {
// return BlocBuilder<ProfileBloc, ProfileState>(
// builder: (context, state) {
// if (state is EligibilityLoaded) {
// return ListView.builder(
// padding: const EdgeInsets.symmetric(
// vertical: 8, horizontal: 10),
// itemCount: state.eligibilities.length,
// itemBuilder: (BuildContext context, int index) {
// String title =
// state.eligibilities[index].eligibility!.title!;
// return Column(
// mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Container(
// width: screenWidth,
// padding: const EdgeInsets.symmetric(
// horizontal: 12, vertical: 8),
// decoration: box1(),
// child: Row(
// children: [
// Expanded(
// child: Column(
// mainAxisAlignment:
// MainAxisAlignment.start,
// crossAxisAlignment:
// CrossAxisAlignment.start,
// children: [
// Text(
// title,
// style: Theme.of(context)
// .textTheme
// .titleMedium!
// .copyWith(
// fontWeight:
// FontWeight.w500),
// ),
// const Divider(),
// const SizedBox(
// height: 5,
// ),
// Text(
// "$licenseNumber: ${state.eligibilities[index].licenseNumber == null ? 'N/A' : state.eligibilities[index].licenseNumber.toString()}",
// style: Theme.of(context)
// .textTheme
// .titleSmall),
// const SizedBox(
// height: 3,
// ),
// Text(
// " : ${state.eligibilities[index].rating ?? 'N/A'}.",
// style: Theme.of(context)
// .textTheme
// .titleSmall)
// ]),
// ),
// ]
// ),
// ),
// const SizedBox(
// height: 5,
// )
// ],
// );
// });
// }
// return Container();
// },
// );
// },
// ));
// }
// }

View File

@ -1,7 +1,13 @@
import 'package:app_popup_menu/app_popup_menu.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttericon/font_awesome_icons.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/model/profile/eligibility.dart';
import 'package:unit2/screens/profile/components/eligibility/edit_modal.dart';
import 'package:unit2/theme-data.dart/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/global.dart';
@ -9,10 +15,9 @@ import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart';
class EligibiltyScreen extends StatelessWidget {
final List<EligibityCert> eligibilities;
const EligibiltyScreen({super.key, required this.eligibilities});
import '../../../utils/alerts.dart';
class EligibiltyScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
@ -20,50 +25,141 @@ class EligibiltyScreen extends StatelessWidget {
title: const Text(elibilityScreenTitle),
centerTitle: true,
backgroundColor: primary,
actions: [AddLeading(onPressed: (){})],
actions: [AddLeading(onPressed: () {})],
),
body: eligibilities.isNotEmpty? ListView.builder(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
itemCount: eligibilities.length,
body: BlocBuilder<UserBloc, UserState>(
builder: (context, state) {
if (state is UserLoggedIn) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is EligibilityLoaded) {
return ListView.builder(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 10),
itemCount: state.eligibilities.length,
itemBuilder: (BuildContext context, int index) {
String title = eligibilities[index].eligibility!.title!;
String title =
state.eligibilities[index].eligibility!.title!;
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: screenWidth,
padding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
decoration: box1(),
child: Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
title,style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500),
title,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight.w500),
),
const Divider(),
const SizedBox(height: 5,),
const SizedBox(
height: 5,
),
Text(
"$licenseNumber: ${eligibilities[index].licenseNumber == null ? 'N/A' : eligibilities[index].licenseNumber.toString()}",style: Theme.of(context).textTheme.titleSmall),
const SizedBox(height: 3,),
"$licenseNumber: ${state.eligibilities[index].licenseNumber == null ? 'N/A' : state.eligibilities[index].licenseNumber.toString()}",
style: Theme.of(context)
.textTheme
.titleSmall),
const SizedBox(
height: 3,
),
Text(
"$rating : ${eligibilities[index].rating}.",style: Theme.of(context).textTheme.titleSmall)
" : ${state.eligibilities[index].rating}.",
style: Theme.of(context)
.textTheme
.titleSmall)
]),
),
IconButton(
onPressed: () {}, icon: const Icon(Icons.more_vert,color: Colors.grey,))
AppPopupMenu<int>(
offset: const Offset(-10, -10),
elevation: 3,
onSelected: (value) {
if (value == 2) {
confirmAlert(context, () => null,
"Delete?", "Confirm Delete?");
}
if (value == 1) {
context.read<ProfileBloc>().add(
EditEligibility(
eligibityCert: state
.eligibilities[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",
)
],
),
),
const SizedBox(height: 5,)
const SizedBox(
height: 5,
)
],
);
}):const EmptyData(message: "You don't have any Eligibility added. Please click + to add."),
});
}
if (state is EditEligibilityState) {
return EditEligibilityScreen(
eligibityCert: state.eligibityCert);
}
return Container();
},
);
}
return Container();
},
));
}
PopupMenuItem<int> popMenuItem({String? text, int? value, IconData? icon}) {
return PopupMenuItem(
value: value,
child: Row(
children: [
Icon(
icon,
),
const SizedBox(
width: 10,
),
Text(
text!,
),
],
),
);
}
}

View File

@ -173,8 +173,7 @@ class _ProfileInfoState extends State<ProfileInfo> {
return BlocProvider<ProfileBloc>.value(value: ProfileBloc()..add(LoadEligibility(eligibilities: state.profileInformation.eligibilities)),
child: EligibiltyScreen(
eligibilities: state
.profileInformation.eligibilities),
),
);
}));
},

View File

@ -20,7 +20,8 @@ Widget getTile(
if (title.toLowerCase() == "logout") {
confirmAlert(context, () {
Navigator.pushReplacementNamed (context,"/");
});
},"Logout","Are You sure you want to logout?");
}if(title.toLowerCase() == 'profile'){
ProfileArguments profileArguments = ProfileArguments(token: userData.user!.login!.token!, userID:userData.user!.login!.user!.profileId!);
Navigator.pushNamed(context, route,arguments: profileArguments);

View File

@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/global.dart';
confirmAlert(context, Function() yes) {
confirmAlert(context, Function() yes,String title, String subtitle) {
AwesomeDialog(
context: context,
dialogType: DialogType.question,
@ -26,8 +26,8 @@ confirmAlert(context, Function() yes) {
// },
headerAnimationLoop: false,
animType: AnimType.bottomSlide,
title: 'LOGOUT!',
desc: 'Are you sure you want to logout?',
title: title,
desc: subtitle,
btnOkText: "Yes",
btnCancelText: "No",
showCloseIcon: false,