问题
Flutter, Google Calendar API v3 https://pub.dartlang.org/packages/googleapis
Works:
Future<List<Event>> getEvents() =>
calendarApi.events.list("primary",
)
.then((Events events){
return events.items;
}).catchError((e){
print("error encountered");
print("${e.toString()}");
});
Doesn't work:
DateTime start = new DateTime.now().subtract(new Duration(days: 10));
DateTime end = new DateTime.now().add(new Duration(days: 10));
..
Future<List<Event>> getEvents() =>
calendarApi.events.list("primary",
timeMin: start,
timeMax: end,
)
.then((Events events){
return events.items;
}).catchError((e){
print("error encountered");
print("${e.toString()}");
});
Why?
回答1:
According to the Google calendar API the timeMin and timeMax values must follow the RFC3339 date standard.
Internally the calendar applies .toIso8601String()
on the DateTimes you pass in. However that does not make them valid RFC3339 dates.
Calling .toUtc()
before passing them in will make them a valid RFC3339. You can try it in DartPad togheter with Googles Api explorer and you will see the different responses.
There is probably more ways to make DateTime RFC3339 compliant but this should point you to the error atleast.
来源:https://stackoverflow.com/questions/49724445/flutter-google-calendar-api-list-events