我被桌面日历困住了。 在 Android Studio 中,我收到以下错误:
The following NoSuchMethodError was thrown building StreamBuilder<List<AppEvent>>(dirty, state: _StreamBuilderBaseState<List<AppEvent>, AsyncSnapshot<List<AppEvent>>>#c5581):
The getter 'weekday' was called on null.
Receiver: null
Tried calling: weekday
这是我的代码:如果有必要,我可以发布更多代码,例如类。 其他代码完美运行。即使在应用程序的红色问题屏幕中,我也可以触发浮动按钮并添加事件。但是我再也看不到日历导致红色问题屏幕。
import 'package:app_tennis_sv_schwaig/kalender/add_event.dart';
import 'package:app_tennis_sv_schwaig/kalender/event_details.dart';
import 'package:app_tennis_sv_schwaig/kalender/event_firestore_service.dart';
import 'package:app_tennis_sv_schwaig/kalender/app_event.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
import 'package:table_calendar/table_calendar.dart';
class TennisKalender extends StatefulWidget {
@override
_TennisKalenderState createState() => _TennisKalenderState();
}
class _TennisKalenderState extends State<TennisKalender> {
CalendarController _calendarController = CalendarController();
Map<DateTime, List<AppEvent>> _groupedEvents;
_groupEvents(List<AppEvent> events) {
_groupedEvents = {};
events.forEach((event) {
DateTime date =
DateTime.utc(event.date.year, event.date.month, event.date.day, 12);
if (_groupedEvents[date] == null) _groupedEvents[date] = [];
_groupedEvents[date].add(event);
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.orange,
appBar: AppBar(
backgroundColor: Colors.red,
title: Text("Tenniskalender"),
actions: <Widget>[
IconButton(
icon: Icon(Icons.person),
onPressed: (null),
)
],
),
body: SingleChildScrollView(
child: StreamBuilder(
stream: eventDBS.streamList(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasData) {
final events = snapshot.data;
_groupEvents(events);
DateTime selectedDate = _calendarController.selectedDay;
final _selectedEvents = _groupedEvents[selectedDate] ?? [];
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Card(
clipBehavior: Clip.antiAlias,
margin: const EdgeInsets.all(8.0),
child: TableCalendar(
calendarController: _calendarController,
events: _groupedEvents,
onDaySelected: (date, events, holidays) {
setState(() {});
},
startingDayOfWeek: StartingDayOfWeek.monday,
headerStyle: HeaderStyle(
decoration: BoxDecoration(
color: Colors.red,
),
headerMargin: const EdgeInsets.only(bottom: 8.0),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 12.0, top: 8.0),
child: Text(
DateFormat('EEEE, dd MMMM, yyyy').format(selectedDate),
style: Theme.of(context).textTheme.headline6,
),
),
ListView.builder(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
itemCount: _selectedEvents.length,
itemBuilder: (BuildContext context, int index) {
AppEvent event = _selectedEvents[index];
return ListTile(
title: Text(event.title),
subtitle: Text(DateFormat("EEEE, dd MMMM, yyyy")
.format(event.date)),
onTap: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => EventDetails(
event: event,
)),
);
},
trailing: IconButton(
icon: Icon(Icons.edit),
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => AddEventPage(
event: event,
)));
},
));
},
),
],
);
}
return CircularProgressIndicator();
},
),
),
floatingActionButton: FloatingActionButton(
child: Icon(
Icons.add,
color: Colors.grey[900],
),
backgroundColor: Colors.yellow,
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => AddEventPage(
selectedDate: _calendarController.selectedDay,
),
),
);
}),
);
}
}
我不明白工作日写为空的地方。 你能帮忙吗?非常感谢!
答案 0 :(得分:0)
我解决了。事实上,其他人也有类似的问题,这是我的解决方案。
DateFormat
中的 ListTile
中的 ListView.builder
是问题所在。不知道为什么,但我删除了它,因为无论如何都不需要应用程序中的视图。
错误命令:
subtitle: Text(DateFormat("EEEE, dd MMMM, yyyy").format(event.date)),