No Material widget found

后端 未结 5 964
轮回少年
轮回少年 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 00:48

    The error message says:

    To introduce a Material widget, you can either directly include one, or use a widget that contains Material itself, such as a Card, Dialog, Drawer, or Scaffold.

    In your case, I'd probably wrap your Column in a Scaffold. This will make it easy to add other material widgets to your app later, such as an AppBar, Drawer, or FloatingActionButton.

    @override
    Widget build(BuildContext context) {
      return new Scaffold(
        body: new Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            new TextField(
                controller: _controller,
                decoration: new InputDecoration(
                    hintText: 'Type something',
                ),
            ),
            new RaisedButton(
                onPressed: () {
                  showDialog(
                      context: context,
                      child: new AlertDialog(
                          title: new Text('What you typed'),
                          content: new Text(_controller.text),
                      ),
                  );
                },
                child: new Text('DONE'),
            ),
          ],
        ),
      );
    }
    

提交回复
热议问题