相关疑难解决方法(0)

错误:在初始化程序中只能访问静态成员,这是什么意思?

我有类似的东西.我很难理解这个错误.为何访问filterController此处会出现此错误?但是如果我TextFormField在构建方法中移动当前的整个创建(在注释A和B之间),它不会出现此错误?如何移动TextFormField构建方法中的整个内部使filterController静态然后解决此问题?

class AppHomeState extends State<AppHome> with SingleTickerProviderStateMixin
{

    TabController _tabController;
    final filterController = new TextEditingController(text: "Search");
        //----A
        TextFormField email = new TextFormField(
        keyboardType: TextInputType.emailAddress,
        controller: filterController,    ------>ERROR : Error: Only static members can be accessed in initializers
        );
       //----B

  @override
    Widget build(BuildContext context)
    {
        return new Scaffold(
                appBar: new AppBar(..),
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

dart flutter

24
推荐指数
2
解决办法
2万
查看次数

标签 统计

dart ×1

flutter ×1