Skip to content

Commit

Permalink
rfac: revamps integration of feedback with backend
Browse files Browse the repository at this point in the history
  • Loading branch information
AmCodesLame committed Apr 3, 2024
1 parent b8e5ed9 commit 61895eb
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 63 deletions.
2 changes: 1 addition & 1 deletion lib/data/services/remote/api_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ abstract class ApiService {
Future<List<FeedbackResponse>> responseOfFeedbacks();

@POST(ApiEndpoints.newFeedback)
Future<AppetizerFeedback> newFeedback(
Future<void> newFeedback(
@Body() Map<String, dynamic> map,
);

Expand Down
14 changes: 3 additions & 11 deletions lib/domain/models/feedback/appetizer_feedback.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@ part 'appetizer_feedback.g.dart';

@JsonSerializable(fieldRename: FieldRename.snake)
class AppetizerFeedback {
int id;
String title;
String message;
int timestamp;
dynamic mealId;
dynamic imageUrl;
int dateIssue;
dynamic response;
List<Map<String, dynamic>> ratings;
// dynamic imageUrl;
int ratings;

AppetizerFeedback({
required this.id,
required this.title,
required this.message,
required this.timestamp,
required this.mealId,
required this.imageUrl,
required this.dateIssue,
required this.response,
// required this.imageUrl,
required this.ratings,
});

Expand Down
7 changes: 3 additions & 4 deletions lib/domain/repositories/feedback_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,16 @@ class FeedbackRepository {
}
}

Future<AppetizerFeedback> newFeedback(AppetizerFeedback feedback) async {
Future<void> newFeedback(AppetizerFeedback feedback) async {
Map<String, dynamic> map = {
'title': feedback.title,
'message': feedback.message,
'date_issue': feedback.dateIssue,
'meal_id': feedback.mealId,
'ratings': feedback.ratings,
'image_url': feedback.imageUrl,
// 'image_url': feedback.imageUrl,
};
try {
return await _apiService.newFeedback(map);
await _apiService.newFeedback(map);
} catch (e) {
debugPrint(e.toString());
throw Failure(AppConstants.GENERIC_FAILURE);
Expand Down
14 changes: 2 additions & 12 deletions lib/presentation/feedback/bloc/feedback_page_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,12 @@ class FeedbackPageBloc extends Bloc<FeedbackPageEvent, FeedbackPageState> {
void _onSubmit(
FeedbackPageSubmitEvent event, Emitter<FeedbackPageState> emit) async {
try {
List<Map<String, dynamic>> ratings = [
{"type": "am", "stars": event.rating[0]},
{"type": "hc", "stars": event.rating[1]},
{"type": "wm", "stars": event.rating[2]},
{"type": "ws", "stars": event.rating[3]},
{"type": "dn", "stars": event.rating[4]}
];
int ratings = event.rating;
AppetizerFeedback feedback = AppetizerFeedback(
id: 0,
title: 'Feedback',
message: event.description,
timestamp: DateTime.now().millisecondsSinceEpoch,
mealId: event.mealId,
imageUrl: null,
dateIssue: DateTime.now().millisecondsSinceEpoch,
response: null,
// imageUrl: null,
ratings: ratings,
);
await repo.newFeedback(feedback);
Expand Down
2 changes: 1 addition & 1 deletion lib/presentation/feedback/bloc/feedback_page_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class FeedbackPageSubmitEvent extends FeedbackPageEvent {
required this.description,
required this.mealId,
});
final List<int> rating;
final int rating;
final String description;
final int mealId;

Expand Down
4 changes: 2 additions & 2 deletions lib/presentation/feedback/bloc/feedback_page_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class FeedbackPageState extends Equatable {
});

FeedbackPageState.initial()
: rating = [0, 0, 0, 0, 0],
: rating = 0,
description = '',
mealId = 0,
submitted = false,
error = false;

List<int> rating;
int rating;
final String description;
final int mealId;
final bool submitted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ class FeedbackTile extends StatelessWidget {
const FeedbackTile({
required this.title,
required this.parentState,
required this.index,
super.key,
});

final String title;
final FeedbackPageState parentState;
final int index;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -44,7 +42,7 @@ class FeedbackTile extends StatelessWidget {
onPressed: () {
context.read<FeedbackTileBloc>().add(
FeedbackRatingChangedEvent(newRating: index + 1));
parentState.rating[this.index] = index + 1;
parentState.rating = index + 1;
},
icon: index < state.rating
? SvgPicture.asset('assets/images/filledStar.svg')
Expand Down
50 changes: 21 additions & 29 deletions lib/presentation/feedback/feedback_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ class FeedbackScreen extends StatelessWidget {
final TextEditingController textController = TextEditingController();
final int mealId;
static const List<String> feedbackHeadings = [
"Ambience",
"Hygiene and Cleanliness",
"Weekly Menu",
"Worker and Services",
"Diet and Nutrition",
"Your Feedback",
];

@override
Expand Down Expand Up @@ -54,17 +50,14 @@ class FeedbackScreen extends StatelessWidget {
),
),
6.toVerticalSizedBox,
...List.generate(feedbackHeadings.length, (ind) {
return Padding(
padding: EdgeInsets.symmetric(
vertical: 2.toAutoScaledHeight),
child: FeedbackTile(
parentState: state,
title: feedbackHeadings[ind],
index: ind,
),
);
}, growable: false),
Padding(
padding: EdgeInsets.symmetric(
vertical: 2.toAutoScaledHeight),
child: FeedbackTile(
parentState: state,
title: "Your Feedback",
),
),
2.toVerticalSizedBox,
Text(
'If any other feeback, please describe below',
Expand Down Expand Up @@ -103,19 +96,18 @@ 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.rating == 0) {
Fluttertoast.showToast(
msg: "Please rate before submitting!",
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!",
Expand Down Expand Up @@ -160,7 +152,7 @@ class FeedbackScreen extends StatelessWidget {
}
if (state.error) {
Fluttertoast.showToast(
msg: "Unable to submit feedback!",
msg: state.description,
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.BOTTOM,
timeInSecForIosWeb: 1,
Expand Down

0 comments on commit 61895eb

Please sign in to comment.