Flutter background alarm trigger

A flutter plugin for Android to launch app from background at specific time just like stock alarm app in Android


flutter_alarm_background_trigger: ^1.0.0
# or
flutter pub add flutter_alarm_background_trigger


void main() {
  // Very important to call before initialize since it 
  // ensures the binding is available and ready before 
  // any native call

  // initialize Required for alarm events to bind with flutter method channel

  runApp(const MyApp());

Create instance

var alarmPlugin = FlutterAlarmBackgroundTrigger();

Set Alarm

      // Required
      DateTime.now().add(Duration(seconds: 10)),

      payload: {"YOUR_EXTRA_DATA":"FOR_ALARM"},

      // screenWakeDuration: For how much time you want 
      // to make screen awake when alarm triggered
      screenWakeDuration: Duration(minutes: 1)

Receive event when alarm trigger

      // Perform your action here such as navigation
      // This event will be triggered on both cases, 
      // when app is in foreground or background!

Additional methods

Request permission to draw over other apps

Future<bool> requestPermission()


Future<AlarmItem> addAlarm(
  DateTime time, 
    String? uid, 
    Map<String, dynamic>? payload, 
    Duration screenWakeDuration

Get alarm by uid

Future<List<AlarmItem>> getAlarmByUid(String uid)

Get all scheduled alarms

Future<List<AlarmItem>> getAllAlarms()

Get single alarm

Future<AlarmItem> getAlarm(int id)

Get alarm by payload

Future<List<AlarmItem>> getAlarmByPayload(Map<String, dynamic> payload)

Get alarm by time

Future<List<AlarmItem>> getAlarmByTime(DateTime time)

Alarm trigger event

void onForegroundAlarmEventHandler(OnForegroundAlarmEvent alarmEvent)

Delete single alarm

Future<void> deleteAlarm(int id)

Delete by payload

Future<void> deleteAlarmsByPayload(Map<String, dynamic> payload)

Delete by time

Future<void> deleteAlarmsByTime(DateTime dateTime)

Delete by uid

Future<void> deleteAlarmsByUid(String uid)

Delete all scheduled alarms

Future<void> deleteAllAlarms()