so i am in a hastle here , in the the presentation layer I want to pass data through the bloc events to the bloc state and finally to a page and I found that I am repeating the same params everywhere , so I though if I can use the entities in the domain or make a new entity that has the things that I need and avoid boilerplate code .
to make it clearer for you I have an entity in the domain layer with multiple field called order
I have an add new order page it is split to two layers a first page and a second page , the first page contains general information about the order , and the second page contains specefic details . when the operation in the first page is successful it uses bloc to emit a transition to the second page with the general information then the second page adds to these general info and initiates the add order use case through the bloc . i hope that was clear enough to understand my issue
this is the code to help you understand more :
Widget build(BuildContext context) {
return BlocConsumer<OrdersBloc, OrdersState>(
listener: (context, state) {
if (state is AddNewOrderMoveToSecondPagePermitted) {
Navigator.of(context).pushReplacement(PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) {
return AddNewOrderMapPage(
state.issuerId, state.orderDescription ... etc);
},
transitionsBuilder:
(context, animation, secondaryAnimation, child) {
return FadeTransition(
opacity: animation,
child: child,
);
},
transitionDuration: const Duration(milliseconds: 600)));
}
if (state is OrderUploaded) {
showSnackBar(context, "success", SnackBarType.success);
} else if (state is OrderFailure) {
showSnackBar(
context, "something wrong happened", SnackBarType.failure);
}
},
builder: (context, state) {
return const AddNewOrderFirstPage();
},
);
}
void _onAddNewOrderSecondPageRequested() {
on<AddNewOrderMoveToSecondPage>(
(event, emit) {
emit(AddNewOrderMoveToSecondPagePermitted(
orderType: event.orderType,
orderTitle: event.orderTitle,
orderImages: event.orderImages,
orderId: event.orderId,
offerPrice: event.offerPrice,
orderDescription: event.orderDescription,
issuerId: event.issuerId));
},
);
}
the event and state share the same parameters which are these
orderType: event.orderType,
orderTitle: event.orderTitle,
orderImages: event.orderImages,
orderId: event.orderId,
offerPrice: event.offerPrice,
orderDescription: event.orderDescription,
issuerId: event.issuerId
please guide me because I am new to clean architecture . thank you
I would recommend using new entity you can called it CreateOrderEntity and put all your properties together there , there is a lot of details about the entity and page I don't know about ,
class CreateOrderEntity{
double price = 0;
string orderType = "";
string orderTitle = "";
//etc
}
you will now pass one object then use it across your two pages or the way you need to fill the entity , I hope you found what was your looking for, also let me know if you need further information