contact refactor and created its own bloc

feature/passo/PASSO-#1-Sync-data-from-device-to-postgre-and-vice-versa
PGAN-MIS 2023-03-07 15:01:56 +08:00
parent 367402b288
commit 5bea76102c
9 changed files with 480 additions and 162 deletions

View File

@ -0,0 +1,22 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import '../../../../model/profile/basic_information/contact_information.dart';
part 'contact_event.dart';
part 'contact_state.dart';
class ContactBloc extends Bloc<ContactEvent, ContactState> {
ContactBloc() : super(ContactInitial()) {
List<ContactInfo> contactInformations = [];
on<GetContacts>((event, emit) {
emit(ContactLoadingState());
try {
contactInformations = event.contactInformations;
emit(ContactLoadedState(contactInformation: contactInformations));
} catch (e) {
emit(ContactErrorState(message: e.toString()));
}
});
}
}

View File

@ -0,0 +1,16 @@
part of 'contact_bloc.dart';
abstract class ContactEvent extends Equatable {
const ContactEvent();
@override
List<Object> get props => [];
}
class GetContacts extends ContactEvent{
final List<ContactInfo> contactInformations;
const GetContacts({required this.contactInformations});
@override
List<Object> get props => [];
}

View File

@ -0,0 +1,27 @@
part of 'contact_bloc.dart';
abstract class ContactState extends Equatable {
const ContactState();
@override
List<Object> get props => [];
}
class ContactInitial extends ContactState {}
class ContactLoadedState extends ContactState{
final List<ContactInfo> contactInformation;
const ContactLoadedState({required this.contactInformation});
@override
List<Object> get props => [];
}
class ContactLoadingState extends ContactState{
}
class ContactErrorState extends ContactState{
final String message;
const ContactErrorState({required this.message});
@override
List<Object> get props => [message];
}

View File

@ -0,0 +1,21 @@
import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import '../../../../model/profile/basic_information/identification_information.dart';
part 'identification_event.dart';
part 'identification_state.dart';
class IdentificationBloc extends Bloc<IdentificationEvent, IdentificationState> {
IdentificationBloc() : super(IdentificationInitial()) {
List<Identification> identificationInformations = [];
on<GetIdentifications>((event, emit) {
try{
identificationInformations = event.identificationInformation;
emit(IdentificationLoadedState(identificationInformation: identificationInformations));
}catch(e){
emit(IdenficationErrorState(message: e.toString()));
}
});
}
}

View File

@ -0,0 +1,15 @@
part of 'identification_bloc.dart';
abstract class IdentificationEvent extends Equatable {
const IdentificationEvent();
@override
List<Object> get props => [];
}
class GetIdentifications extends IdentificationEvent{
final List<Identification> identificationInformation;
const GetIdentifications({required this.identificationInformation});
@override
List<Object> get props => [identificationInformation];
}

View File

@ -0,0 +1,28 @@
part of 'identification_bloc.dart';
abstract class IdentificationState extends Equatable {
const IdentificationState();
@override
List<Object> get props => [];
}
class IdentificationInitial extends IdentificationState {}
class IdentificationLoadedState extends IdentificationState{
final List<Identification> identificationInformation;
const IdentificationLoadedState({required this.identificationInformation});
@override
List<Object> get props => [identificationInformation];
}
class IdenficationErrorState extends IdentificationState{
final String message;
const IdenficationErrorState({required this.message});
@override
List<Object> get props => [message];
}
class IdentificationLoadingState extends IdentificationState{
}

View File

