flutter calendar events
scrolling calendar events list widget for flutter.
shows a scrolling calendar list of events. this is still relatively basic, it always assumes that the getevents returns the entire list of calendar events (mostly ignoring the values passed into the source). it does work however right now it also assumes there is an asset at assets/images/calendarheader.png which it will use to display the header and an asset at assets/images/calendarbanner.jpg which it will use for the month header.
the calendar uses slivers to display the widgets in the view and lets you scroll forward and backward through the events. the header widget will drop down and open up the days of the month, letting you select specific days as well as move back and forth between the months. by default it displays a list of events and not a day view, the day view code is all just a stub right now.
here is how to use the calendar widget itself:
new calendarwidget(
initialdate: new tzdatetime.now(local),
source: _calendarstate,
);
how to setup a source for the calendar widget.
class gamelistcalendarstate extends calendarsource {
list<game> _listtoshow;
streamsubscription<updatereason> _listening;
@override
widget buildwidget(buildcontext context, calendarevent event) {
return new gamecard(_listtoshow[event.index]);
}
@override
list<calendarevent> getevents(datetime start, datetime end) {
if (_listtoshow == null) {
_listtoshow = userdatabasedata.instance.games.values.tolist();
}
if (_listtoshow == null) {
return [];
}
list<calendarevent> events = new list<calendarevent>();
int pos = 0;
_listtoshow.foreach((game g) => events.add(new calendarevent(
instant: g.tztime, instantend: g.tzendtime, index: pos++)));
return events;
}
@override
void initstate() {
_listtoshow = userdatabasedata.instance.games.values.tolist();
_listening = userdatabasedata.instance.gamestream.listen((updatereason r) {
_listtoshow = userdatabasedata.instance.games.values.tolist();
state.updateevents();
});
}
@override
void dispose() {
_listening.cancel();
}
future<void> loadgames(filterdetails details) async {
iterable<game> list = await userdatabasedata.instance.getgames(details);
_setgames(list);
}
void _setgames(iterable<game> res) {
list<game> games = res.tolist();
games.sort((a, b) => a.time.compareto(b.time));
_listtoshow = games;
}
}
example of the calendar widget in action:
Comments are closed.