1+ import 'package:appetizer/domain/models/feedback/appetizer_feedback.dart' ;
12import 'package:appetizer/domain/repositories/feedback_repository.dart' ;
23import 'package:bloc/bloc.dart' ;
34import 'package:equatable/equatable.dart' ;
@@ -10,26 +11,57 @@ class FeedbackPageBloc extends Bloc<FeedbackPageEvent, FeedbackPageState> {
1011 FeedbackPageBloc ({
1112 required this .repo,
1213 }) : super (
13- const FeedbackPageState .initial (),
14+ FeedbackPageState .initial (),
1415 ) {
1516 on < FeedbackPageSubmitEvent > (_onSubmit);
1617 on < FeedbackPageDescriptionChangedEvent > (_onDescriptionChange);
1718 }
1819
1920 void _onSubmit (
20- FeedbackPageSubmitEvent event, Emitter <FeedbackPageState > emit) {
21- // TODO: implement repository call
22- bool submissionSuccessful = true ;
23- if (submissionSuccessful) {
21+ FeedbackPageSubmitEvent event, Emitter <FeedbackPageState > emit) async {
22+ try {
23+ List <Map <String , dynamic >> ratings = [
24+ {"type" : "am" , "stars" : event.rating[0 ]},
25+ {"type" : "hc" , "stars" : event.rating[1 ]},
26+ {"type" : "wm" , "stars" : event.rating[2 ]},
27+ {"type" : "ws" , "stars" : event.rating[3 ]},
28+ {"type" : "dn" , "stars" : event.rating[4 ]}
29+ ];
30+ AppetizerFeedback feedback = AppetizerFeedback (
31+ id: 0 ,
32+ title: 'Feedback' ,
33+ message: event.description,
34+ timestamp: DateTime .now ().millisecondsSinceEpoch,
35+ mealId: event.mealId,
36+ imageUrl: null ,
37+ dateIssue: DateTime .now ().millisecondsSinceEpoch,
38+ response: null ,
39+ ratings: ratings,
40+ );
41+ await repo.newFeedback (feedback);
2442 emit (
2543 FeedbackPageState (
2644 rating: event.rating,
2745 description: event.description,
2846 submitted: true ,
2947 error: false ,
48+ mealId: event.mealId,
49+ ),
50+ );
51+ } catch (e) {
52+ emit (
53+ FeedbackPageState (
54+ rating: event.rating,
55+ description: event.description,
56+ submitted: false ,
57+ error: true ,
58+ mealId: event.mealId,
3059 ),
3160 );
3261 }
62+
63+ // bool submissionSuccessful = true;
64+ // if (submissionSuccessful) {}
3365 // else {
3466 // emit(
3567 // FeedbackPageState(
@@ -51,6 +83,7 @@ class FeedbackPageBloc extends Bloc<FeedbackPageEvent, FeedbackPageState> {
5183 description: event.description,
5284 submitted: state.submitted,
5385 error: state.error,
86+ mealId: state.mealId,
5487 ),
5588 );
5689 }
0 commit comments