@@ -9,17 +9,15 @@ import 'package:appetizer/presentation/feedback/components/feedback_banner.dart'
99import 'package:auto_route/auto_route.dart' ;
1010import 'package:flutter/material.dart' ;
1111import 'package:flutter_bloc/flutter_bloc.dart' ;
12+ import 'package:fluttertoast/fluttertoast.dart' ;
1213
1314@RoutePage ()
1415class FeedbackScreen extends StatelessWidget {
15- FeedbackScreen ({super .key});
16+ FeedbackScreen ({required this .mealId, super .key});
1617 final TextEditingController textController = TextEditingController ();
18+ final int mealId;
1719 static const List <String > feedbackHeadings = [
18- "Ambience" ,
19- "Hygiene and Cleanliness" ,
20- "Weekly Menu" ,
21- "Worker and Services" ,
22- "Diet and Nutrition" ,
20+ "Your Feedback" ,
2321 ];
2422
2523 @override
@@ -29,7 +27,7 @@ class FeedbackScreen extends StatelessWidget {
2927 body: BlocProvider (
3028 create: (context) =>
3129 FeedbackPageBloc (repo: context.read <FeedbackRepository >()),
32- child: BlocBuilder <FeedbackPageBloc , FeedbackPageState >(
30+ child: BlocConsumer <FeedbackPageBloc , FeedbackPageState >(
3331 builder: (context, state) {
3432 return Column (
3533 children: [
@@ -52,17 +50,14 @@ class FeedbackScreen extends StatelessWidget {
5250 ),
5351 ),
5452 6. toVerticalSizedBox,
55- ...List .generate (feedbackHeadings.length, (ind) {
56- return Padding (
57- padding: EdgeInsets .symmetric (
58- vertical: 2. toAutoScaledHeight),
59- child: FeedbackTile (
60- parentState: state,
61- title: feedbackHeadings[ind],
62- index: ind,
63- ),
64- );
65- }, growable: false ),
53+ Padding (
54+ padding: EdgeInsets .symmetric (
55+ vertical: 2. toAutoScaledHeight),
56+ child: FeedbackTile (
57+ parentState: state,
58+ title: "Your Feedback" ,
59+ ),
60+ ),
6661 2. toVerticalSizedBox,
6762 Text (
6863 'If any other feeback, please describe below' ,
@@ -100,11 +95,36 @@ class FeedbackScreen extends StatelessWidget {
10095 Align (
10196 alignment: Alignment .bottomRight,
10297 child: BlackIconButton (
103- onTap: context.router.pop,
104- // onTap: () => context.read<FeedbackPageBloc>().add(
105- // FeedbackPageSubmitEvent(
106- // rating: state.rating,
107- // description: state.description)),
98+ onTap: () {
99+ if (state.rating == 0 ) {
100+ Fluttertoast .showToast (
101+ msg: "Please rate before submitting!" ,
102+ toastLength: Toast .LENGTH_SHORT ,
103+ gravity: ToastGravity .BOTTOM ,
104+ timeInSecForIosWeb: 1 ,
105+ textColor: Colors .white,
106+ backgroundColor: AppTheme .red,
107+ fontSize: 12. toAutoScaledFont);
108+ return ;
109+ }
110+
111+ if (state.description.trim ().isEmpty) {
112+ Fluttertoast .showToast (
113+ msg: "Please describe your Feedback!" ,
114+ toastLength: Toast .LENGTH_SHORT ,
115+ gravity: ToastGravity .BOTTOM ,
116+ timeInSecForIosWeb: 1 ,
117+ textColor: Colors .white,
118+ backgroundColor: AppTheme .red,
119+ fontSize: 12. toAutoScaledFont);
120+ return ;
121+ }
122+ context.read <FeedbackPageBloc >().add (
123+ FeedbackPageSubmitEvent (
124+ mealId: mealId,
125+ rating: state.rating,
126+ description: state.description));
127+ },
108128 title: "SUBMIT" ,
109129 width: 102. toAutoScaledWidth,
110130 icon: Icons .keyboard_double_arrow_right_sharp,
@@ -118,6 +138,29 @@ class FeedbackScreen extends StatelessWidget {
118138 ],
119139 );
120140 },
141+ listener: (BuildContext context, FeedbackPageState state) {
142+ if (state.submitted) {
143+ Fluttertoast .showToast (
144+ msg: "Feedback submitted successfully!" ,
145+ toastLength: Toast .LENGTH_SHORT ,
146+ gravity: ToastGravity .BOTTOM ,
147+ timeInSecForIosWeb: 1 ,
148+ textColor: Colors .white,
149+ backgroundColor: AppTheme .green,
150+ fontSize: 12. toAutoScaledFont);
151+ context.router.pop ();
152+ }
153+ if (state.error) {
154+ Fluttertoast .showToast (
155+ msg: state.description,
156+ toastLength: Toast .LENGTH_SHORT ,
157+ gravity: ToastGravity .BOTTOM ,
158+ timeInSecForIosWeb: 1 ,
159+ textColor: Colors .white,
160+ backgroundColor: AppTheme .red,
161+ fontSize: 16.0 );
162+ }
163+ },
121164 ),
122165 ),
123166 );
0 commit comments