Skip to content

added a custom timer for the alarm challenges#949

Open
raghavgupta000001 wants to merge 1 commit intoCCExtractor:mainfrom
raghavgupta000001:custom_timer
Open

added a custom timer for the alarm challenges#949
raghavgupta000001 wants to merge 1 commit intoCCExtractor:mainfrom
raghavgupta000001:custom_timer

Conversation

@raghavgupta000001
Copy link
Copy Markdown
Contributor

🚀 What this PR does

This PR introduces a highly requested feature: the ability to set a custom duration for alarm challenges. Alongside this feature, it resolves a critical rendering bottleneck (flickering on emulators) and fixes a background service crash on modern Android versions.

🛠️ Key Changes

1. Custom Challenge Timer Feature

  • Added a challengeDuration property to the Isar AlarmModel (defaulting to 15s).
  • Updated the SQLite alarms database table schema via isar_provider.dart to sync with the new duration state.
  • Added a dynamic slider in the Add/Update Alarm UI allowing users to choose a challenge duration between 5 and 60 seconds.

2. Render Optimization (Flickering Fix)

  • The Bug: The AlarmChallengeController timer was originally ticking every 50ms (for the old linear progress bar). When applied to the new massive text timer, this overloaded the Android emulator's graphics renderer, causing violent black screen flashing/frame drops.
  • The Fix: Refactored the timer engine to use a clean integer timeRemaining that ticks exactly once per second (Timer.periodic(const Duration(seconds: 1)...).
  • Wrapped the timer Obx widgets in the Challenge Views with RepaintBoundary to strictly isolate UI repaints and eliminate frame drops entirely.

3. Android 14 Exact Alarm Permissions

  • The Bug: Android 12+ strictly prohibits background services from setting exact millisecond alarms without explicit permission, causing silent crashes. Furthermore, emulators lack physical battery profiles, causing the UI's ignoreBatteryOptimizations check to silently fail and block alarm creation.
  • The Fix: Added <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" /> and <uses-permission android:name="android.permission.USE_EXACT_ALARM" /> to AndroidManifest.xml. Removed the strict battery optimization check in add_or_update_alarm_view.dart to allow emulator testing.

📱 Visuals

Custom_Alarm_Video.mp4

🧪 Testing Performed

  • Verified alarms save perfectly to both Isar and SQLite databases.
  • Tested UI rendering on an Android emulator: confirmed 0 frame drops and no flickering during Math, Shake, QR, and Pedometer challenges.
  • Verified background service successfully wakes the device and triggers the alarm ring screen at the exact scheduled minute.

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.

1 participant