Android Alarm Clock Plugin for Flutter.

Overview

Android Alarm Clock Plugin for Flutter

pub package

This plugin allows Flutter apps to operate with the default clock application when the platform is Android. Provides a lightweight wrapper around clock app intents. It uses Android intents to communicate with the default clock app.

Currently supported features

  • Create new Alarms
  • Create new Timer
  • Open default Clock app showing Alarms
  • Open default Clock app showing Timers

Usage

Create an Alarm

Create a new alarm. Function arguments:
'hour' specifies alarm hour
'minutes' specifies alarm minutes
'title' specifies alarm title - optional
'skipUi' specifies whether clock app should open or not - optional

// Create an alarm at 23:59
FlutterAlarmClock.createAlarm(23, 59);

Create a Timer

Create a new timer. Function arguments:
'length' specifies timer length in seconds
'title' specifies timer title - optional
'skipUi' specifies whether clock app should open or not - optional

// Create a timer for 42 seconds
FlutterAlarmClock.createTimer(42);

Show Alarms

Opens default clock app showing alarms.

FlutterAlarmClock.showAlarms();

Show Timers

Opens default clock app showing timers.

FlutterAlarmClock.showTimers();

Feel free to add support for additional functionality.

Note that a similar method does not currently exist for iOS.

Platform Support

Android
✔️

Example App

Screenshot

screenshot

Code

import 'package:flutter/material.dart';
import 'package:flutter_alarm_clock/flutter_alarm_clock.dart';


void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter alarm clock example'),
        ),
        body: Center(
            child: Column(children: <Widget>[
          Container(
            margin: const EdgeInsets.all(25),
            child: TextButton(
              child: const Text(
                'Create alarm at 23:59',
                style: TextStyle(fontSize: 20.0),
              ),
              onPressed: () {
                FlutterAlarmClock.createAlarm(23, 59);
              },
            ),
          ),
          Container(
            margin: const EdgeInsets.all(25),
            child: TextButton(
              child: const Text(
                'Show alarms',
                style: TextStyle(fontSize: 20.0),
              ),
              onPressed: () {
                FlutterAlarmClock.showAlarms();
              },
            ),
          ),
          Container(
            margin: const EdgeInsets.all(25),
            child: TextButton(
              child: const Text(
                'Create timer for 42 seconds',
                style: TextStyle(fontSize: 20.0),
              ),
              onPressed: () {
                FlutterAlarmClock.createTimer(42);
              },
            ),
          ),
          Container(
            margin: const EdgeInsets.all(25),
            child: TextButton(
              child: const Text(
                'Show Timers',
                style: TextStyle(fontSize: 20.0),
              ),
              onPressed: () {
                FlutterAlarmClock.showTimers();
              },
            ),
          ),
        ])),
      ),
    );
  }
}

You might also like...
LicensesDialog is an open source library to display licenses of third-party libraries in an Android app.
LicensesDialog is an open source library to display licenses of third-party libraries in an Android app.

LicensesDialog LicensesDialog is an open source library to display licenses of third-party libraries in an Android app. Download Download the latest R

Android library to show
Android library to show "Rate this app" dialog

Android-RateThisApp Android-RateThisApp is an library to show "Rate this app" dialog. The library monitors the following status How many times is the

A small library replicating the new dialogs in android L.
A small library replicating the new dialogs in android L.

L-Dialogs A small library replicating the new dialogs in android L. Set Up (Android Studio): Download the aar here: https://www.dropbox.com/s/276bhapr

A simple file/ directory picker dialog for android
A simple file/ directory picker dialog for android

FileListerDialog FileListerDialog helps you to list and pick file/directory. Library is built for Android Getting Started Installing To use this libra

📱 An Android Library for 💫fluid, 😍beautiful, 🎨custom Dialogs.
📱 An Android Library for 💫fluid, 😍beautiful, 🎨custom Dialogs.

Aesthetic Dialogs for Android 📱 📱 Android Library for 💫 fluid, 😍 beautiful, 🎨 custom Dialogs. Table of Contents: Introduction Types of Dialog Dar

a quick custom android dialog project
a quick custom android dialog project

QustomDialog Qustom helps you make quick custom dialogs for Android. All this is, for the time being, is a way to make it easy to achieve the Holo loo

Android library that allows applications to add dialog-based slider widgets to their settings
Android library that allows applications to add dialog-based slider widgets to their settings

Android Slider Preference Library Overview Slider represents a float between 0.0 and 1.0 Access with SliderPreference.getValue() or SharedPreferences.

An Android library that provides a simple implementation of a DialogFragment

SimpleDialogFragment An Android library that provides a simple implementation of a DialogFragment. Are you tired of creating a new DialogFragment for

