Skip to content

Commit b8e5ed9

Browse files
committed
feat: makes all form fields required for submission
1 parent 139347d commit b8e5ed9

File tree

1 file changed

+48
-22
lines changed

1 file changed

+48
-22
lines changed

lib/presentation/feedback/feedback_view.dart

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,8 @@ class FeedbackScreen extends StatelessWidget {
3131
body: BlocProvider(
3232
create: (context) =>
3333
FeedbackPageBloc(repo: context.read<FeedbackRepository>()),
34-
child: BlocBuilder<FeedbackPageBloc, FeedbackPageState>(
34+
child: BlocConsumer<FeedbackPageBloc, FeedbackPageState>(
3535
builder: (context, state) {
36-
if (state.error) {
37-
Fluttertoast.showToast(
38-
msg: "Unable to submit feedback!",
39-
toastLength: Toast.LENGTH_SHORT,
40-
gravity: ToastGravity.BOTTOM,
41-
timeInSecForIosWeb: 1,
42-
textColor: Colors.white,
43-
backgroundColor: AppTheme.red,
44-
fontSize: 16.0);
45-
}
46-
if (state.submitted) {
47-
Fluttertoast.showToast(
48-
msg: "Feedback submitted successfully!",
49-
toastLength: Toast.LENGTH_SHORT,
50-
gravity: ToastGravity.BOTTOM,
51-
timeInSecForIosWeb: 1,
52-
textColor: Colors.white,
53-
backgroundColor: AppTheme.green,
54-
fontSize: 12.toAutoScaledFont);
55-
context.router.pop();
56-
}
5736
return Column(
5837
children: [
5938
const FeedbackBanner(),
@@ -124,6 +103,30 @@ class FeedbackScreen extends StatelessWidget {
124103
alignment: Alignment.bottomRight,
125104
child: BlackIconButton(
126105
onTap: () {
106+
for (var rating in state.rating) {
107+
if (rating == 0) {
108+
Fluttertoast.showToast(
109+
msg: "Please rate all the categories!",
110+
toastLength: Toast.LENGTH_SHORT,
111+
gravity: ToastGravity.BOTTOM,
112+
timeInSecForIosWeb: 1,
113+
textColor: Colors.white,
114+
backgroundColor: AppTheme.red,
115+
fontSize: 12.toAutoScaledFont);
116+
return;
117+
}
118+
}
119+
if (state.description.trim().isEmpty) {
120+
Fluttertoast.showToast(
121+
msg: "Please describe your Feedback!",
122+
toastLength: Toast.LENGTH_SHORT,
123+
gravity: ToastGravity.BOTTOM,
124+
timeInSecForIosWeb: 1,
125+
textColor: Colors.white,
126+
backgroundColor: AppTheme.red,
127+
fontSize: 12.toAutoScaledFont);
128+
return;
129+
}
127130
context.read<FeedbackPageBloc>().add(
128131
FeedbackPageSubmitEvent(
129132
mealId: mealId,
@@ -143,6 +146,29 @@ class FeedbackScreen extends StatelessWidget {
143146
],
144147
);
145148
},
149+
listener: (BuildContext context, FeedbackPageState state) {
150+
if (state.submitted) {
151+
Fluttertoast.showToast(
152+
msg: "Feedback submitted successfully!",
153+
toastLength: Toast.LENGTH_SHORT,
154+
gravity: ToastGravity.BOTTOM,
155+
timeInSecForIosWeb: 1,
156+
textColor: Colors.white,
157+
backgroundColor: AppTheme.green,
158+
fontSize: 12.toAutoScaledFont);
159+
context.router.pop();
160+
}
161+
if (state.error) {
162+
Fluttertoast.showToast(
163+
msg: "Unable to submit feedback!",
164+
toastLength: Toast.LENGTH_SHORT,
165+
gravity: ToastGravity.BOTTOM,
166+
timeInSecForIosWeb: 1,
167+
textColor: Colors.white,
168+
backgroundColor: AppTheme.red,
169+
fontSize: 16.0);
170+
}
171+
},
146172
),
147173
),
148174
);

0 commit comments

Comments
 (0)