如何使用构造函数在有状态的小部件中传递数据?

问题描述

我是新手,我想我错过了一些有关构造函数和有状态小部件的信息。我尝试了很多方法,但始终会出错。我只想将数据传递到有状态的小部件中以从那里进行操作。

这是我的错误

The instance member 'widget' can't be accessed in an initializer.
Try replacing the reference to the instance member with a different expression

这是我的代码

class CreateEducatorEventForm extends StatefulWidget {
  final DateTime day = DateTime.now();
  final String favoriteId = '';

  CreateEducatorEventForm(DateTime day,String favoriteId);

  @override
  _CreateEducatorEventFormState createState() =>
      _CreateEducatorEventFormState();
}

class _CreateEducatorEventFormState extends State<CreateEducatorEventForm> {
  final _formKey = GlobalKey<FormState>();
  bool _isLoading = false;
  String _eventName = '';
  String _eventDescription = '';
  DateTime _eventDateStart = widget.day;
  DateTime _eventDateFinish = widget.day;

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)