Reputation: 77
void getCalendarEvents(DateTime t1,DateTime t2) async {
DateTime start = t1.subtract(new Duration(days: 10)).toUtc ();
DateTime end = t1.subtract(new Duration(days: 9)).toUtc ();
final authHeaders = await _currentUser.authHeaders;
final httpClient = new GoogleHttpClient(authHeaders);
CalendarApi calendarApi = CalendarApi(httpClient);
var calEvents = calendarApi.events.list("primary",timeMin: start,timeMax: end,);
calEvents.then((Events events) {
events.items.forEach((Event event) {print(event.summary);});
});
}
I get events in console so how i can display event on the mobile screen. I want to display event fields like "summary", "description", "location", "start", "end", etc.. on the mobile screen.
Upvotes: 1
Views: 856
Reputation: 70
You have to stock them in a list, like that:
initiate your list at the after the imported library like so:
var val = [];
then you stock them like this:
calEvents.then(
(events) => {events.items.forEach((event) => val.add(event.summary) ) }, ,
);
after, you're able to access the value on the Page you want by calling them like that:
Let's do in a list view for example,
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.fromLTRB(20, 8.0, 4, 0),
child: ListView.separated(
itemBuilder: (BuildContext context, int index) {
return Container(
height: 50,
child: Row(
children: <Widget>[
Align(
alignment: Alignment.centerLeft,
child: Text('${val[index]}'),
),
],
),
);
},
separatorBuilder: (BuildContext context, int index) =>
const Divider(),
itemCount: val.length),
));
}
Upvotes: 3