Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter android_alarm_manager without firebase auth

I'm trying to use the Flutter android_alarm_manager to create some background tasks but can't seem to get it working without the firebase auth. I followed the readme on the plugin, but just adding the android_alarm_manager plugin in the pubspec.yaml causes the app to crash immediately (emulator and real device) on startup. How can I avoid the Firebase integration and still use the alarm manager plugin?

like image 682
indijanc Avatar asked Nov 08 '22 02:11

indijanc


1 Answers

Re: but can't seem to get it working without the firebase auth

Maybe at the time of your attempt back in 2018, there was some unintended entangling or some other issue in your app, but as of now, https://pub.dev/packages/android_alarm_manager does not require any Firebase.

Just need to set up some permissions, a service, and receivers in the manifest, then this sample is runnable:

import 'package:android_alarm_manager/android_alarm_manager.dart';

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

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

Also see /flutter/android_alarm_manager/example/

like image 72
TWL Avatar answered Nov 16 '22 12:11

TWL