Moh*_*min 10 notifications flutter
我正在尝试安排通知:但我收到此错误:
未处理的异常:在初始化时区数据库之前尝试获取位置
虽然我在 init 函数中初始化了时区:
tz.initializeTimeZones();
Run Code Online (Sandbox Code Playgroud)
时间表代码:
Future<void> scheduleNotifications(String title,int yy,int mm,int dd,int hh,int ii) async {
final loc_egypt = tz.getLocation('Africa/Cairo');
final tz.TZDateTime now = tz.TZDateTime.now(loc_egypt);
var schedule_30before=tz.TZDateTime(loc_egypt,yy,mm,dd,hh,ii).subtract(Duration(minutes: 30));
await flutterLocalNotificationsPlugin.zonedSchedule(
0,
title,
"The Webinar will start after 30 minutes",
schedule_30before,
NotificationDetails(android: _androidNotificationDetails),
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
}
Run Code Online (Sandbox Code Playgroud)
您需要导入以下包:
import 'package:timezone/data/latest.dart' as tzl;
import 'package:timezone/standalone.dart' as tz;
Run Code Online (Sandbox Code Playgroud)
然后,您可以调用例如:
ElevatedButton(
onPressed: ()async {
await scheduleNotifications("title", 2022, 9, 1, 1, 47);
},
child: Text("Notify Me!"))
Run Code Online (Sandbox Code Playgroud)
鉴于您输入tzl.initializeTimeZones();
了 initState()。
您的问题是使用initializeTimeZones()
与以下不同的包"package:timezone/data/latest.dart"