fix: correct Map vs bool comparison in _updateTaskStatus - #251
fix: correct Map vs bool comparison in _updateTaskStatus#251Priyanshu-byte-coder wants to merge 1 commit into
Conversation
WalkthroughThe PR fixes a type mismatch bug in task status updates where the return value comparison was unreachable. The method now correctly accesses the ChangesTask Status Update Result Handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/screens/tasks/task_detail_screen.dart (1)
80-85:⚠️ Potential issue | 🟠 Major | ⚡ Quick winRe-check
mountedafter awaiting_loadTaskDetails()before usingcontext.At line 83,
await _loadTaskDetails()can unmount this widget. TheScaffoldMessenger.of(context)call on line 84 then usescontextafter an async gap without a fresh mounted guard. Additionally, line 93 has the same unguarded pattern in the else branch.Suggested fix
if (mounted) { if (result['success'] == true) { // Reload task details await _loadTaskDetails(); + if (!mounted) return; ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text( 'Task status updated to ${_getStatusLabel(status)}', ),Apply the same check after line 93 in the else branch as well.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lib/screens/tasks/task_detail_screen.dart` around lines 80 - 85, After awaiting _loadTaskDetails() you must re-check the widget's mounted property before using the BuildContext; update both the success branch (after await _loadTaskDetails() and before ScaffoldMessenger.of(context).showSnackBar(...)) and the else branch (the place at line ~93 where ScaffoldMessenger.of(context) is used) to return or skip the context-dependent calls if mounted is false, i.e., re-evaluate mounted and only call ScaffoldMessenger.of(context).showSnackBar(...) when mounted is true to avoid using context after an async gap.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@lib/screens/tasks/task_detail_screen.dart`:
- Around line 80-85: After awaiting _loadTaskDetails() you must re-check the
widget's mounted property before using the BuildContext; update both the success
branch (after await _loadTaskDetails() and before
ScaffoldMessenger.of(context).showSnackBar(...)) and the else branch (the place
at line ~93 where ScaffoldMessenger.of(context) is used) to return or skip the
context-dependent calls if mounted is false, i.e., re-evaluate mounted and only
call ScaffoldMessenger.of(context).showSnackBar(...) when mounted is true to
avoid using context after an async gap.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 30842278-8bcd-4667-8d72-072652bb9aed
📒 Files selected for processing (1)
lib/screens/tasks/task_detail_screen.dart
|
@M4dhav @Swayanshuu this one is approved and mergeable — could you merge when you get a chance? It fixes the Map-vs-bool comparison in |
Summary
Closes #222
_updateTaskStatus()stored the return value ofupdateTaskStatus()insuccess, then comparedsuccess == true. ButupdateTaskStatus()returnsFuture<Map<String, dynamic>>, notbool— soMap == boolis alwaysfalsein Dart. The success SnackBar was unreachable and the failure SnackBar showed on every status update.Root cause
Fix
Changes
lib/screens/tasks/task_detail_screen.dart:75— renamedsuccess→resultlib/screens/tasks/task_detail_screen.dart:81— changedsuccess == true→result['success'] == trueThis matches the pattern already used on line 186 in the same file (
result['success']).Summary by CodeRabbit