You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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):
The text was updated successfully, but these errors were encountered:
can you tell me what i should do ? please
Reproducible code:
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):
The text was updated successfully, but these errors were encountered: