No Material widget found

后端 未结 5 960
轮回少年
轮回少年 2020-12-24 00:11

I am new to Flutter and I was trying do execute the example here. I just want to use the TextField widget to get some user input. The issue is that I get a \"No Material wid

5条回答
  •  醉酒成梦
    2020-12-24 01:00

    Put your widget inside a Scaffold, like this:

        import 'package:flutter/material.dart';
    
        void main() => runApp(MyApp());
    
        class MyApp extends StatelessWidget {
          @override
          Widget build(BuildContext context) {
            return MaterialApp(
              title: 'Demo',
              //home: MyWidget(), --> do not do this !!!
              home: Home() --> this will wrap it in Scaffold
            );
          }
        }
    
        class Home extends StatelessWidget {
          @override
          Widget build(BuildContext context) {
            return Scaffold(
                appBar: AppBar(
                  title: Text('Demo'),
                ),
                body: MyWidget()); --> put your widget here
          }
        }
    
    class MyWidget extends StatefulWidget {
    ...
    

提交回复
热议问题