问题描述
我正在使用 VS Code 在 Flutter 中设置 TextField 小部件,但在 TextFormField 上出现此错误:
No Material widget found.
TextField widgets require a Material widget ancestor.
I/flutter ( 3827): In material design,most widgets are conceptually "printed" on a sheet of material. In Flutter's
I/flutter ( 3827): material library,that material is represented by the Material widget. It is the Material widget
I/flutter ( 3827): that renders ink splashes,for instance. Because of this,many material library widgets require that
I/flutter ( 3827): there be a Material widget in the tree above them.
I/flutter ( 3827): To introduce a Material widget,you can either directly include one,or use a widget that contains
I/flutter ( 3827): Material itself,such as a Card,Dialog,Drawer,or Scaffold.
I/flutter ( 3827): The specific widget that could not find a Material ancestor was:
I/flutter ( 3827): TextField
I/flutter ( 3827): The ancestors of this widget were:
I/flutter ( 3827): ...
I/flutter ( 3827): TextFormField
I/flutter ( 3827): Column
I/flutter ( 3827): Padding
I/flutter ( 3827): Padding
I/flutter ( 3827): Container
TextFormField 的代码是:
TextFormField txtEmail(String title,IconData icon) {
return TextFormField(
controller: emailController,style: TextStyle(color: Colors.white70),decoration: InputDecoration(
hintText: title,hintStyle: TextStyle(color: Colors.white70),icon: Icon(icon)),);
}
实际上我在此调用 txtEmail:
Container textSection() {
return Container(
padding: EdgeInsets.symmetric(horizontal: 20.0),margin: EdgeInsets.only(top: 30.0),child: Column(
children: <Widget>[
txtEmail("Email",Icons.email),SizedBox(height: 30.0),txtPassword("Password",Icons.lock),],),);
}
是什么原因?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)