@ -1,5 +1,10 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:unit2/model/profile/basic_information/contact_information.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/profile/primary_information/contact/contact_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/bloc/user/user_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';
@ -7,8 +12,9 @@ import 'package:unit2/widgets/Leadings/add_leading.dart';
import 'package:unit2/widgets/empty_data.dart'; import 'package:unit2/widgets/empty_data.dart';
class ContactInformationScreen extends StatelessWidget { class ContactInformationScreen extends StatelessWidget {
final List<ContactInfo> contacts; const ContactInformationScreen({
const ContactInformationScreen({super.key, required this.contacts}); super.key,
});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -18,62 +24,166 @@ class ContactInformationScreen extends StatelessWidget {
title: const Text(contactScreenTitle), title: const Text(contactScreenTitle),
centerTitle: true, centerTitle: true,
backgroundColor: primary, backgroundColor: primary,
actions: [AddLeading(onPressed: (){})], actions: [AddLeading(onPressed: () {})],
), ),
body: contacts.isNotEmpty? ListView.builder( body: ProgressHUD(
padding: const EdgeInsets.symmetric(vertical: 8,horizontal: 10), padding: const EdgeInsets.all(24),
itemCount: contacts.length, backgroundColor: Colors.black87,
itemBuilder: (BuildContext context, int index) { indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
String numberMail = contacts[index].numbermail!; child: BlocBuilder<UserBloc, UserState>(
String commService = contacts[index].commService!.serviceProvider!.alias!; builder: (context, state) {
if (state is UserLoggedIn) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocConsumer<ContactBloc, ContactState>(
listener: (context, state) {
if (state is ContactLoadingState) {
final progress = ProgressHUD.of(context);
progress!.showWithText("Please wait...");
}
if (state is ContactLoadedState ||
state is ContactErrorState) {
final progress = ProgressHUD.of(context);
progress!.dismiss();
}
},
builder: (context, state) {
if (state is ContactLoadedState) {
if (state.contactInformation.isNotEmpty) {
return ListView.builder(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 10),
itemCount: state.contactInformation.length,
itemBuilder:
(BuildContext context, int index) {
String numberMail = state
.contactInformation[index]
.numbermail!;
String commService = state
.contactInformation[index]
.commService!
.serviceProvider!
.alias!;
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment:
crossAxisAlignment: CrossAxisAlignment.start, MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [ children: [
Container( Container(
decoration: box1(), decoration: box1(),
padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8), padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 8),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment:
crossAxisAlignment: CrossAxisAlignment.start, MainAxisAlignment
.start,
crossAxisAlignment:
CrossAxisAlignment
.start,
children: [ children: [
Text(numberMail,style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w500)), Text(numberMail,
style: Theme.of(
context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight
.w500)),
const Divider(), const Divider(),
const SizedBox(height: 5,), const SizedBox(
height: 5,
),
Row( Row(
children: [ children: [
Expanded( Expanded(
child: Text(commService child: Text(
.toString(),style: Theme.of(context).textTheme.titleSmall,), commService
.toString(),
style: Theme.of(
context)
.textTheme
.titleSmall,
), ),
),
contacts[index].active==true? const Badge(backgroundColor: Colors.green, label: Text("Active",),):const SizedBox(), state.contactInformation[index]
const SizedBox(width: 5), .active ==
contacts[index].primary==true? const Badge(backgroundColor: Colors.blue, label: Text("Primary"),):const SizedBox() true
? const Badge(
backgroundColor:
Colors
.green,
label: Text(
"Active",
),
)
: const SizedBox(),
const SizedBox(
width: 5),
state.contactInformation[index]
.primary ==
true
? const Badge(
backgroundColor:
Colors
.blue,
label: Text(
"Primary"),
)
: const SizedBox()
], ],
), ),
const SizedBox(height: 5,), const SizedBox(
Text(contacts[index].commService! height: 5,
.serviceProvider!.agency!.name ),
Text(state
.contactInformation[
index]
.commService!
.serviceProvider!
.agency!
.name
.toString()), .toString()),
]), ]),
), ),
IconButton(onPressed: (){}, icon: const Icon(Icons.more_vert,color: Colors.grey,)) IconButton(
onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
], ],
), ),
), ),
const SizedBox(height: 5,), const SizedBox(
height: 5,
),
], ],
); );
}):const EmptyData(message: "You don't have contact information added. Please click + to add"), });
} else {
const EmptyData(
message:
"You don't have contact information added. Please click + to add");
}
}
return Container();
},
);
}
return Container();
},
);
}
return Container();
},
), ),
)),
); );
} }
} }

View File

@ -1,4 +1,7 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:unit2/bloc/profile/primary_information/identification/identification_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/model/profile/basic_information/identification_information.dart'; import 'package:unit2/model/profile/basic_information/identification_information.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';
@ -7,9 +10,10 @@ 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 '../../../../bloc/user/user_bloc.dart';
class IdentificationsScreen extends StatelessWidget { class IdentificationsScreen extends StatelessWidget {
final List<Identification> identities; const IdentificationsScreen({super.key});
const IdentificationsScreen({super.key, required this.identities});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -18,56 +22,103 @@ class IdentificationsScreen extends StatelessWidget {
title: const Text(identificationScreenTitle), title: const Text(identificationScreenTitle),
centerTitle: true, centerTitle: true,
backgroundColor: primary, backgroundColor: primary,
actions: [AddLeading(onPressed: (){})], actions: [AddLeading(onPressed: () {})],
), ),
body:identities.isNotEmpty? ListView.builder( body: BlocBuilder<UserBloc, UserState>(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10), builder: (context, state) {
itemCount: identities.length, if (state is UserLoggedIn) {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (context, state) {
if (state is ProfileLoaded) {
return BlocConsumer<IdentificationBloc,
IdentificationState>(
listener: (context, state) {},
builder: (context, state) {
if (state is IdentificationLoadedState) {
if (state.identificationInformation.isNotEmpty) {
return ListView.builder(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 10),
itemCount: state.identificationInformation.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
String agency = identities[index].agency!.name!; String agency =
String idNumber = identities[index].identificationNumber!; state.identificationInformation[index].agency!.name!;
bool government = identities[index].agency!.privateEntity!; String idNumber =
String issuedAt = "${identities[index].issuedAt!.cityMunicipality!.description!} ${identities[index].issuedAt!.cityMunicipality!.province!.description}"; state.identificationInformation[index].identificationNumber!;
bool government =
state.identificationInformation[index].agency!.privateEntity!;
String issuedAt =
"${state.identificationInformation[index].issuedAt!.cityMunicipality!.description!} ${state.identificationInformation[index].issuedAt!.cityMunicipality!.province!.description}";
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment:
CrossAxisAlignment.start,
children: [ children: [
Container( Container(
width: screenWidth,
decoration: box1(), decoration: box1(),
padding: padding: const EdgeInsets.symmetric(
const EdgeInsets.symmetric(horizontal: 12, vertical: 8), horizontal: 12, vertical: 8),
child: Row( child: Row(
children: [ children: [
Expanded( Expanded(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment:
crossAxisAlignment: CrossAxisAlignment.start, MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [ children: [
Expanded(child: Text(agency,style: Theme.of(context).textTheme.titleMedium!.copyWith(fontWeight: FontWeight.w400))), Text(agency,
style: Theme.of(context)
.textTheme
.titleMedium!
.copyWith(
fontWeight:
FontWeight
.w400)),
const Divider(), const Divider(),
const SizedBox(height: 5,), const SizedBox(
height: 5,
),
Row(children: [
Expanded( Expanded(
child: Text( child: Text(
"$idNumberText : $idNumber",style: Theme.of(context).textTheme.titleSmall, "$idNumberText : $idNumber",
style:
Theme.of(context)
.textTheme
.titleSmall,
), ),
), ),
Badge( Badge(
backgroundColor:
backgroundColor: success2, success2,
label: Text( label: Text(
government == government == true
true ? privateText
? privateText.toUpperCase() .toUpperCase()
:governmentText.toUpperCase(), : governmentText
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.white),)), .toUpperCase(),
const SizedBox(height: 5,), style: Theme.of(
context)
.textTheme
.bodySmall!
.copyWith(
color: Colors
.white),
))
]),
const SizedBox(
height: 5,
),
Text(issuedAt), Text(issuedAt),
]), ]),
), ),
IconButton( IconButton(
onPressed: () {}, icon: const Icon(Icons.more_vert,color: Colors.grey,)) onPressed: () {},
icon: const Icon(
Icons.more_vert,
color: Colors.grey,
))
], ],
), ),
), ),
@ -76,7 +127,23 @@ class IdentificationsScreen extends StatelessWidget {
), ),
], ],
); );
}):const EmptyData(message: "You don't have identifications added. Please click + to add."), });
} else {
const EmptyData(
message:
"You don't have identifications added. Please click + to add.");
}
}
return Container();
},
); );
} }
return Container();
},
);
}
return Container();
},
));
}
} }

