flutter中将字符串日期时间转换为DateTime类型

Nab*_*man 1 dart flutter

我想将日期和时间合并为日期时间格式。这样我就可以用它来发送本地通知。我从 firebase 中分别获取时间和日期作为约会日期和约会时间:

在此输入图像描述

使用此代码:

for (int i = 0; i < appt_list.length; i++) {
          
            String name = appt_list[i].docName;
            String k = appt_list[i].key;
            Provider.of<NotificationService>(context, listen: false)
                .sheduledNotification(datetime, name, k);
          }
Run Code Online (Sandbox Code Playgroud)

我想在本地通知函数中使用自定义(存储在 firebase 中用于约会提醒的值)时间日期,例如使用“scheduledNotificationDateTime”变量正在执行的操作:

Future sheduleddateNotification(DateTime datetime, String name, String key) async {
    var scheduledNotificationDateTime = DateTime.now().add(Duration(seconds: 5));
    var androidPlatformChannelSpecifics =
    AndroidNotificationDetails(key,
        'your other channel name', 'your other channel description');
    var iOSPlatformChannelSpecifics =
    IOSNotificationDetails();
    NotificationDetails platformChannelSpecifics = NotificationDetails(
        androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
    await _flutterLocalNotificationsPlugin.schedule(
        0,
        'Reminder Appointment',
        'You have an appointment scheduled with $name at ${(time.hour)}:${(time.minute)}',
        scheduledNotificationDateTime,
        platformChannelSpecifics);
  }
Run Code Online (Sandbox Code Playgroud)

但我不知道如何将日期和时间结合在一起并将它们合而为一!请帮我解决这个问题

HTM*_*ell 6

像这样的事情怎么样?

final String dateTimeString = appointment_date + " " + appointment_time;
final DateFormat format = new DateFormat("yyyy-MM-dd hh:mm a");
print (format.parse(dateTimeString));
Run Code Online (Sandbox Code Playgroud)