TextField widgets require a Material widget ancestor.

flutter在运用

TextField控件的时候出现这个错误的,解决方案:

需要用Scaffold进行包裹

class Loging extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new LogingLess();
  }
}

class LogingLess extends State<Loging> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new MaterialApp(
      title: "loging",
      home: new Scaffold(
        body: new LogingUi(),
      ),
    );
  }
}
class LogingUi extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    var size = MediaQuery.of(context).size;
    // TODO: implement build
    return new TextField(
        //相当于Android属性hint
        decoration: new InputDecoration(
      hintText: "用户名",
    ));
  }
}

猜你喜欢

转载自blog.csdn.net/fl2502923/article/details/89284695