简体   繁体   English

未处理的异常:无效参数(scheduledDate):必须是未来的日期:“TZDateTime”的实例

[英]Unhandled Exception: Invalid argument (scheduledDate): Must be a date in the future: Instance of 'TZDateTime'

This is me trying to create a daily scheduled notification using flutter_local_notification.这是我尝试使用 flutter_local_notification 创建每日计划通知。 I've tried changing the time and uses different methods such as using TZDateTime.from instead of TZDateTime.utc and yet it still doesn't fix anything.我尝试更改时间并使用不同的方法,例如使用 TZDateTime.from 而不是 TZDateTime.utc,但它仍然无法解决任何问题。 Here's the code:这是代码:


        import 'package:timezone/data/latest.dart' as tz;
        import 'package:timezone/timezone.dart' as tz;

        \\\

        const platform = const MethodChannel('helper');

        tz.initializeTimeZones();
        final String timeZoneName = 'Asia/Bangkok';
        tz.setLocalLocation(tz.getLocation(timeZoneName));

        final tzTime = tz.TZDateTime.utc(time.year, time.month, time.day, i, time.minute + 1, time.second);

        await flutterLocalNotificationsPlugin.zonedSchedule(
            0,
            'Shouter Clock',
            "It's $dateTime",
            tzTime,
            platformChannelSpecifics,
            payload: "Test",
          androidAllowWhileIdle: true,
          uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
        );

In my opinion, It's throwing this error because of the time which you selected is before than now.在我看来,它抛出这个错误是因为你选择的时间比现在早。 In their pub.dev page, there is an example for solve this problem.在他们的 pub.dev 页面中,有一个解决此问题的示例。

tz.TZDateTime _nextInstanceOfTenAM() {
final tz.TZDateTime now = tz.TZDateTime.now(tz.local);
tz.TZDateTime scheduledDate =
    tz.TZDateTime(tz.local, now.year, now.month, now.day, 10);
if (scheduledDate.isBefore(now)) {
  scheduledDate = scheduledDate.add(const Duration(days: 1));
}
return scheduledDate;
}

It's the example link from their pub.dev page这是他们 pub.dev 页面中的示例链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未处理的异常:无效参数:“未来”的实例<String?> &#39; - Unhandled Exception: Invalid argument: Instance of 'Future<String?>' Dart Error:未处理的异常:E / flutter(5079):无效的参数:&#39;未来的实例 <String> “ - Dart Error: Unhandled exception: E/flutter ( 5079): Invalid argument: Instance of 'Future<String>' DateTime 不是 TimeStamp/Unhandled 异常类型的子类型:无效参数:'Future 的实例<locationdata></locationdata> - DateTime not a subtype of type TimeStamp/Unhandled Exception: Invalid argument: Instance of 'Future<LocationData> 未处理的异常:无效参数:“模型”类的实例 - Unhandled Exception: Invalid argument: Instance of 'Model' class 未处理的异常:无效参数:flutter 中“用户”的实例 - Unhandled Exception: Invalid argument: Instance of 'User' in flutter 未处理的异常:无效参数:“加密”的实例 - Unhandled Exception: Invalid argument: Instance of 'Encrypted' 未处理的异常:无效的参数:“CartItemModel”的实例 - Unhandled Exception: Invalid argument: Instance of 'CartItemModel' 未处理的异常:无效参数:“TextEditingController”的实例 - Unhandled Exception: Invalid argument: Instance of 'TextEditingController' 未处理的异常:无效参数:是一个常规实例:“LocationDto”的实例 - Unhandled Exception: Invalid argument: is a regular instance: Instance of 'LocationDto' Flutter 未处理的异常:无效参数(值):不得为 null - Flutter Unhandled Exception: Invalid argument(s) (value): Must not be null
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM