contact refactor and created its own bloc
parent
367402b288
commit
5bea76102c
|
@ -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()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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 => [];
|
||||
}
|
|
@ -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];
|
||||
}
|
|
@ -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()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
|
@ -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];
|
||||
}
|
|
@ -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{
|
||||
|
||||
}
|
|
@ -1,5 +1,10 @@
|
|||
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/colors.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';
|
||||
|
||||
class ContactInformationScreen extends StatelessWidget {
|
||||
final List<ContactInfo> contacts;
|
||||
const ContactInformationScreen({super.key, required this.contacts});
|
||||
const ContactInformationScreen({
|
||||
super.key,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -20,60 +26,164 @@ class ContactInformationScreen extends StatelessWidget {
|
|||
backgroundColor: primary,
|
||||
actions: [AddLeading(onPressed: () {})],
|
||||
),
|
||||
body: contacts.isNotEmpty? ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8,horizontal: 10),
|
||||
itemCount: contacts.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
String numberMail = contacts[index].numbermail!;
|
||||
String commService = contacts[index].commService!.serviceProvider!.alias!;
|
||||
body: ProgressHUD(
|
||||
padding: const EdgeInsets.all(24),
|
||||
backgroundColor: Colors.black87,
|
||||
indicatorWidget: const SpinKitFadingCircle(color: Colors.white),
|
||||
child: BlocBuilder<UserBloc, UserState>(
|
||||
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(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
decoration: box1(),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12,vertical: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment
|
||||
.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment
|
||||
.start,
|
||||
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 SizedBox(height: 5,),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(commService
|
||||
.toString(),style: Theme.of(context).textTheme.titleSmall,),
|
||||
child: Text(
|
||||
commService
|
||||
.toString(),
|
||||
style: Theme.of(
|
||||
context)
|
||||
.textTheme
|
||||
.titleSmall,
|
||||
),
|
||||
|
||||
contacts[index].active==true? const Badge(backgroundColor: Colors.green, label: Text("Active",),):const SizedBox(),
|
||||
const SizedBox(width: 5),
|
||||
contacts[index].primary==true? const Badge(backgroundColor: Colors.blue, label: Text("Primary"),):const SizedBox()
|
||||
),
|
||||
state.contactInformation[index]
|
||||
.active ==
|
||||
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,),
|
||||
Text(contacts[index].commService!
|
||||
.serviceProvider!.agency!.name
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Text(state
|
||||
.contactInformation[
|
||||
index]
|
||||
.commService!
|
||||
.serviceProvider!
|
||||
.agency!
|
||||
.name
|
||||
.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();
|
||||
},
|
||||
),
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
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/theme-data.dart/box_shadow.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/empty_data.dart';
|
||||
|
||||
import '../../../../bloc/user/user_bloc.dart';
|
||||
|
||||
class IdentificationsScreen extends StatelessWidget {
|
||||
final List<Identification> identities;
|
||||
const IdentificationsScreen({super.key, required this.identities});
|
||||
const IdentificationsScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
@ -20,54 +24,101 @@ class IdentificationsScreen extends StatelessWidget {
|
|||
backgroundColor: primary,
|
||||
actions: [AddLeading(onPressed: () {})],
|
||||
),
|
||||
body:identities.isNotEmpty? ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 10),
|
||||
itemCount: identities.length,
|
||||
body: BlocBuilder<UserBloc, UserState>(
|
||||
builder: (context, state) {
|
||||
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) {
|
||||
String agency = identities[index].agency!.name!;
|
||||
String idNumber = identities[index].identificationNumber!;
|
||||
bool government = identities[index].agency!.privateEntity!;
|
||||
String issuedAt = "${identities[index].issuedAt!.cityMunicipality!.description!} ${identities[index].issuedAt!.cityMunicipality!.province!.description}";
|
||||
String agency =
|
||||
state.identificationInformation[index].agency!.name!;
|
||||
String idNumber =
|
||||
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(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: screenWidth,
|
||||
decoration: box1(),
|
||||
padding:
|
||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.start,
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
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 SizedBox(height: 5,),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Row(children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
"$idNumberText : $idNumber",style: Theme.of(context).textTheme.titleSmall,
|
||||
"$idNumberText : $idNumber",
|
||||
style:
|
||||
Theme.of(context)
|
||||
.textTheme
|
||||
.titleSmall,
|
||||
),
|
||||
),
|
||||
|
||||
Badge(
|
||||
|
||||
backgroundColor: success2,
|
||||
backgroundColor:
|
||||
success2,
|
||||
label: Text(
|
||||
government ==
|
||||
true
|
||||
? privateText.toUpperCase()
|
||||
:governmentText.toUpperCase(),
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(color: Colors.white),)),
|
||||
const SizedBox(height: 5,),
|
||||
government == true
|
||||
? privateText
|
||||
.toUpperCase()
|
||||
: governmentText
|
||||
.toUpperCase(),
|
||||
style: Theme.of(
|
||||
context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
color: Colors
|
||||
.white),
|
||||
))
|
||||
]),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
Text(issuedAt),
|
||||
]),
|
||||
),
|
||||
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();
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,8 @@ import 'package:fluttericon/entypo_icons.dart';
|
|||
import 'package:fluttericon/font_awesome5_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/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/screens/profile/components/basic_information/address_screen.dart';
|
||||
import 'package:unit2/screens/profile/components/basic_information/citizenship_screen.dart';
|
||||
|
@ -122,28 +124,36 @@ class _ProfileInfoState extends State<ProfileInfo> {
|
|||
return BlocProvider(
|
||||
create: (context) => AddressBloc()
|
||||
..add(GetAddress(
|
||||
addresses: state.profileInformation.basicInfo.addresses)),
|
||||
addresses: state.profileInformation
|
||||
.basicInfo.addresses)),
|
||||
child: const AddressScreen(),
|
||||
);
|
||||
}));
|
||||
|
||||
}),
|
||||
subMenu(Icons.contact_mail, "Identifications",
|
||||
() {
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return IdentificationsScreen(
|
||||
identities: state.profileInformation
|
||||
.basicInfo.identifications);
|
||||
return BlocProvider(
|
||||
create: (context) => IdentificationBloc()
|
||||
..add(GetIdentifications(
|
||||
identificationInformation: state
|
||||
.profileInformation
|
||||
.basicInfo
|
||||
.identifications)),
|
||||
child: const IdentificationsScreen(),
|
||||
);
|
||||
}));
|
||||
}),
|
||||
subMenu(Icons.contact_phone, "Contact Info",
|
||||
() {
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return ContactInformationScreen(
|
||||
contacts: state.profileInformation
|
||||
.basicInfo.contactInformation,
|
||||
return BlocProvider(
|
||||
create: (context) => ContactBloc()
|
||||
..add(GetContacts(
|
||||
contactInformations: state.profileInformation.basicInfo.contactInformation)),
|
||||
child: ContactInformationScreen(),
|
||||
);
|
||||
}));
|
||||
}),
|
||||
|
@ -303,7 +313,8 @@ class _ProfileInfoState extends State<ProfileInfo> {
|
|||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => OrganizationMembershipBloc()
|
||||
create: (context) =>
|
||||
OrganizationMembershipBloc()
|
||||
..add(GetOrganizationMembership(
|
||||
profileId: profileId!,
|
||||
token: token!)),
|
||||
|
@ -313,15 +324,16 @@ class _ProfileInfoState extends State<ProfileInfo> {
|
|||
}),
|
||||
subMenu(Entypo.doc_text,
|
||||
"Non-Academic Recognitions", () {
|
||||
|
||||
Navigator.push(context, MaterialPageRoute(
|
||||
builder: (BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => NonAcademicRecognitionBloc()
|
||||
create: (context) =>
|
||||
NonAcademicRecognitionBloc()
|
||||
..add(GetNonAcademicRecognition(
|
||||
profileId: profileId!,
|
||||
token: token!)),
|
||||
child: const NonAcademicRecognitionScreen(),
|
||||
child:
|
||||
const NonAcademicRecognitionScreen(),
|
||||
);
|
||||
}));
|
||||
}),
|
||||
|
|
Loading…
Reference in New Issue