-
Notifications
You must be signed in to change notification settings - Fork 0
Restaurants rating #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📝 WalkthroughWalkthroughThe pull request introduces a new Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (3)
lib/features/home/presentation/screens/rating_screen.dart (1)
3-10: Add validation for restaurantName parameterConsider adding validation to ensure the restaurantName is not empty, as it's displayed in the AppBar and likely used for data submission.
class RatingScreen extends StatefulWidget { - const RatingScreen({super.key, required this.restaurantName}); + const RatingScreen({super.key, required this.restaurantName}) { + assert(restaurantName.isNotEmpty, 'Restaurant name cannot be empty'); + } final String restaurantName;lib/features/home/presentation/widgets/for_you_tab.dart (2)
67-78: Consider enhancing the Rate button functionalityThe current implementation allows unlimited rating submissions. Consider:
- Tracking whether a user has already rated a restaurant
- Disabling or hiding the Rate button for already rated restaurants
- Showing the user's previous rating
- const Spacer(), - TextButton( - onPressed: () { - Navigator.of(context).push( - MaterialPageRoute<void>( - builder: (BuildContext context) => RatingScreen( - restaurantName: foodBusiness.name), - ), - ); - }, - child: const Text('Rate'), - ), + const Spacer(), + BlocBuilder<RatingBloc, RatingState>( + builder: (context, state) { + final hasRated = state.hasUserRatedRestaurant(foodBusiness.id); + final previousRating = state.getUserRating(foodBusiness.id); + + return Row( + children: [ + if (hasRated) + Text('Your rating: ${previousRating.toString()}'), + TextButton( + onPressed: hasRated ? null : () { + Navigator.of(context).push( + MaterialPageRoute<void>( + builder: (BuildContext context) => RatingScreen( + restaurantName: foodBusiness.name, + ), + ), + ); + }, + child: Text(hasRated ? 'Rated' : 'Rate'), + ), + ], + ); + }, + ),
Line range hint
1-1: Consider implementing a complete ratings architectureThe current implementation focuses on UI components but lacks crucial architectural elements:
- State Management: Consider implementing a RatingBloc for managing rating states
- Data Layer: Add a repository pattern for handling rating data persistence
- API Integration: Implement proper API client for submitting ratings to backend
- Models: Create proper data models for ratings
Would you like assistance in implementing any of these architectural components?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
lib/features/home/presentation/screens/rating_screen.dart(1 hunks)lib/features/home/presentation/widgets/for_you_tab.dart(2 hunks)
| class _RatingScreenState extends State<RatingScreen> { | ||
| double _rating = 3.0; | ||
| final TextEditingController _commentController = TextEditingController(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider adding comment length validation
The comment field currently accepts empty text. Consider adding validation to ensure meaningful feedback.
class _RatingScreenState extends State<RatingScreen> {
double _rating = 3.0;
final TextEditingController _commentController = TextEditingController();
+ final int _minCommentLength = 10;
+ String? _commentError;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| class _RatingScreenState extends State<RatingScreen> { | |
| double _rating = 3.0; | |
| final TextEditingController _commentController = TextEditingController(); | |
| class _RatingScreenState extends State<RatingScreen> { | |
| double _rating = 3.0; | |
| final TextEditingController _commentController = TextEditingController(); | |
| final int _minCommentLength = 10; | |
| String? _commentError; | |
| TextField( | ||
| controller: _commentController, | ||
| maxLines: 5, | ||
| decoration: InputDecoration( | ||
| hintText: 'Write your comments here...', | ||
| border: OutlineInputBorder( | ||
| borderRadius: BorderRadius.circular(8), | ||
| ), | ||
| ), | ||
| ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error text display to TextField
Update the TextField to display validation errors.
TextField(
controller: _commentController,
maxLines: 5,
decoration: InputDecoration(
hintText: 'Write your comments here...',
+ errorText: _commentError,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
),Committable suggestion skipped: line range outside the PR's diff.
| void _submitRating(BuildContext context) { | ||
| final String comment = _commentController.text.trim(); | ||
|
|
||
| // Perform the rating submission logic here | ||
| // For example, send the data to the server | ||
|
|
||
| ScaffoldMessenger.of(context).showSnackBar( | ||
| const SnackBar(content: Text('Rating submitted!')), | ||
| ); | ||
|
|
||
| Navigator.pop(context); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enhance _submitRating with proper error handling and loading state
The current implementation lacks:
- Loading state during submission
- Error handling for submission failures
- Actual implementation for server submission
Consider implementing this improved version:
- void _submitRating(BuildContext context) {
- final String comment = _commentController.text.trim();
-
- // Perform the rating submission logic here
- // For example, send the data to the server
-
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('Rating submitted!')),
- );
-
- Navigator.pop(context);
+ Future<void> _submitRating(BuildContext context) async {
+ final String comment = _commentController.text.trim();
+
+ if (comment.length < _minCommentLength) {
+ setState(() {
+ _commentError = 'Comment must be at least $_minCommentLength characters';
+ });
+ return;
+ }
+
+ setState(() {
+ _commentError = null;
+ });
+
+ try {
+ // Show loading indicator
+ showDialog(
+ context: context,
+ barrierDismissible: false,
+ builder: (BuildContext context) => const Center(
+ child: CircularProgressIndicator(),
+ ),
+ );
+
+ // TODO: Implement actual rating submission
+ // await ratingService.submitRating(
+ // restaurantName: widget.restaurantName,
+ // rating: _rating,
+ // comment: comment,
+ // );
+
+ // Hide loading indicator
+ Navigator.pop(context);
+
+ ScaffoldMessenger.of(context).showSnackBar(
+ const SnackBar(content: Text('Rating submitted successfully!')),
+ );
+
+ Navigator.pop(context); // Close rating screen
+ } catch (e) {
+ // Hide loading indicator
+ Navigator.pop(context);
+
+ ScaffoldMessenger.of(context).showSnackBar(
+ SnackBar(content: Text('Failed to submit rating: ${e.toString()}')),
+ );
}Committable suggestion skipped: line range outside the PR's diff.
Closes #73
Summary by CodeRabbit
New Features
RatingScreenfor users to rate restaurants and leave comments.ForYouTabto navigate to the new rating feature.Bug Fixes
ForYouTabfor improved layout.