Conversation
|
🎉 Welcome @mahmoudr80!
We appreciate your contribution! 🚀 |
📝 WalkthroughWalkthroughA guard condition was added to the rating display logic in the profile screen to prevent division by zero when Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/views/screens/profile_screen.dart`:
- Around line 206-213: The creator-profile rating can be null and is being
force-formatted in the Text widget; update the display logic in
profile_screen.dart (where widget.isCreatorProfile and
widget.creator!.userRating are used) to fall back to "0.0" when
widget.creator!.userRating is null or when ratingCount is zero, and/or normalize
the value when constructing ResonateUser so userRating is non-null (compute
ratingTotal/ratingCount only if ratingCount>0 else set 0.0) in the ResonateUser
creation path (see explore_story_controller where ratingTotal/ratingCount are
computed) so the UI can safely call toStringAsFixed(1).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ca3e114d-5037-42a6-b0df-44d2c9dd3d5f
📒 Files selected for processing (1)
lib/views/screens/profile_screen.dart
| child:Text( | ||
| widget.isCreatorProfile == null | ||
| ? (authController.ratingTotal / | ||
| ? authController.ratingCount!=0? | ||
| (authController.ratingTotal / | ||
| authController.ratingCount) | ||
| .toStringAsFixed(1) | ||
| : widget.creator!.userRating!.toStringAsFixed(1), | ||
| ), | ||
| : "0.0":widget.creator!.userRating!.toStringAsFixed(1), | ||
| ),), |
There was a problem hiding this comment.
The zero-rating fix doesn't cover creator profiles.
Line 212 still force-formats widget.creator!.userRating!. That field is nullable in lib/models/resonate_user.dart:16, and lib/controllers/explore_story_controller.dart:201-202 still computes it from ratingTotal / ratingCount without a zero-count guard. Creator profiles with no ratings can therefore still end up with an invalid value here. Please apply the same 0.0 fallback there, or normalize userRating before constructing ResonateUser.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@lib/views/screens/profile_screen.dart` around lines 206 - 213, The
creator-profile rating can be null and is being force-formatted in the Text
widget; update the display logic in profile_screen.dart (where
widget.isCreatorProfile and widget.creator!.userRating are used) to fall back to
"0.0" when widget.creator!.userRating is null or when ratingCount is zero,
and/or normalize the value when constructing ResonateUser so userRating is
non-null (compute ratingTotal/ratingCount only if ratingCount>0 else set 0.0) in
the ResonateUser creation path (see explore_story_controller where
ratingTotal/ratingCount are computed) so the UI can safely call
toStringAsFixed(1).
Description
This PR fixes a crash in the Profile screen caused by a division by zero when calculating the user's rating.
Fixes # (issue)
Added a guard condition to prevent division when ratingCount == 0
Displays a default rating (0.0) when no ratings exist
Type of change
Previously:
(authController.ratingTotal / authController.ratingCount)
This caused a runtime crash when ratingCount was 0.
Solution
(authController.ratingCount == 0)
? "0.0"
: (authController.ratingTotal / authController.ratingCount).toStringAsFixed(1)
Please delete options that are not relevant.
How Has This Been Tested?
Manual Testing
Set ratingCount = 0
Open Profile screen
Verified:
No crash occurs
Rating displays as 0.0
Set ratingCount > 0
Verified:
Rating displays correctly with 1 decimal
Please include screenshots below if applicable.
Checklist:
Maintainer Checklist
Summary by CodeRabbit