【发布时间】:2020-12-30 17:22:12
【问题描述】:
我正在使用 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),
],
),
);
}
是什么原因?
【问题讨论】:
标签: flutter dart visual-studio-code widget issue-tracking