【发布时间】:2021-05-10 08:36:50
【问题描述】:
这是我目前正在使用的颤振日历小部件的代码:
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Calendar"),
),
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection('Events').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return Text('Loading data... Please Wait');
print(snapshot.data.documents['name']);
return Column(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
_buildTableCalendar(context, snapshot),
const SizedBox(height: 8.0),
Expanded(child: _buildEventList()),
],
);
}));
}
Widget _buildTableCalendar(BuildContext context, AsyncSnapshot snapshot) {
return TableCalendar(
calendarController: _controller,
events: _events,
holidays: _holidays,
startingDayOfWeek: StartingDayOfWeek.monday,
calendarStyle: CalendarStyle(
selectedColor: Colors.purple[400],
todayColor: Colors.purple[200],
markersColor: Colors.purple[700],
outsideDaysVisible: false,
),
headerStyle: HeaderStyle(
formatButtonTextStyle:
TextStyle().copyWith(color: Colors.white, fontSize: 15.0),
formatButtonDecoration: BoxDecoration(
color: Colors.purple[400],
borderRadius: BorderRadius.circular(16.0),
),
),
onDaySelected: _onDaySelected,
onVisibleDaysChanged: _onVisibleDaysChanged,
onCalendarCreated: _onCalendarCreated,
);
}
我目前只是尝试打印快照的内容,因为我不太确定如何将事件信息输入代码,但我不断收到type 'String' is not a subtype of type 'int' of 'index' 错误。如果有人能够发现任何问题,那就太好了!
【问题讨论】: