Skip to content

Commit 6a20633

Browse files
hoanghaozcoderabbitai[bot]CodeRabbit
authored
fix(timer): prevent division by zero in progress calculation and sanitize negative settings input (#28)
* feat(core): add auth layout template, custom textfield and colors * feat(auth): implement viewmodels for auth flow (MVVM) * feat(auth): build complete auth UI screens (Login, Register, OTP, Passwords) * chore(main): set LoginView as initial route * refactor(auth) : delete .gitkeep * chore: update dependencies and pubspec.lock * refactor(auth): optimize registration logic, timezone handling, and form validation * feat(auth): update UI for login, registration, and forgot password screens * feat(tasks): update task management UI and statistics screen * chore: update main entry point and fix widget tests * chore: ignore devtools_options.yaml * chore: ignore devtools_options.yaml * style(login) : rewrite title for login view * feat(auth): configure android deep link for supabase oauth * refactor(ui): add social login callbacks to auth layout template * feat(auth): update oauth methods with redirect url and signout * feat(auth): implement AuthGate using StreamBuilder for session tracking * feat(viewmodel): add oauth logic and improve provider lifecycle * refactor(ui): migrate LoginView to Provider pattern * chore(main): set AuthGate as initial route and setup provider * feat: implement full Focus feature set - 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. * fix (auth) : dispose TextEditingControllers to prevent memory leaks * refactor (alarm ) : create off alarm button when time out * fix: apply CodeRabbit auto-fixes Fixed 3 file(s) based on 4 unresolved review comments. Co-authored-by: CodeRabbit <[email protected]> * fix(timer): prevent division by zero in progress calculation and sanitize negative settings input * fix(timer): prevent division by zero in progress calculation and sanitize negative settings input --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: CodeRabbit <[email protected]>
1 parent 2bdbda5 commit 6a20633

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/lib/features/note/viewmodel/focus_viewmodel.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class FocusViewModel extends ChangeNotifier {
151151
}
152152

153153
// Calculate progress for the circular indicator
154-
double get progress => timeRemaining / totalTime;
154+
double get progress => totalTime <= 0 ? 0.0 : (timeRemaining / totalTime).clamp(0.0, 1.0);
155155

156156
// --- TIMER OPERATIONS ---
157157

@@ -221,6 +221,11 @@ class FocusViewModel extends ChangeNotifier {
221221

222222
// Update preferences from the settings dialog
223223
void updateSettings({required int newPomodoroMinutes, required int newBreakMinutes, required bool vibrate, required int ringtone}) {
224+
if (newPomodoroMinutes <= 0 || newBreakMinutes <= 0) {
225+
debugPrint('Lỗi: Thời gian cài đặt phải lớn hơn 0 phút. Đã tự động set về 1.');
226+
newPomodoroMinutes = newPomodoroMinutes <= 0 ? 1 : newPomodoroMinutes;
227+
newBreakMinutes = newBreakMinutes <= 0 ? 1 : newBreakMinutes;
228+
}
224229
stopAlarm(); // Stop alarm if opening settings
225230
pomodoroTime = newPomodoroMinutes * 60;
226231
shortBreakTime = newBreakMinutes * 60;

0 commit comments

Comments
 (0)