Skip to content

Instantly share code, notes, and snippets.

@marcos-bah
Last active November 18, 2020 13:21
Show Gist options
  • Save marcos-bah/bdeb6bd1d038200e922fa08314707395 to your computer and use it in GitHub Desktop.
Save marcos-bah/bdeb6bd1d038200e922fa08314707395 to your computer and use it in GitHub Desktop.
code below
//inserir evento
Future<dynamic> insertEvent(CalendarStore calendarStore) async {
Map<String, String> eventData;
String calendarId;
v3.Event event = v3.Event();
event.summary = calendarStore.title;
event.description = calendarStore.description;
event.attendees = calendarStore.destiny;
event.location = calendarStore.location;
if (calendarStore.hasConferenceSupport) {
v3.ConferenceData conferenceData = v3.ConferenceData();
v3.CreateConferenceRequest conferenceRequest = v3.CreateConferenceRequest();
conferenceRequest.requestId =
"${DateTime.parse(calendarStore.startTime).millisecondsSinceEpoch}-${DateTime.parse(calendarStore.endTime).millisecondsSinceEpoch}";
conferenceData.createRequest = conferenceRequest;
event.conferenceData = conferenceData;
}
v3.EventDateTime start = new v3.EventDateTime();
start.dateTime = DateTime.parse(calendarStore.startTime);
start.timeZone = "GMT-03:00";
event.start = start;
v3.EventDateTime end = new v3.EventDateTime();
end.timeZone = "GMT-03:00";
end.dateTime = DateTime.parse(calendarStore.endTime);
event.end = end;
try {
await clientViaUserConsent(
calendarStore.clientID, calendarStore.scopes, prompt)
.then((AuthClient client) { //como criar isso sem clientViaUserConsent? :(
var calendar = v3.CalendarApi(client);
calendar.events
.insert(event, calendarId,
conferenceDataVersion:
calendarStore.hasConferenceSupport ? 1 : 0,
sendUpdates:
calendarStore.shouldNotifyAttendees ? "all" : "none")
.then((value) {
print("Event Status: ${value.status}");
if (value.status == "confirmed") {
String joiningLink;
String eventId;
eventId = value.id;
if (calendarStore.hasConferenceSupport) {
joiningLink =
"https://meet.google.com/${value.conferenceData.conferenceId}";
calendarStore.setUrl(joiningLink);
}
eventData = {'id': eventId, 'link': joiningLink};
print('Event added to Google Calendar');
calendarStore.setEventDatabase(eventId);
} else {
print("Unable to add event to Google Calendar");
}
});
}
} catch (e) {
print('Error creating event \n\n\n$e');
}
return eventData;
}
dynamic prompt(String url) async {
print("Please go to the following URL and grant access:");
print(" => $url");
print("");
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment