Im trying to use plugin Android Alarm Manager for timer and code execution in background, but cant really get it working right. If i set something like "print("v")" as a callback - everything works fine, but when Im trying to do something extra, it just doesn't work.
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:android_alarm_manager/android_alarm_manager.dart';
import 'dart:isolate';
class MyApp extends StatefulWidget {
_MyAppState createState() => _MyAppState();
}
startTimer(sendport) async {
await AndroidAlarmManager.oneShot(
Duration(seconds: 60), 0, timerCallback(sendport),
wakeup: true, exact: true);
}
timerCallback(sendport) {
sendport.send("DONE");
}
class _MyAppState extends State<MyApp> {
ReceivePort receivePort = ReceivePort();
SendPort sendport;
@override
void initState() {
super.initState();
AndroidAlarmManager.initialize();
receivePort.listen((v) {
print(v);
});
}
@override
Widget build(BuildContext context) {
RaisedButton(
onPressed: startTimer(sendport),
child: Text("Start"),
);
}
}
I expect that code to send message after 1 minute, instead im getting message right after execution and get Error "/flutter (11424): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: 'dart:ui/plugins.dart': Failed assertion: line 62: '': 'callback' must not be null."