temp_alarm_manager 0.2.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 68

android_alarm_manager #

pub package

A Flutter plugin for accessing the Android AlarmManager service, and running Dart code in the background when alarms fire.

Getting Started #

After importing this plugin to your project as usual, add the following to your AndroidManifest.xml:


Then in Dart code add:

import 'package:android_alarm_manager/android_alarm_manager.dart';

void printHello() {
  final DateTime now = new DateTime.now();
  final int isolateId = Isolate.current.hashCode;
  print("[$now] Hello, world! isolate=${isolateId} function='$printHello'");

main() async {
  final int helloAlarmID = 0;
  await AndroidAlarmManager.periodic(const Duration(minutes: 1), helloAlarmID, printHello);

printHello will then run (roughly) every minute, even if the main app ends. However, printHello will not run in the same isolate as the main application. Unlike threads, isolates do not share memory and communication between isolates must be done via message passing (see more documentation on isolates here).

If alarm callbacks will need access to other Flutter plugins, including the alarm manager plugin itself, it is necessary to teach the background service how to initialize plugins. This is done by giving the AlarmService a callback to call in the application's onCreate method. See the example's Application overrides. In particular, its Application class is as follows:

public class Application extends FlutterApplication implements PluginRegistrantCallback {
  public void onCreate() {

  public void registerWith(PluginRegistry registry) {

Which must be reflected in the application's AndroidManifest.xml. E.g.:


For help getting started with Flutter, view our online documentation.

For help on editing plugin code, view the documentation.

0.2.0 #

  • Breaking change. A new isolate is always spawned for the background service instead of trying to share an existing isolate owned by the application.
  • Breaking change. Removed AlarmService.getSharedFlutterView.

0.1.1 #

  • Updated Gradle tooling to match Android Studio 3.1.2.

0.1.0 #

  • Breaking change. Set SDK constraints to match the Flutter beta release.

0.0.5 #

  • Simplified and upgraded Android project template to Android SDK 27.
  • Moved Android package to io.flutter.plugins.

0.0.4 #

  • Breaking change. Upgraded to Gradle 4.1 and Android Studio Gradle plugin 3.0.1. Older Flutter projects need to upgrade their Gradle setup as well in order to use this version of the plugin. Instructions can be found here.

0.0.3 #

  • Adds use of a Firebase plugin to the example. The example also now demonstrates overriding the Application's onCreate method so that the AlarmService can initialize plugin connections.

0.0.2 #

  • Add FLT prefix to iOS types.

0.0.1 #

  • Initial release.


// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:async';
import 'dart:isolate';

import 'package:android_alarm_manager/android_alarm_manager.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/widgets.dart';

final FirebaseAuth firebaseAuth = FirebaseAuth.instance;
FirebaseUser firebaseUser;

Future<Null> ensureFirebaseUser() async {
  if (firebaseUser == null) {
    firebaseUser = await firebaseAuth.currentUser();
    if (firebaseUser == null) {
      firebaseUser = await firebaseAuth.signInAnonymously();

class HelloMessage {
  final DateTime _now;
  final String _msg;
  final int _isolate;
  final FirebaseUser _user;
  final String _token;

  HelloMessage(this._now, this._msg, this._isolate, this._user, this._token);

  String toString() {
    return "[$_now] $_msg "
        "isolate=$_isolate "
        "user='$_user' "

void printHelloMessage(String msg) {
  ensureFirebaseUser().then((_) {
    firebaseUser.getIdToken().then((String idToken) {
      print(new HelloMessage(
        new DateTime.now(),

void printHello() {
  printHelloMessage("Hello, world!");

void printGoodbye() {
  printHelloMessage("Goodbye, world!");

bool oneShotFired = false;

void printOneShot() {
  printHelloMessage("Hello, once!");

Future<Null> main() async {
  final int helloAlarmID = 0;
  final int goodbyeAlarmID = 1;
  final int oneShotID = 2;

  // Start the AlarmManager service.
  await AndroidAlarmManager.initialize();

  printHelloMessage("Hello, main()!");
  runApp(const Center(
      child: Text('Hello, world!', textDirection: TextDirection.ltr)));
  await AndroidAlarmManager.periodic(
      const Duration(seconds: 5), helloAlarmID, printHello,
      wakeup: true);
  await AndroidAlarmManager.oneShot(
      const Duration(seconds: 5), goodbyeAlarmID, printGoodbye);
  if (!oneShotFired) {
    await AndroidAlarmManager.oneShot(
        const Duration(seconds: 5), oneShotID, printOneShot);

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  temp_alarm_manager: ^0.2.1

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:temp_alarm_manager/android_alarm_manager.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.8

Maintenance suggestions

Package is getting outdated. (-52.33 points)

The package was last published 79 weeks ago.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8