GenericDialog 1.3 0.0 Java A new AlertDialog for Android is here...!!
GenericDialog 1.3 0.0 Java A new AlertDialog for Android is here...!!

GenericDialog A new AlertDialog for Android is here...!! Getting Started Installation Add this into your root build.gradle file: allprojects { reposi

Comments
  • while i am using

    while i am using "android_alarm_manager_plus", I failed it to create "createAlarm" in the callback function

    can you tell me what i should do ? please

    Reproducible code:

    import 'package:flutter/material.dart';
    // ignore: depend_on_referenced_packages
    import 'package:android_alarm_manager_plus/android_alarm_manager_plus.dart';
    import 'package:flutter_alarm_clock/flutter_alarm_clock.dart';
    
    void main() async {
      // initialize AlarmClockManager service
    
      runApp(const MyApp());
      await AndroidAlarmManager.initialize();
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({super.key});
    
      // This widget is the root of your application.
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            primarySwatch: Colors.blue,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
      const MyHomePage({super.key, required this.title});
    
      final String title;
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      //  定时器任务
      // Future<void> main() async {
      //   final int periodicId = 0;
      //   final int oneshotId = 0;
      //   final int oneshotAtId = 0;
    
      //   print("main alarm run");
    
      // }
    
      bool isOn = false;
      bool edit = true;
      int alarmId = 1;
      TextEditingController hc = TextEditingController();
      TextEditingController mc = TextEditingController();
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text(widget.title),
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                TextField(
                  enabled: edit,
                  keyboardType: TextInputType.number,
                  decoration: InputDecoration(
                    labelText: "Hour",
                  ),
                  controller: hc,
                ),
                TextField(
                  enabled: edit,
                  keyboardType: TextInputType.number,
                  decoration: InputDecoration(
                    labelText: "minutes",
                  ),
                  controller: mc,
                ),
                Transform.scale(
                  scale: 2,
                  child: Switch(
                      value: isOn,
                      onChanged: ((value) {
                        setState(() {
                          isOn = value;
                          edit = !edit;
                        });
                        if (isOn == true) {
                          var h = hc.text;
                          var m = mc.text;
                          print("$h $m");
                          AndroidAlarmManager.oneShotAt(
                            DateTime(2022, 09, 26, int.parse(h), int.parse(m), 00),
                            alarmId,
                            setAlarmClock,
                            // () => FlutterAlarmClock.createAlarm(23, 59),
    // your code
                          );
                        } else {
                          AndroidAlarmManager.cancel(alarmId);
                          print('Alarm Timer Canceled');
                        }
                      })),
                ),
                TextButton(
                    onPressed: () {
                      setAlarmClock();
                      // FlutterAlarmClock.createAlarm(23, 59);
                    },
                    child: const Text("clock"))
              ],
            ),
          ),
          // This trailing comma makes auto-formatting nicer for build methods.
        );
      }
    }
    
    void setAlarmClock() {
      print('Alarm Fired at ${DateTime.now()}');
      FlutterAlarmClock.createAlarm(23, 59);
    }
    

    issue:

    E/MethodChannel#flutter_alarm_clock(26487): Failed to handle method call E/MethodChannel#flutter_alarm_clock(26487): kotlin.UninitializedPropertyAccessException: lateinit property activity has not been initialized E/MethodChannel#flutter_alarm_clock(26487): at tech.sebastjanmevlja.flutter_alarm_clock.FlutterAlarmClockPlugin.createAlarm(FlutterAlarmClockPlugin.kt:111) E/MethodChannel#flutter_alarm_clock(26487): at tech.sebastjanmevlja.flutter_alarm_clock.FlutterAlarmClockPlugin.onMethodCall(FlutterAlarmClockPlugin.kt:57) E/MethodChannel#flutter_alarm_clock(26487): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/MethodChannel#flutter_alarm_clock(26487): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/MethodChannel#flutter_alarm_clock(26487): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/MethodChannel#flutter_alarm_clock(26487): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/MethodChannel#flutter_alarm_clock(26487): at android.os.Handler.handleCallback(Handler.java:938) E/MethodChannel#flutter_alarm_clock(26487): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#flutter_alarm_clock(26487): at android.os.Looper.loopOnce(Looper.java:233) E/MethodChannel#flutter_alarm_clock(26487): at android.os.Looper.loop(Looper.java:344) E/MethodChannel#flutter_alarm_clock(26487): at android.app.ActivityThread.main(ActivityThread.java:8212) E/MethodChannel#flutter_alarm_clock(26487): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#flutter_alarm_clock(26487): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) E/MethodChannel#flutter_alarm_clock(26487): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) E/flutter (26487): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, lateinit property activity has not been initialized, null, kotlin.UninitializedPropertyAccessException: lateinit property activity has not been initialized E/flutter (26487): at tech.sebastjanmevlja.flutter_alarm_clock.FlutterAlarmClockPlugin.createAlarm(FlutterAlarmClockPlugin.kt:111) E/flutter (26487): at tech.sebastjanmevlja.flutter_alarm_clock.FlutterAlarmClockPlugin.onMethodCall(FlutterAlarmClockPlugin.kt:57) E/flutter (26487): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/flutter (26487): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/flutter (26487): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/flutter (26487): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/flutter (26487): at android.os.Handler.handleCallback(Handler.java:938) E/flutter (26487): at android.os.Handler.dispatchMessage(Handler.java:99) E/flutter (26487): at android.os.Looper.loopOnce(Looper.java:233) E/flutter (26487): at android.os.Looper.loop(Looper.java:344) E/flutter (26487): at android.app.ActivityThread.main(ActivityThread.java:8212) E/flutter (26487): at java.lang.reflect.Method.invoke(Native Method) E/flutter (26487): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584) E/flutter (26487): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034) E/flutter (26487): ) E/flutter (26487): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:653:7) E/flutter (26487): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:296:18) E/flutter (26487): E/flutter (26487):

    bug question 
    opened by boziyoung 2
  • Alarm does not work when phone is locked

    Alarm does not work when phone is locked

    I am calling this function FlutterAlarmClock.createAlarm(16, 39); in my initState() method. The alarm works when the app is open.

    But when it is removed from background or the phone is locked, the alarm does not rung.

    I am testing it on Android 12.

    Any help is highly appreciated. Thank you.

    opened by Intihar12 2
