【问题标题】:No Material widget found flutter vs code没有发现材料小部件颤动与代码
【发布时间】: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


    【解决方案1】:

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

    void main() async {
      runApp(
        MaterialApp(
          debugShowCheckedModeBanner: false,
            home: Scaffold(
              body: MyApp(),
            ),
          ),
        );
      }
    

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

    【讨论】:

      猜你喜欢
      • 2021-12-18
      • 2020-05-09
      • 2020-08-18
      • 1970-01-01
      • 2020-09-24
      • 2021-05-18
      • 2020-05-23
      • 2017-05-02
      • 1970-01-01
      相关资源
      最近更新 更多