### Build and Run with Setup Doctor Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/InstallationSteps.md After setup, run this command to verify all installation steps and then build the release version of your app. Includes optional CocoaPods installation. ```bash cd ios && pod install && cd .. # CocoaPods only dart run flutter_alarmkit:setup --doctor flutter run --release ``` -------------------------------- ### Run Flutter Alarmkit Setup Script Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/InstallationSteps.md Execute the setup script to diagnose and fix common installation problems, including project format and build phase issues. ```bash dart run flutter_alarmkit:setup --doctor ``` ```bash dart run flutter_alarmkit:setup ``` -------------------------------- ### Install and Verify Flutter AlarmKit Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/README.md Run these commands to install and verify the flutter_alarmkit setup on your iOS project. The --doctor flag checks for any issues. ```bash dart run flutter_alarmkit:setup dart run flutter_alarmkit:setup --doctor ``` -------------------------------- ### Build and Run Flutter Project Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/InstallationSteps.md Standard commands to clean the project, fetch dependencies, install CocoaPods, and run the release build. ```bash flutter clean flutter pub get cd ios pod install # CocoaPods only — skip on Swift Package Manager cd .. flutter run --release ``` -------------------------------- ### Run Alarmkit Setup Command Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/InstallationSteps.md Execute this command after completing Xcode configurations to patch project files and set up the plugin. ```bash dart run flutter_alarmkit:setup ``` -------------------------------- ### Schedule Daily Alarm Example Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/weekday.md Demonstrates how to schedule a daily alarm at a specific time using `Weekday.everyday`. ```dart await FlutterAlarmkit().scheduleRecurrentAlarm( weekdays: Weekday.everyday, hour: 7, minute: 0, label: 'Wake up', ); ``` -------------------------------- ### Minimal Customization (Stop Button Only) Example Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-ui-config.md Schedules a one-shot alarm with minimal UI customization, focusing only on the stop button. This example shows how to set a custom text, icon, and tint color for the stop button. ```dart final alarmId = await FlutterAlarmkit().scheduleOneShotAlarm( timestamp: fireDate.millisecondsSinceEpoch.toDouble(), label: 'Medication', uiConfig: const AlarmUIConfig( stopButton: AlarmButtonConfig( text: 'Took it', icon: 'checkmark', tintColor: '#34C759', ), ), ); ``` -------------------------------- ### toBitmask Method Example Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/weekday.md Shows how to convert a set of weekdays into an integer bitmask for internal representation. Handles workdays, all days, and empty sets. ```dart final workdays = {Weekday.monday, Weekday.wednesday, Weekday.friday}; final mask = Weekday.toBitmask(workdays); // → 0b0010101 (binary) = 21 (decimal) // bit 0 (monday) = 1, bit 1 (tuesday) = 0, bit 2 (wednesday) = 1, etc. final daily = Weekday.toBitmask(Weekday.everyday); // → 0b1111111 (binary) = 127 (decimal) final empty = Weekday.toBitmask({}); // → 0 (binary) = 0 (decimal) ``` -------------------------------- ### Fully Customized Countdown Timer Example Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-ui-config.md Sets a countdown alarm with extensive UI customization. This example demonstrates configuring all available buttons (stop, pause, resume, repeat) and custom titles for the countdown and paused states. ```dart final alarmId = await FlutterAlarmkit().setCountdownAlarm( countdownDurationInSeconds: 60, repeatDurationInSeconds: 10, label: 'Tea Timer', uiConfig: const AlarmUIConfig( stopButton: AlarmButtonConfig( text: 'Done', icon: 'checkmark.circle', textColor: '#FFFFFF', tintColor: '#34C759', ), pauseButton: AlarmButtonConfig( text: 'Pause', icon: 'pause.fill', textColor: '#FFFFFF', tintColor: '#FF9500', ), resumeButton: AlarmButtonConfig( text: 'Resume', icon: 'play.fill', textColor: '#FFFFFF', tintColor: '#34C759', ), repeatButton: AlarmButtonConfig( text: 'Repeat', icon: 'repeat.circle.fill', textColor: '#FFFFFF', tintColor: '#0A84FF', ), countdownTitle: 'Steeping...', pausedTitle: 'On hold', ), ); ``` -------------------------------- ### Convert MP3 to CAF using afconvert Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/configuration.md Provides a command-line example for converting MP3 audio files to the Core Audio Format (CAF) using the `afconvert` tool on macOS. ```bash afconvert -f caff -d LEI16 input.mp3 output.caf ``` -------------------------------- ### Clone and Copy Claude Code Skill Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/InstallationSteps.md Automates flutter_alarmkit setup by cloning a skill and copying it to the project's .claude/skills directory. ```bash # from your Flutter app root mkdir -p .claude/skills git clone --depth 1 https://github.com/gdelataillade/flutter_alarmkit /tmp/flutter_alarmkit-skill cp -R /tmp/flutter_alarmkit-skill/.claude/skills/flutter-alarmkit-setup .claude/skills/ rm -rf /tmp/flutter_alarmkit-skill ``` -------------------------------- ### Schedule Complex Alarm with Full Customization Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/configuration.md Use this example to schedule a countdown alarm with repeat functionality and extensive UI customization. Ensure authorization is requested beforehand and custom sounds are correctly configured. ```dart import 'package:flutter_alarmkit/flutter_alarmkit.dart'; Future scheduleComplexAlarm() async { final alarmkit = FlutterAlarmkit(); // 1. Request authorization final authorized = await alarmkit.requestAuthorization(); if (!authorized) return; // 2. Schedule with full customization final alarmId = await alarmkit.setCountdownAlarm( countdownDurationInSeconds: 1800, // 30 minutes repeatDurationInSeconds: 300, // Repeat every 5 minutes // Basic label: 'Cooking: Roast Chicken', tintColor: '#FF9500', // Orange soundPath: 'assets/sounds/beep.caf', // UI customization uiConfig: const AlarmUIConfig( stopButton: AlarmButtonConfig( text: 'Done', icon: 'checkmark.circle.fill', textColor: '#FFFFFF', tintColor: '#34C759', ), pauseButton: AlarmButtonConfig( text: 'Pause', icon: 'pause.fill', tintColor: '#FF9500', ), resumeButton: AlarmButtonConfig( text: 'Resume', icon: 'play.fill', tintColor: '#34C759', ), countdownTitle: 'Roasting...', pausedTitle: 'Paused', ), // Metadata metadata: const AlarmMetadata( icon: 'flame.fill', subtitle: '190°C', ), ); print('Alarm scheduled: $alarmId'); } ``` -------------------------------- ### Customize Live Activity UI with AlarmUIConfig Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/README.md Configure the appearance of Live Activity buttons and titles for countdown and paused states. Custom tint colors require the App Group setup. ```dart final alarmId = await FlutterAlarmkit().setCountdownAlarm( countdownDurationInSeconds: 60, repeatDurationInSeconds: 10, label: 'Tea timer', uiConfig: const AlarmUIConfig( stopButton: AlarmButtonConfig( text: 'Done', icon: 'checkmark.circle', textColor: '#FFFFFF', tintColor: '#FF3B30', ), pauseButton: AlarmButtonConfig(text: 'Hold', icon: 'pause.fill'), resumeButton: AlarmButtonConfig(text: 'Go', icon: 'play.fill'), countdownTitle: 'Steeping...', pausedTitle: 'On hold', ), ); ``` -------------------------------- ### Schedule Daily Alarm Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/weekday.md Example of scheduling a recurring alarm for every day of the week. ```dart await FlutterAlarmkit().scheduleRecurrentAlarm( weekdays: Weekday.everyday, hour: 9, minute: 0, label: 'Daily standup', ); ``` -------------------------------- ### Set Workout Timer (Countdown Alarm) Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-metadata.md Sets a countdown alarm for a workout session. This example configures a 15-minute initial countdown with 5-minute repeating rounds. The metadata uses a dumbbell icon. ```dart await FlutterAlarmkit().setCountdownAlarm( countdownDurationInSeconds: 900, // 15 minutes repeatDurationInSeconds: 300, // 5 minute rounds label: 'Workout', metadata: const AlarmMetadata( icon: 'dumbbell.fill', subtitle: 'Cardio session', ), ); ``` -------------------------------- ### Get Platform Version Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/flutter-alarmkit.md Retrieves the iOS platform version. Throws a PlatformException if the iOS version is less than 26.0. ```dart final version = await FlutterAlarmkit().getPlatformVersion(); print('iOS version: $version'); ``` -------------------------------- ### Configure Custom Alarm UI Buttons Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-button-config.md This example demonstrates how to use AlarmButtonConfig to customize the stop and pause buttons within the AlarmUIConfig. The custom buttons are then applied when setting a countdown alarm. ```dart final config = AlarmUIConfig( stopButton: AlarmButtonConfig( text: 'Dismiss', icon: 'checkmark.circle.fill', textColor: '#FFFFFF', tintColor: '#5AC8FA', ), pauseButton: AlarmButtonConfig( text: 'Hold on', icon: 'pause.circle', textColor: '#FFFFFF', tintColor: '#FF6B6B', ), ); final alarmId = await FlutterAlarmkit().setCountdownAlarm( countdownDurationInSeconds: 120, repeatDurationInSeconds: 30, label: 'Work Timer', uiConfig: config, ); ``` -------------------------------- ### toMap Method Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-ui-config.md Serializes the AlarmUIConfig object into a map, which is useful for transmitting the configuration data, for example, over a platform channel. Only non-null fields are included in the resulting map. ```APIDOC ## Methods ### toMap ```dart Map toMap() ``` Serializes this configuration to a map for transmission over the platform channel. Only non-null fields are included. **Returns:** `Map` — A map with keys matching the constructor parameters. **Example:** ```dart final config = AlarmUIConfig( stopButton: AlarmButtonConfig(text: 'Done', icon: 'checkmark.circle'), countdownTitle: 'Brewing...', ); final map = config.toMap(); // → { 'stopButton': {...}, 'countdownTitle': 'Brewing...' } ``` --- ``` -------------------------------- ### Check for Unknown Alarm Schedule Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/types.md Example of how to check if an alarm's schedule is of an unknown type. This is useful for informing the user to update the plugin. ```dart final schedule = alarm.schedule; if (schedule is UnknownAlarmSchedule) { print('Unsupported schedule type; update the plugin'); } ``` -------------------------------- ### Schedule Weekends Only Alarm Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/weekday.md Example for scheduling a recurring alarm that only triggers on Saturday and Sunday. ```dart await FlutterAlarmkit().scheduleRecurrentAlarm( weekdays: {Weekday.saturday, Weekday.sunday}, hour: 10, minute: 0, label: 'Weekend breakfast', ); ``` -------------------------------- ### Troubleshoot Release Build Errors Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/InstallationSteps.md Addresses the 'Could not run build/ios/iphoneos/Runner.app' error, typically resolved by unlocking the iPhone. ```bash flutter run --release ``` -------------------------------- ### Configure Info.plist for AlarmKit and Live Activities Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/InstallationSteps.md Add these keys to your ios/Runner/Info.plist file to enable AlarmKit functionality, Live Activities, and local network communication. Ensure descriptions are user-friendly. ```xml NSAlarmKitUsageDescription This app uses alarms to notify you even when your device is locked. NSSupportsLiveActivities NSBonjourServices _alarmkit._tcp NSLocalNetworkUsageDescription This app needs access to the local network to discover and connect to alarm devices. UIApplicationSceneManifest UIApplicationSupportsMultipleScenes UISceneConfigurations UIWindowSceneSessionRoleApplication UISceneClassName UIWindowScene UISceneConfigurationName flutter UISceneDelegateClassName FlutterSceneDelegate UISceneStoryboardFile Main ``` -------------------------------- ### Version Check at Startup Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/errors.md Verifies if the current platform version supports Alarmkit. It catches 'UNSUPPORTED_VERSION' errors and informs the user if a minimum iOS version is required. ```dart Future isAlarmkitSupported() async { try { final version = await FlutterAlarmkit().getPlatformVersion(); print('iOS version: $version'); return true; } on PlatformException catch (e) { if (e.code == 'UNSUPPORTED_VERSION') { print('Alarmkit requires iOS 26+'); return false; } return false; } } ``` -------------------------------- ### Working with Metadata Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm.md Explains how to access alarm metadata, specifically the `icon` and `subtitle` fields, if they are present. ```APIDOC ## Working with Metadata ### Description Accesses and prints metadata associated with an alarm, such as icon and subtitle. ### Method `getAlarms()` ### Endpoint N/A (SDK method) ### Request Example ```dart final alarm = await FlutterAlarmkit().getAlarms() .then((l) => l.firstWhere((a) => a.metadata != null)); if (alarm.metadata case AlarmMetadata(:var icon, :var subtitle)) { print('Icon: $icon'); print('Subtitle: $subtitle'); } ``` ``` -------------------------------- ### Typical AlarmKit Workflow Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/flutter-alarmkit.md Demonstrates the complete lifecycle of managing alarms using FlutterAlarmkit, from requesting authorization to scheduling, listening, querying, and canceling alarms. Ensure authorization is granted before proceeding with alarm operations. ```dart import 'package:flutter_alarmkit/flutter_alarmkit.dart'; Future setupAlarms() async { final alarmkit = FlutterAlarmkit(); // 1. Request authorization final authorized = await alarmkit.requestAuthorization(); if (!authorized) return; // 2. Schedule alarms final id1 = await alarmkit.scheduleOneShotAlarm( timestamp: DateTime.now().add(Duration(hours: 1)).millisecondsSinceEpoch.toDouble(), label: 'Meeting', ); final id2 = await alarmkit.scheduleRecurrentAlarm( weekdays: Weekday.everyday, hour: 7, minute: 0, label: 'Wake up', ); // 3. Listen to alarm updates alarmkit.alarmUpdates().listen((event) { print('Alarm ${event.alarmId}: ${event.kind}'); }); // 4. Query alarms final alarms = await alarmkit.getAlarms(); print('Scheduled alarms: ${alarms.length}'); // 5. Cancel when needed await alarmkit.cancelAlarm(alarmId: id1); } ``` -------------------------------- ### AlarmButtonConfig Constructor Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-button-config.md Creates a configuration object for a Live Activity alarm button, specifying its text, icon, and optional colors. ```APIDOC ## Constructor AlarmButtonConfig ### Description Creates a button configuration for a Live Activity alarm button (stop, pause, resume, repeat). ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **text** (String) - Required - Button label text (e.g., "Stop", "Pause", "Resume", "Done"). - **icon** (String) - Required - SF Symbol name for the button icon (e.g., "stop.circle", "pause.fill"). - **textColor** (String?) - Optional - Hex color for button text. Format: `#RRGGBB`. If null, uses system default. - **tintColor** (String?) - Optional - Hex color for button background/tint. Format: `#RRGGBB`. If null, uses standard tint for button type. ### Request Example ```dart const AlarmButtonConfig( text: "Stop", icon: "stop.circle", textColor: "#FFFFFF", tintColor: "#FF0000", ) ``` ### Response None (This is a constructor for a Dart class) ### Error Handling None explicitly documented for constructor usage. ``` -------------------------------- ### Get Authorization State Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/flutter-alarmkit.md Queries the current alarm scheduling authorization state without user interaction. Throws a PlatformException if the iOS version is less than 26.0. ```dart final state = await FlutterAlarmkit().getAuthorizationState(); switch (state) { case AlarmAuthorizationState.authorized: print('Authorized'); case AlarmAuthorizationState.denied: print('Denied'); case AlarmAuthorizationState.notDetermined: print('Not determined'); case AlarmAuthorizationState.unknown: print('Unknown'); } ``` -------------------------------- ### AlarmUIConfig Constructor Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-ui-config.md Use this constructor to create a UI configuration object for an alarm's Live Activity. All parameters are optional; null values trigger default AlarmKit behavior. ```dart const AlarmUIConfig({ AlarmButtonConfig? stopButton, AlarmButtonConfig? pauseButton, AlarmButtonConfig? resumeButton, AlarmButtonConfig? repeatButton, String? countdownTitle, String? pausedTitle, }) ``` -------------------------------- ### Create a Resume Button Configuration Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-button-config.md Defines a green resume button. Use this configuration when the alarm action involves resuming a process. ```dart const AlarmButtonConfig( text: 'Resume', icon: 'play.fill', tintColor: '#34C759', ) ``` -------------------------------- ### AlarmUIConfig Constructor Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-ui-config.md Creates a UI configuration object for alarms. All parameters are optional and will use default AlarmKit behavior if not provided. ```APIDOC ## Constructor AlarmUIConfig ### Description Creates a UI configuration object for alarms. All parameters are optional and will use default AlarmKit behavior if not provided. ### Parameters #### Optional Parameters - **stopButton** (`AlarmButtonConfig?`) - Customization for the stop/dismiss button. Default: text="Stop" (or "Done" for countdown), icon="stop.circle", tint=system red. - **pauseButton** (`AlarmButtonConfig?`) - Customization for the pause button (countdown alarms only). Default: text="Pause", icon="pause.circle", tint=system orange. - **resumeButton** (`AlarmButtonConfig?`) - Customization for the resume button (paused countdown alarms only). Default: text="Resume", icon="play.circle", tint=system green. - **repeatButton** (`AlarmButtonConfig?`) - Customization for the repeat button (countdown alarms only, typically restarts countdown). Default: text="Repeat", icon="repeat.circle", tint=system blue. - **countdownTitle** (`String?`) - Title shown during the countdown state. If null, uses the alarm's main `label`. - **pausedTitle** (`String?`) - Title shown when the countdown is paused. If null, uses the alarm's main `label`. ``` -------------------------------- ### Schedule Sleep Alarm Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-metadata.md Schedules a recurrent alarm for bedtime. This example sets the alarm to repeat every day at 10:30 PM. Metadata includes a moon icon and a 'Good night' subtitle. ```dart await FlutterAlarmkit().scheduleRecurrentAlarm( weekdays: Weekday.everyday, hour: 22, minute: 30, label: 'Bedtime', metadata: const AlarmMetadata( icon: 'moon.zzz.fill', subtitle: 'Good night', ), ); ``` -------------------------------- ### Iterate and Print Alarm Details Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/types.md Shows how to fetch all alarms and iterate through them to print their properties. This includes label, state, ID, tint color, and metadata. ```dart final alarms = await FlutterAlarmkit().getAlarms(); for (final alarm in alarms) { print('${alarm.label ?? "Untitled"} — ${alarm.state}'); print(' ID: ${alarm.id}'); print(' Color: ${alarm.tintColor}'); print(' Metadata: ${alarm.metadata}'); } ``` -------------------------------- ### Querying All Alarms Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm.md Demonstrates how to retrieve all alarms and access their properties like ID, label, state, and color. ```APIDOC ## Querying All Alarms ### Description Retrieves all alarms and iterates through them to print their details. ### Method `getAlarms()` ### Endpoint N/A (SDK method) ### Request Example ```dart final alarms = await FlutterAlarmkit().getAlarms(); for (final alarm in alarms) { print('ID: ${alarm.id}'); print('Label: ${alarm.label ?? "(no label)"}'); print('State: ${alarm.state}'); print('Color: ${alarm.tintColor}'); } ``` ``` -------------------------------- ### Custom Titles Only (Keep Default Buttons) Example Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-ui-config.md Sets a countdown alarm using custom titles for the countdown and paused states while retaining the default appearance for all buttons. This is useful for providing context-specific information without altering button functionality. ```dart final alarmId = await FlutterAlarmkit().setCountdownAlarm( countdownDurationInSeconds: 300, repeatDurationInSeconds: 60, label: 'Workout Timer', uiConfig: const AlarmUIConfig( countdownTitle: 'Getting stronger...', pausedTitle: 'Rest time', ), ); ``` -------------------------------- ### Alarm Constructor Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm.md Creates an alarm snapshot. All parameters except `id` and `state` are optional. Instances are returned by `getAlarms()` and carried in `AlarmUpdateEvent`s. ```APIDOC ## Alarm Constructor ### Description Creates an alarm snapshot. All parameters except `id` and `state` are optional. ### Parameters #### Path Parameters - **id** (String) - Required - The alarm's unique UUID. - **state** (AlarmState) - Required - The current lifecycle state. #### Query Parameters - **schedule** (AlarmSchedule?) - Optional - When the alarm fires. Null for countdown timers. - **countdownDuration** (AlarmCountdownDuration?) - Optional - Countdown timing (countdown alarms only). - **label** (String?) - Optional - The alarm title, if persisted by the plugin. - **tintColor** (String?) - Optional - The alarm tint color as `#RRGGBB`, if persisted. - **metadata** (AlarmMetadata?) - Optional - Icon and subtitle, if persisted. ``` -------------------------------- ### AlarmButtonConfig Constructor Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-button-config.md Use this constructor to create a button configuration for a Live Activity alarm button. Specify the button's label, SF Symbol icon, and optional text and tint colors. ```dart const AlarmButtonConfig({ required String text, required String icon, String? textColor, String? tintColor, }) ``` -------------------------------- ### Pattern Matching on Schedule Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm.md Illustrates how to use pattern matching to determine the type of alarm schedule (fixed, relative, unknown, or countdown). ```APIDOC ## Pattern Matching on Schedule ### Description Uses pattern matching to analyze the schedule type of an alarm. ### Method `getAlarms()` ### Endpoint N/A (SDK method) ### Request Example ```dart final alarm = await FlutterAlarmkit().getAlarms().then((l) => l.first); switch (alarm.schedule) { case FixedAlarmSchedule(:final date): print('One-shot: fires at $date'); case RelativeAlarmSchedule(:final hour, :final minute, :final weekdays): if (weekdays.isEmpty) { print('One-time: fires at next $hour:$minute'); } else { print('Repeating: fires at $hour:$minute on $weekdays'); } case UnknownAlarmSchedule(): print('Unknown schedule type'); case null: print('Countdown timer'); } ``` ``` -------------------------------- ### Pattern Matching on AlarmSchedule Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/README.md Demonstrates how to use a switch statement for pattern matching on the AlarmSchedule type to handle different alarm scheduling scenarios. ```dart switch (alarm.schedule) { case FixedAlarmSchedule(:var date) => ..., case RelativeAlarmSchedule(...) => ..., case UnknownAlarmSchedule() => ..., case null => ..., } ``` -------------------------------- ### Authorization Check and Request Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/errors.md Demonstrates how to check the current authorization state for scheduling alarms and request it if not granted. This is crucial as many alarm-scheduling methods fail silently if the app is not authorized. ```APIDOC ## Check and Request Authorization ### Description This snippet shows how to check if the app has permission to schedule alarms and request it from the user if necessary. Failure to obtain authorization can lead to silent failures in alarm scheduling. ### Method `getAuthorizationState()` returns `Future` `requestAuthorization()` returns `Future` ### Usage ```dart final state = await FlutterAlarmkit().getAuthorizationState(); if (state != AlarmAuthorizationState.authorized) { print('Not authorized. Requesting...'); final granted = await FlutterAlarmkit().requestAuthorization(); if (!granted) { print('User denied alarm scheduling permission'); } } ``` ### Error Handling - `requestAuthorization()` returns `false` if the user denies permission or the system rejects the request. ``` -------------------------------- ### AlarmMetadata Constructor Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-metadata.md Creates metadata to be attached to an alarm. Both icon and subtitle are optional. ```APIDOC ## Constructor ### Description Creates metadata to be attached to an alarm. Both fields are optional; empty strings are treated as null. ### Parameters #### Path Parameters - **icon** (String?) - Optional - SF Symbol name displayed alongside the alarm title (e.g., "pills.fill"). - **subtitle** (String?) - Optional - Secondary text line displayed beneath the alarm title. ``` -------------------------------- ### Troubleshoot App Group Configuration Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/InstallationSteps.md Ensures the App Group is enabled for both Runner and AlarmkitWidgetExtension targets to enable custom colors and titles in Live Activities. ```bash dart run flutter_alarmkit:setup --doctor ``` -------------------------------- ### Query & Monitor Methods Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/README.md Methods for retrieving existing alarms and monitoring alarm lifecycle events. ```APIDOC ## getAlarms ### Description Retrieves a list of all currently scheduled alarms. ### Method `getAlarms()` ### Parameters None ### Response A list of `Alarm` objects. ``` ```APIDOC ## alarmUpdates ### Description Provides a stream of events related to the alarm lifecycle (added, updated, removed). ### Method `alarmUpdates()` ### Parameters None ### Response A stream emitting `AlarmUpdateEvent` objects. ``` -------------------------------- ### Monitoring Alarm Changes Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm.md Details how to subscribe to real-time updates for alarms using `alarmUpdates()`, and how to handle different update events like added, updated, or removed. ```APIDOC ## Monitoring Alarm Changes ### Description Subscribes to a stream of alarm updates and handles different event kinds. ### Method `alarmUpdates()` ### Endpoint N/A (SDK method) ### Request Example ```dart final subscriptions = []; FlutterAlarmkit().alarmUpdates().listen((event) { switch (event.kind) { case AlarmUpdateKind.added: print('Added: ${event.alarm?.label}'); case AlarmUpdateKind.updated: print('Updated: ${event.alarm?.state}'); case AlarmUpdateKind.removed: print('Removed: ${event.alarmId}'); case AlarmUpdateKind.unknown: break; } }); ``` ``` -------------------------------- ### Listen to Alarm Updates Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/types.md Shows how to subscribe to a stream of alarm updates and react to different kinds of changes. Handle 'unknown' events to ensure robustness. ```dart FlutterAlarmkit().alarmUpdates().listen((event) { switch (event.kind) { case AlarmUpdateKind.added: print('New alarm: ${event.alarmId}'); case AlarmUpdateKind.updated: print('Updated: ${event.alarmId}, new state: ${event.alarm?.state}'); case AlarmUpdateKind.removed: print('Removed: ${event.alarmId}'); case AlarmUpdateKind.unknown: break; } }); ``` -------------------------------- ### fromMap Factory Constructor Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-metadata.md Deserialize AlarmMetadata from a platform channel map. ```APIDOC ## Factory Constructor ### fromMap Deserializes metadata from a platform-channel map. Empty strings are normalized to null. ### Parameters #### Path Parameters - **map** (Map) - A map from the platform channel with optional `'icon'` and `'subtitle'` keys. ### Returns `AlarmMetadata` — A new instance with fields populated from the map. ### Example ```dart final map = {'icon': 'pills.fill', 'subtitle': 'Take 2'}; final metadata = AlarmMetadata.fromMap(map); print(metadata.icon); // 'pills.fill' ``` ``` -------------------------------- ### Static Constant: everyday Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/weekday.md A predefined set containing all seven weekdays, useful for scheduling daily alarms. ```APIDOC ## Static Constants ### everyday ```dart static const Set everyday = { monday, tuesday, wednesday, thursday, friday, saturday, sunday, }; ``` A set containing all seven weekdays. Pass this to `scheduleRecurrentAlarm` to create a daily alarm. **Type:** `Set` **Example:** ```dart // Daily alarm at 7:00 AM await FlutterAlarmkit().scheduleRecurrentAlarm( weekdays: Weekday.everyday, hour: 7, minute: 0, label: 'Wake up', ); ``` ``` -------------------------------- ### Create a Repeat Button Configuration Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-button-config.md Defines a blue repeat button with white text. This configuration is appropriate for alarms that can be repeated. ```dart const AlarmButtonConfig( text: 'Repeat', icon: 'repeat.circle.fill', textColor: '#FFFFFF', tintColor: '#0A84FF', ) ``` -------------------------------- ### Create AlarmMetadata Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-metadata.md Constructs AlarmMetadata with optional icon and subtitle. Empty strings are treated as null. ```dart const AlarmMetadata({ String? icon, String? subtitle, }) ``` -------------------------------- ### isEmpty Method Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-metadata.md Check if the AlarmMetadata is empty (both icon and subtitle are null or empty). ```APIDOC ## Methods ### isEmpty Returns `true` if both `icon` and `subtitle` are null or empty strings (after normalization). ### Returns `bool` — `true` if no metadata fields are set. ### Example ```dart final empty = AlarmMetadata(); print(empty.isEmpty); // true final populated = AlarmMetadata(icon: 'pills.fill', subtitle: 'Take 2'); print(populated.isEmpty); // false ``` ``` -------------------------------- ### Handling Platform Exceptions Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/flutter-alarmkit.md Illustrates how to catch and handle `PlatformException` errors that may occur during native platform communication. Common error codes include `UNSUPPORTED_VERSION`, `CANCEL_ALL_ERROR`, and `UNKNOWN_ERROR`. ```dart try { await FlutterAlarmkit().scheduleOneShotAlarm( timestamp: DateTime.now().millisecondsSinceEpoch.toDouble(), label: 'Test', ); } on PlatformException catch (e) { print('Platform error [${e.code}]: ${e.message}'); } ``` -------------------------------- ### Authorization Methods Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/README.md Methods for managing alarm authorization states and requesting permissions. ```APIDOC ## requestAuthorization ### Description Requests user permission to schedule alarms. ### Method `requestAuthorization()` ### Parameters None ### Response None explicitly documented. ``` ```APIDOC ## getAuthorizationState ### Description Checks the current authorization state for scheduling alarms without prompting the user. ### Method `getAuthorizationState()` ### Parameters None ### Response Returns the current `AlarmAuthorizationState`. ``` ```APIDOC ## getPlatformVersion ### Description Retrieves the platform version, specifically for iOS. ### Method `getPlatformVersion()` ### Parameters None ### Response String representing the platform version. ``` -------------------------------- ### Build Alarm List with Schedule Details Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/README.md Retrieves all scheduled alarms and iterates through them to print their labels, states, and detailed schedule information using pattern matching on the schedule type. ```dart final alarms = await FlutterAlarmkit().getAlarms(); for (final alarm in alarms) { final scheduleText = switch (alarm.schedule) { FixedAlarmSchedule(:var date) => 'Once at $date', RelativeAlarmSchedule(:var hour, :var minute, :var weekdays) => weekdays.isEmpty ? 'Next $hour:$minute' : '$hour:$minute on $weekdays', UnknownAlarmSchedule() => 'Unknown schedule', null => 'Countdown timer', }; print('${alarm.label ?? alarm.id}: ${alarm.state} — $scheduleText'); } ``` -------------------------------- ### toMap Method Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-metadata.md Serialize AlarmMetadata to a map for platform channel transmission. ```APIDOC ## Methods ### toMap Serializes this metadata to a map for transmission over the platform channel. Only non-null, non-empty fields are included. ### Returns `Map` — A map with keys `'icon'` and/or `'subtitle'` (empty fields omitted). ### Example ```dart final metadata = AlarmMetadata( icon: 'pills.fill', subtitle: 'Take 2 tablets', ); final map = metadata.toMap(); // → { 'icon': 'pills.fill', 'subtitle': 'Take 2 tablets' } ``` ``` -------------------------------- ### Platform Version Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/GENERATION_REPORT.md Retrieves the platform version of the alarm service. ```APIDOC ## getPlatformVersion ### Description Retrieves the current version of the platform's alarm service. ### Method ``` Future getPlatformVersion() ``` ``` -------------------------------- ### pauseAlarm, resumeAlarm, countdownAlarm, stopAlarm Error Conditions Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/errors.md Highlights that the `pauseAlarm`, `resumeAlarm`, `countdownAlarm`, and `stopAlarm` methods do not throw exceptions and indicate success or failure through a boolean return value. ```APIDOC ## pauseAlarm, resumeAlarm, countdownAlarm, stopAlarm Specific Errors ### Description This section details the error conditions for the `pauseAlarm`, `resumeAlarm`, `countdownAlarm`, and `stopAlarm` methods. ### Throws Nothing. Failures are silent. ### Returns - `Future`: Returns `true` on success and `false` on failure (e.g., alarm does not exist, operation rejected, not applicable to alarm type). ``` -------------------------------- ### Static Method: toBitmask Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/weekday.md Converts a set of weekdays into an integer bitmask for internal alarm scheduling. ```APIDOC ## Static Methods ### toBitmask ```dart static int toBitmask(Set weekdays) ``` Converts a set of weekdays to a bitmask for internal representation. Each weekday occupies the bit at its enum position. **Parameters:** | Parameter | Type | Description | |-----------|------|-------------| | `weekdays` | `Set` | A set of weekdays to encode. | **Returns:** `int` — A bitmask where each bit corresponds to a weekday's enum position. Empty set returns `0`. **Example:** ```dart final workdays = {Weekday.monday, Weekday.wednesday, Weekday.friday}; final mask = Weekday.toBitmask(workdays); // → 0b0010101 (binary) = 21 (decimal) // bit 0 (monday) = 1, bit 1 (tuesday) = 0, bit 2 (wednesday) = 1, etc. final daily = Weekday.toBitmask(Weekday.everyday); // → 0b1111111 (binary) = 127 (decimal) final empty = Weekday.toBitmask({}); // → 0 (binary) = 0 (decimal) ``` ``` -------------------------------- ### Scheduling Methods Error Conditions Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/errors.md Outlines the potential `PlatformException` errors that can occur during alarm scheduling operations, including invalid parameters, native scheduling failures, lack of authorization, and issues with the returned alarm ID. ```APIDOC ## Alarm Scheduling Methods Errors ### Description This section covers the error conditions for scheduling methods: `scheduleOneShotAlarm`, `setCountdownAlarm`, and `scheduleRecurrentAlarm`. ### Throws - `PlatformException` with code `UNSUPPORTED_VERSION`: Thrown if the iOS version is less than 26.0. - `PlatformException` with code `UNKNOWN_ERROR`: Thrown under the following circumstances: - Invalid parameters (e.g., timestamp/durations out of range, invalid hour/minute). - Scheduling fails on the native side. - The app is not authorized to schedule alarms. - The returned alarm ID is null. ### Returns - `Future`: The alarm UUID on success. The method throws an exception on failure. ``` -------------------------------- ### Weekday Values Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/weekday.md Lists the available weekday values and their corresponding bit positions and descriptions. ```APIDOC ## Values | Value | Bit Position | Description | |-------|--------------|-------------| | `monday` | 0 | Monday | | `tuesday` | 1 | Tuesday | | `wednesday` | 2 | Wednesday | | `thursday` | 3 | Thursday | | `friday` | 4 | Friday | | `saturday` | 5 | Saturday | | `sunday` | 6 | Sunday | ``` -------------------------------- ### toMap Method Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-button-config.md Serializes the AlarmButtonConfig object into a map, suitable for platform channel communication. ```APIDOC ## toMap Method ### Description Serializes this configuration to a map for transmission over the platform channel. ### Method ```dart Map toMap() ``` ### Returns `Map` — A map with keys `'text'`, `'icon'`, `'textColor'`, `'tintColor'`. ### Example ```dart final button = AlarmButtonConfig( text: 'Done', icon: 'checkmark.circle', tintColor: '#34C759', ); final map = button.toMap(); // → { // 'text': 'Done', // 'icon': 'checkmark.circle', // 'textColor': null, // 'tintColor': '#34C759', // } ``` ``` -------------------------------- ### Add flutter_alarmkit Dependency Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/InstallationSteps.md Use this command to add the flutter_alarmkit package to your project's dependencies. ```bash flutter pub add flutter_alarmkit ``` -------------------------------- ### AlarmUIConfig Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/types.md UI customization for an alarm's Live Activity presentation. Allows configuration of buttons and titles. ```APIDOC ## Class: AlarmUIConfig ### Description Provides configuration options for customizing the appearance of an alarm's Live Activity, including buttons and titles. ### Fields - **stopButton** (AlarmButtonConfig?) - Configuration for the stop button. - **pauseButton** (AlarmButtonConfig?) - Configuration for the pause button. - **resumeButton** (AlarmButtonConfig?) - Configuration for the resume button. - **repeatButton** (AlarmButtonConfig?) - Configuration for the repeat button. - **countdownTitle** (String?) - The title displayed during the countdown. - **pausedTitle** (String?) - The title displayed when the alarm is paused. ``` -------------------------------- ### requestAuthorization Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/flutter-alarmkit.md Requests user permission to schedule alarms. This is a prerequisite for scheduling any alarms and presents a system dialog to the user. ```APIDOC ## requestAuthorization ### Description Requests user permission to schedule alarms. Presents a system dialog to the user asking for alarm scheduling permission. ### Method Future ### Parameters None ### Response #### Success Response - **isAuthorized** (bool) - `true` if authorization was granted, `false` otherwise. ### Throws - `PlatformException` if iOS version < 26.0. ### Example ```dart try { final isAuthorized = await FlutterAlarmkit().requestAuthorization(); if (isAuthorized) { print('Authorization granted'); } else { print('Authorization denied'); } } catch (e) { print('Error: $e'); } ``` ``` -------------------------------- ### Work with Alarm Metadata Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm.md Find an alarm that has metadata and access its icon and subtitle properties. ```dart final alarm = await FlutterAlarmkit().getAlarms() .then((l) => l.firstWhere((a) => a.metadata != null)); if (alarm.metadata case AlarmMetadata(:var icon, :var subtitle)) { print('Icon: $icon'); print('Subtitle: $subtitle'); } ``` -------------------------------- ### cancelAll Error Conditions Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/errors.md Explains the `PlatformException` errors that can occur when attempting to cancel all alarms, including specific error codes for cancellation failures and unsupported versions. ```APIDOC ## cancelAll Specific Errors ### Description This section details the error conditions for the `cancelAll` method. ### Throws - `PlatformException` with code `CANCEL_ALL_ERROR`: Thrown if one or more alarms could not be cancelled. - `PlatformException` with code `UNSUPPORTED_VERSION`: Thrown if the iOS version is less than 26.0. ### Returns - `Future`: This method completes successfully only if all cancellations are successful. It does not return a value on success but will throw an exception on failure. ``` -------------------------------- ### Alarm Factory Methods Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/GENERATION_REPORT.md Factory methods for creating Alarm and AlarmMetadata objects from maps. ```APIDOC ## Alarm Factory Methods ### Description Provides factory constructors for creating `Alarm` and `AlarmMetadata` objects, typically used when deserializing data. ### Methods ```dart // For Alarm class Alarm.fromMap(Map map) // For AlarmMetadata class AlarmMetadata.fromMap(Map map) ``` ``` -------------------------------- ### Control Methods Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/README.md Methods for controlling the state and lifecycle of scheduled alarms. ```APIDOC ## cancelAlarm ### Description Cancels a single, specific alarm. ### Method `cancelAlarm()` ### Parameters Requires an identifier for the alarm to be cancelled. ### Response None explicitly documented. ``` ```APIDOC ## cancelAll ### Description Cancels all currently scheduled alarms. ### Method `cancelAll()` ### Parameters None ### Response None explicitly documented. ``` ```APIDOC ## pauseAlarm ### Description Pauses a countdown alarm that is currently active. ### Method `pauseAlarm()` ### Parameters Requires an identifier for the countdown alarm to be paused. ### Response None explicitly documented. ``` ```APIDOC ## resumeAlarm ### Description Resumes a previously paused countdown alarm. ### Method `resumeAlarm()` ### Parameters Requires an identifier for the paused countdown alarm. ### Response None explicitly documented. ``` ```APIDOC ## countdownAlarm ### Description Restarts the countdown for a countdown alarm. ### Method `countdownAlarm()` ### Parameters Requires an identifier for the countdown alarm to restart. ### Response None explicitly documented. ``` ```APIDOC ## stopAlarm ### Description Stops an alarm. For one-shot alarms, this cancels them. For recurring alarms, this may reschedule them. ### Method `stopAlarm()` ### Parameters Requires an identifier for the alarm to be stopped. ### Response None explicitly documented. ``` -------------------------------- ### Alarm Equality Check Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm.md Demonstrates how Alarm objects are compared for equality based on all their fields. Use this to verify if two alarm instances represent the same alarm. ```dart final a1 = Alarm(id: 'a', state: AlarmState.scheduled); final a2 = Alarm(id: 'a', state: AlarmState.scheduled); print(a1 == a2); // true final a3 = Alarm(id: 'a', state: AlarmState.countdown); print(a1 == a3); // false ``` -------------------------------- ### getPlatformVersion Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/flutter-alarmkit.md Retrieves the iOS platform version running on the device. This method is useful for checking compatibility or logging purposes. ```APIDOC ## getPlatformVersion ### Description Returns the iOS platform version running on the device. ### Method Future ### Parameters None ### Response #### Success Response - **version** (String?) - The iOS version string, or null if unavailable. ### Throws - `PlatformException` if iOS version < 26.0. ### Example ```dart final version = await FlutterAlarmkit().getPlatformVersion(); print('iOS version: $version'); ``` ``` -------------------------------- ### Create a Stop Button Configuration Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm-button-config.md Defines a red stop button with white text. This configuration is useful for alarm actions that require a clear 'stop' indicator. ```dart const AlarmButtonConfig( text: 'Stop', icon: 'stop.circle', textColor: '#FFFFFF', tintColor: '#FF3B30', ) ``` -------------------------------- ### Alarm.fromMap Factory Constructor Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/api-reference/alarm.md Deserializes an alarm snapshot from a platform-channel map. This method is tolerant of the nested `Map` format that platform channels produce. ```APIDOC ## Alarm.fromMap ### Description Deserializes an alarm snapshot from a platform-channel map. Tolerant of the nested `Map` format that platform channels produce. ### Method Signature `factory Alarm.fromMap(Map map)` ### Parameters #### Path Parameters - **map** (`Map`) - Required - A map from the platform channel with keys: `id`, `state`, `schedule`, `countdownDuration`, `label`, `tintColor`, `metadata`. ### Returns - **Alarm** — A new instance deserialized from the map. ### Example ```dart // From getAlarms() final alarms = await FlutterAlarmkit().getAlarms(); for (final alarm in alarms) { print('Alarm: ${alarm.id}'); } // From alarmUpdates() FlutterAlarmkit().alarmUpdates().listen((event) { if (event.alarm case Alarm alarm) { print('Updated: ${alarm.label}'); } }); ``` ``` -------------------------------- ### AlarmButtonConfig Source: https://github.com/gdelataillade/flutter_alarmkit/blob/main/_autodocs/types.md Configuration for a single button displayed in an alarm's Live Activity. ```APIDOC ## Class: AlarmButtonConfig ### Description Defines the properties for a single button that can be displayed within an alarm's Live Activity. ### Fields - **text** (String) - Required - The text to display on the button. - **icon** (String) - Required - The icon to display on the button. - **textColor** (String?) - Optional - The color of the button text. - **tintColor** (String?) - Optional - The tint color of the button icon. ```