我们可以在 initState 中使用小部件数据吗?
下面是我制作的日历状态类的代码片段。我的问题是,我可以将下面的 initState 中的 eventDateList 作为“widget.eventDateList”访问吗?!
class Calendar extends StatefulWidget {
final List<DateTime> eventDateList;
final void Function(DateTime, List<Event>) onDayPressed;
final DateTime selectedDate;
bool isReserved;
Calendar(
{required this.eventDateList,
required this.onDayPressed,
required this.selectedDate,
this.isReserved = false});
@override
_CalendarState createState() => _CalendarState();
}
class _CalendarState extends State<Calendar> {
DateTime _currentDate = DateTime.now();
String _currentMonth = DateFormat.yMMM().format(DateTime.now());
DateTime _targetDateTime = DateTime.now();
EventList<Event> _markedDateMap=new EventList<Event>(
events: {},
);
@override
void initState() {
super.initState();
}
Below is a code snippet of the Calendar stateful class I made.My question is, can I access the eventDateList inside the initState below as "widget.eventDateList"?!
class Calendar extends StatefulWidget {
final List<DateTime> eventDateList;
final void Function(DateTime, List<Event>) onDayPressed;
final DateTime selectedDate;
bool isReserved;
Calendar(
{required this.eventDateList,
required this.onDayPressed,
required this.selectedDate,
this.isReserved = false});
@override
_CalendarState createState() => _CalendarState();
}
class _CalendarState extends State<Calendar> {
DateTime _currentDate = DateTime.now();
String _currentMonth = DateFormat.yMMM().format(DateTime.now());
DateTime _targetDateTime = DateTime.now();
EventList<Event> _markedDateMap=new EventList<Event>(
events: {},
);
@override
void initState() {
super.initState();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你可以。可以在initstate中访问如下:
Yes you can. You can access in initstate as follows: