Skip to content

fix(timer): prevent division by zero in progress calculation and sanitize negative settings input#28

Merged
tqha1011 merged 30 commits intomainfrom
feature/countdown_timer
Apr 8, 2026
Merged

fix(timer): prevent division by zero in progress calculation and sanitize negative settings input#28
tqha1011 merged 30 commits intomainfrom
feature/countdown_timer

Conversation

@hoanghaoz
Copy link
Copy Markdown
Collaborator

@hoanghaoz hoanghaoz commented Apr 8, 2026

Summary by CodeRabbit

Bug Fixes

  • Improved robustness of progress calculation to prevent invalid values in edge cases
  • Enhanced timer duration settings validation to prevent invalid configurations and automatically enforce a 1-minute minimum

hoanghaoz and others added 30 commits March 24, 2026 16:04
- Added Pomodoro timer with Start/Reset/Skip logic.
- Integrated local Quick Notes with Pin/Delete functionality.
- Supported image attachments in notes using image_picker.
- Added Focus settings: time duration, vibration, and ringtones.
Fixed 3 file(s) based on 4 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 86c0aaf7-4e08-40eb-85c2-e6d4b5c70c95

📥 Commits

Reviewing files that changed from the base of the PR and between 2bdbda5 and 1b8984e.

📒 Files selected for processing (1)
  • src/lib/features/note/viewmodel/focus_viewmodel.dart

📝 Walkthrough

Walkthrough

Updated the focus viewmodel to add defensive validation: the progress getter now guards against division by zero, returning 0.0 for invalid totalTime values and clamping results to [0.0, 1.0], while updateSettings(...) validates and coerces non-positive duration parameters to safe defaults.

Changes

Cohort / File(s) Summary
Input Validation & Guard Clauses
src/lib/features/note/viewmodel/focus_viewmodel.dart
Added zero-check guard to progress getter to prevent invalid calculations; introduced input validation in updateSettings(...) to coerce non-positive Pomodoro/break minutes to minimum safe value of 1 with error logging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Hop hop, the timers now stand tall,
No division by zero shall make us fall,
With guards in place and bounds held tight,
The Pomodoro dream burns ever bright! ⏲️✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the two main bug fixes: preventing division by zero in progress calculation and sanitizing negative settings input.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/countdown_timer

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@tqha1011 tqha1011 merged commit 6a20633 into main Apr 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants