From b8e5ed9fd2bd4ff930c8fa883045131220e676bb Mon Sep 17 00:00:00 2001 From: Aayushmaan Date: Thu, 29 Feb 2024 23:31:33 +0530 Subject: [PATCH] feat: makes all form fields required for submission --- lib/presentation/feedback/feedback_view.dart | 70 ++++++++++++++------ 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/lib/presentation/feedback/feedback_view.dart b/lib/presentation/feedback/feedback_view.dart index ee8ff910..5cea3e47 100644 --- a/lib/presentation/feedback/feedback_view.dart +++ b/lib/presentation/feedback/feedback_view.dart @@ -31,29 +31,8 @@ class FeedbackScreen extends StatelessWidget { body: BlocProvider( create: (context) => FeedbackPageBloc(repo: context.read()), - child: BlocBuilder( + child: BlocConsumer( builder: (context, state) { - if (state.error) { - Fluttertoast.showToast( - msg: "Unable to submit feedback!", - toastLength: Toast.LENGTH_SHORT, - gravity: ToastGravity.BOTTOM, - timeInSecForIosWeb: 1, - textColor: Colors.white, - backgroundColor: AppTheme.red, - fontSize: 16.0); - } - if (state.submitted) { - Fluttertoast.showToast( - msg: "Feedback submitted successfully!", - toastLength: Toast.LENGTH_SHORT, - gravity: ToastGravity.BOTTOM, - timeInSecForIosWeb: 1, - textColor: Colors.white, - backgroundColor: AppTheme.green, - fontSize: 12.toAutoScaledFont); - context.router.pop(); - } return Column( children: [ const FeedbackBanner(), @@ -124,6 +103,30 @@ class FeedbackScreen extends StatelessWidget { alignment: Alignment.bottomRight, child: BlackIconButton( onTap: () { + for (var rating in state.rating) { + if (rating == 0) { + Fluttertoast.showToast( + msg: "Please rate all the categories!", + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + textColor: Colors.white, + backgroundColor: AppTheme.red, + fontSize: 12.toAutoScaledFont); + return; + } + } + if (state.description.trim().isEmpty) { + Fluttertoast.showToast( + msg: "Please describe your Feedback!", + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + textColor: Colors.white, + backgroundColor: AppTheme.red, + fontSize: 12.toAutoScaledFont); + return; + } context.read().add( FeedbackPageSubmitEvent( mealId: mealId, @@ -143,6 +146,29 @@ class FeedbackScreen extends StatelessWidget { ], ); }, + listener: (BuildContext context, FeedbackPageState state) { + if (state.submitted) { + Fluttertoast.showToast( + msg: "Feedback submitted successfully!", + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + textColor: Colors.white, + backgroundColor: AppTheme.green, + fontSize: 12.toAutoScaledFont); + context.router.pop(); + } + if (state.error) { + Fluttertoast.showToast( + msg: "Unable to submit feedback!", + toastLength: Toast.LENGTH_SHORT, + gravity: ToastGravity.BOTTOM, + timeInSecForIosWeb: 1, + textColor: Colors.white, + backgroundColor: AppTheme.red, + fontSize: 16.0); + } + }, ), ), );