我有类似的东西.我很难理解这个错误.为何访问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)
我该如何解决这个问题?