View File

@ -9,6 +9,8 @@ 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/profile/primary_information/address/address_bloc.dart'; import 'package:unit2/bloc/profile/primary_information/address/address_bloc.dart';
import 'package:unit2/bloc/profile/primary_information/contact/contact_bloc.dart';
import 'package:unit2/bloc/profile/primary_information/identification/identification_bloc.dart';
import 'package:unit2/bloc/profile/profile_bloc.dart'; import 'package:unit2/bloc/profile/profile_bloc.dart';
import 'package:unit2/screens/profile/components/basic_information/address_screen.dart'; import 'package:unit2/screens/profile/components/basic_information/address_screen.dart';
import 'package:unit2/screens/profile/components/basic_information/citizenship_screen.dart'; import 'package:unit2/screens/profile/components/basic_information/citizenship_screen.dart';
@ -122,28 +124,36 @@ class _ProfileInfoState extends State<ProfileInfo> {
return BlocProvider( return BlocProvider(
create: (context) => AddressBloc() create: (context) => AddressBloc()
..add(GetAddress( ..add(GetAddress(
addresses: state.profileInformation.basicInfo.addresses)), addresses: state.profileInformation
.basicInfo.addresses)),
child: const AddressScreen(), child: const AddressScreen(),
); );
})); }));
}), }),
subMenu(Icons.contact_mail, "Identifications", subMenu(Icons.contact_mail, "Identifications",
() { () {
Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
return IdentificationsScreen( return BlocProvider(
identities: state.profileInformation create: (context) => IdentificationBloc()
.basicInfo.identifications); ..add(GetIdentifications(
identificationInformation: state
.profileInformation
.basicInfo
.identifications)),
child: const IdentificationsScreen(),
);
})); }));
}), }),
subMenu(Icons.contact_phone, "Contact Info", subMenu(Icons.contact_phone, "Contact Info",
() { () {
Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
return ContactInformationScreen( return BlocProvider(
contacts: state.profileInformation create: (context) => ContactBloc()
.basicInfo.contactInformation, ..add(GetContacts(
contactInformations: state.profileInformation.basicInfo.contactInformation)),
child: ContactInformationScreen(),
); );
})); }));
}), }),
@ -303,7 +313,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
return BlocProvider( return BlocProvider(
create: (context) => OrganizationMembershipBloc() create: (context) =>
OrganizationMembershipBloc()
..add(GetOrganizationMembership( ..add(GetOrganizationMembership(
profileId: profileId!, profileId: profileId!,
token: token!)), token: token!)),
@ -313,15 +324,16 @@ class _ProfileInfoState extends State<ProfileInfo> {
}), }),
subMenu(Entypo.doc_text, subMenu(Entypo.doc_text,
"Non-Academic Recognitions", () { "Non-Academic Recognitions", () {
Navigator.push(context, MaterialPageRoute( Navigator.push(context, MaterialPageRoute(
builder: (BuildContext context) { builder: (BuildContext context) {
return BlocProvider( return BlocProvider(
create: (context) => NonAcademicRecognitionBloc() create: (context) =>
NonAcademicRecognitionBloc()
..add(GetNonAcademicRecognition( ..add(GetNonAcademicRecognition(
profileId: profileId!, profileId: profileId!,
token: token!)), token: token!)),
child: const NonAcademicRecognitionScreen(), child:
const NonAcademicRecognitionScreen(),
); );
})); }));
}), }),