微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

没有找到材质小部件颤动与代码

如何解决没有找到材质小部件颤动与代码

我正在使用 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),],),);
  }

是什么原因?

解决方法

我认为您需要一个 Material Widget 作为根对象(例如 MaterialApp)

{1,2}

查看 https://flutter.dev/ 获取教程。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?