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

@ -14,20 +14,22 @@ class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
ProfileInformation? _profileInformation; ProfileInformation? _profileInformation;
on<LoadProfile>((event, emit) async { on<LoadProfile>((event, emit) async {
// try { // try {
emit(ProfileLoading()); emit(ProfileLoading());
ProfileInformation? profileInformation = ProfileInformation? profileInformation =
await ProfileService.instance.getProfile(event.token, event.userID); await ProfileService.instance.getProfile(event.token, event.userID);
_profileInformation = profileInformation; _profileInformation = profileInformation;
emit(ProfileLoaded( emit(ProfileLoaded(profileInformation: _profileInformation!));
profileInformation: _profileInformation!));
// } catch (e) { // } catch (e) {
// emit(ProfileErrorState(mesage: e.toString())); // emit(ProfileErrorState(mesage: e.toString()));
// } // }
}); });
on<LoadEligibility>((event,emit){ on<LoadEligibility>((event, emit) {
emit(ProfileLoading()); emit(ProfileLoading());
emit(EligibilityLoaded(eligibilities: event.eligibilities)); 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 => []; 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]; 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:app_popup_menu/app_popup_menu.dart';
import 'package:flutter/material.dart'; // import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart'; // import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart'; // import 'package:flutter/src/widgets/placeholder.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; // import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:fluttericon/font_awesome_icons.dart'; // import 'package:fluttericon/font_awesome_icons.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart'; // import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_bloc.dart'; // import 'package:unit2/bloc/user/user_bloc.dart';
import 'package:unit2/model/profile/eligibility.dart'; // import 'package:unit2/model/profile/eligibility.dart';
import 'package:unit2/screens/profile/components/eligibility/edit_modal.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/box_shadow.dart';
import 'package:unit2/theme-data.dart/colors.dart'; // import 'package:unit2/theme-data.dart/colors.dart';
import 'package:unit2/utils/alerts.dart'; // import 'package:unit2/utils/alerts.dart';
import 'package:unit2/utils/global.dart'; // import 'package:unit2/utils/global.dart';
import 'package:unit2/utils/text_container.dart'; // import 'package:unit2/utils/text_container.dart';
import 'package:unit2/widgets/add_leading.dart'; // import 'package:unit2/widgets/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart'; // import 'package:unit2/widgets/empty_data.dart';
class EligibiltyScreen extends StatefulWidget { // class EligibiltyScreen extends StatefulWidget {
const EligibiltyScreen({super.key,}); // const EligibiltyScreen({
// super.key,
// });
@override // @override
State<EligibiltyScreen> createState() => _EligibiltyScreenState(); // State<EligibiltyScreen> createState() => _EligibiltyScreenState();
} // }
class _EligibiltyScreenState extends State<EligibiltyScreen> { // class _EligibiltyScreenState extends State<EligibiltyScreen> {
@override // @override
Widget build(BuildContext context) { // Widget build(BuildContext context) {
return Scaffold( // return Scaffold(
appBar: AppBar( // appBar: AppBar(
title: const Text(elibilityScreenTitle), // title: const Text(elibilityScreenTitle),
centerTitle: true, // centerTitle: true,
backgroundColor: primary, // backgroundColor: primary,
actions: context.read()[AddLeading( // actions: context.read()[AddLeading(
onPressed: () => () {}, // onPressed: () => () {},
)], // )],
), // ),
body: BlocBuilder<UserBloc, UserState>( // body: BlocBuilder<UserBloc, UserState>(
builder: (context, state) { // builder: (context, state) {
return BlocBuilder<ProfileBloc, ProfileState>( // return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) { // builder: (context, state) {
if(state is EligibilityLoaded){ // if (state is EligibilityLoaded) {
return ListView.builder( // return ListView.builder(
padding: // padding: const EdgeInsets.symmetric(
const EdgeInsets.symmetric(vertical: 8, horizontal: 10), // vertical: 8, horizontal: 10),
itemCount: state.eligibilities.length, // itemCount: state.eligibilities.length,
itemBuilder: (BuildContext context, int index) { // itemBuilder: (BuildContext context, int index) {
String title = // String title =
state.eligibilities[index].eligibility!.title!; // state.eligibilities[index].eligibility!.title!;
return Column( // return Column(
mainAxisAlignment: MainAxisAlignment.start, // mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, // crossAxisAlignment: CrossAxisAlignment.start,
children: [ // children: [
Container( // Container(
width: screenWidth, // width: screenWidth,
padding: const EdgeInsets.symmetric( // padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8), // horizontal: 12, vertical: 8),
decoration: box1(), // decoration: box1(),
child: Row( // child: Row(
children: [ // children: [
Expanded( // Expanded(
child: Column( // child: Column(
mainAxisAlignment: // mainAxisAlignment:
MainAxisAlignment.start, // MainAxisAlignment.start,
crossAxisAlignment: // crossAxisAlignment:
CrossAxisAlignment.start, // CrossAxisAlignment.start,
children: [ // children: [
Text( // Text(
title, // title,
style: Theme.of(context) // style: Theme.of(context)
.textTheme // .textTheme
.titleMedium! // .titleMedium!
.copyWith( // .copyWith(
fontWeight: FontWeight.w500), // fontWeight:
), // FontWeight.w500),
const Divider(), // ),
const SizedBox( // const Divider(),
height: 5, // const SizedBox(
), // height: 5,
Text( // ),
"$licenseNumber: ${state.eligibilities[index].licenseNumber == null ? 'N/A' : state.eligibilities[index].licenseNumber.toString()}", // Text(
style: Theme.of(context) // "$licenseNumber: ${state.eligibilities[index].licenseNumber == null ? 'N/A' : state.eligibilities[index].licenseNumber.toString()}",
.textTheme // style: Theme.of(context)
.titleSmall), // .textTheme
const SizedBox( // .titleSmall),
height: 3, // const SizedBox(
), // height: 3,
Text( // ),
" : ${state.eligibilities[index].rating ?? 'N/A'}.", // Text(
style: Theme.of(context) // " : ${state.eligibilities[index].rating ?? 'N/A'}.",
.textTheme // style: Theme.of(context)
.titleSmall) // .textTheme
]), // .titleSmall)
), // ]),
AppPopupMenu<int>( // ),
offset: const Offset(-10, -10), // ]
elevation: 3, // ),
onSelected: (value) { // ),
// if (value == 1) { // const SizedBox(
// confirmAlert(context, () => null, // height: 5,
// "Delete?", "Confirm Delete?"); // )
// } // ],
// if (value == 2) { // );
// context.read<ProfileBloc>().add( // });
// EditEligibility( // }
// eligibityCert: widget // return Container();
// .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();
},
);
},
));
}
}

View File

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

View File

@ -20,7 +20,8 @@ Widget getTile(
if (title.toLowerCase() == "logout") { if (title.toLowerCase() == "logout") {
confirmAlert(context, () { confirmAlert(context, () {
Navigator.pushReplacementNamed (context,"/"); Navigator.pushReplacementNamed (context,"/");
});
},"Logout","Are You sure you want to logout?");
}if(title.toLowerCase() == 'profile'){ }if(title.toLowerCase() == 'profile'){
ProfileArguments profileArguments = ProfileArguments(token: userData.user!.login!.token!, userID:userData.user!.login!.user!.profileId!); ProfileArguments profileArguments = ProfileArguments(token: userData.user!.login!.token!, userID:userData.user!.login!.user!.profileId!);
Navigator.pushNamed(context, route,arguments: profileArguments); 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/theme-data.dart/colors.dart';
import 'package:unit2/utils/global.dart'; import 'package:unit2/utils/global.dart';
confirmAlert(context, Function() yes) { confirmAlert(context, Function() yes,String title, String subtitle) {
AwesomeDialog( AwesomeDialog(
context: context, context: context,
dialogType: DialogType.question, dialogType: DialogType.question,
@ -26,8 +26,8 @@ confirmAlert(context, Function() yes) {
// }, // },
headerAnimationLoop: false, headerAnimationLoop: false,
animType: AnimType.bottomSlide, animType: AnimType.bottomSlide,
title: 'LOGOUT!', title: title,
desc: 'Are you sure you want to logout?', desc: subtitle,
btnOkText: "Yes", btnOkText: "Yes",
btnCancelText: "No", btnCancelText: "No",
showCloseIcon: false, showCloseIcon: false,