Owner
Sebastjan Mevlja
Enthusiastic Computer Science student. Interested in developing Web and Mobile applications.
Sebastjan Mevlja
Make your native android Dialog Fancy and Gify. A library that takes the standard Android Dialog to the next level with a variety of styling options and Gif's. Style your dialog from code.

FancyGifDialog-Android Prerequisites Add this in your root build.gradle file (not your module build.gradle file): allprojects { repositories { ...

Shashank Singhal 522 Jan 2, 2023
AlertDialog for Android, a beautiful and material alert dialog to use in your android app.

AlertDialog for Android, a beautiful and material alert dialog to use in your android app. Older verion of this library has been removed

Akshay Masram 124 Dec 28, 2022
Android has a built in microphone through which you can capture audio and store it , or play it in your phone. There are many ways to do that but with this dialog you can do all thats with only one dialog.

# Media Recorder Dialog ![](https://img.shields.io/badge/Platform-Android-brightgreen.svg) ![](https://img.shields.io/badge/Android-CustomView-blue.sv

Abdullah Alhazmy 73 Nov 29, 2022
A simple library for creating animated warnings/dialogs/alerts for Android.

Noty A simple library for creating animated warnings/notifications for Android. Examples Show me code Show me code Show me code Show me code Show me c

Emre 144 Nov 29, 2022
Advanced dialog solution for android

DialogPlus Simple and advanced dialog solution. Uses normal view as dialog Provides expandable option Multiple positioning Built-in options for easy i

Orhan Obut 5k Dec 29, 2022
SweetAlert for Android, a beautiful and clever alert dialog

Sweet Alert Dialog SweetAlert for Android, a beautiful and clever alert dialog 中文版 Inspired by JavaScript SweetAlert Demo Download ScreenShot Setup Th

书呆子 7.3k Dec 30, 2022
An Android Dialog Lib simplify customization.

FlycoDialog-Master 中文版 An Android Dialog Lib simplify customization. Supprot 2.2+. Features [Built-in Dialog, convenient to use](#Built-in Dialog) [Ab

Flyco 2.3k Dec 8, 2022
😍 A beautiful, fluid, and extensible dialogs API for Kotlin & Android.

Material Dialogs View Releases and Changelogs Modules The core module is the fundamental module that you need in order to use this library. The others

Aidan Follestad 19.5k Dec 29, 2022
[Deprecated] This project can make it easy to theme and custom Android's dialog. Also provides Holo and Material themes for old devices.

Deprecated Please use android.support.v7.app.AlertDialog of support-v7. AlertDialogPro Why AlertDialogPro? Theming Android's AlertDialog is not an eas

Feng Dai 468 Nov 10, 2022
Android AlertDialog with moving dots progress indicator

Spots progress dialog Android AlertDialog with moving spots progress indicator packed as android library. =========== Usage The library available in m

Maksym Dybarskyi 1.1k Jan 8, 2023