为什么在第9行出现错误,未使用字段_maintext的值?

时间:2019-05-09 18:04:08

标签: flutter

我只用2个按钮编写了一个代码,按下这些按钮可以更改屏幕上居中的卡片小部件上的文本。很好然后尝试将这2个按钮提取到不同的widdget中的另一个dart文件中(只是为了练习,我是一个新手),但是会在第9行显示绿色下划线。

class Buttons extends StatefulWidget {
  @override
  _ButtonsState createState() => _ButtonsState();
}

class _ButtonsState extends State<Buttons> {
 String _maintext;
  @override
  Widget build(BuildContext context) {

    return Container(
                height: 200,
                child: Row(children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.only(left: 50),
                    child: Icon(Icons.favorite, color: Colors.white70),
                  ),
                  RaisedButton(
                    splashColor: Colors.greenAccent,
                    color: Colors.green,
                    highlightElevation: 100,
                    onPressed: () {
                      setState(() {
                        _maintext = "Κι εγώ!";
                      });
                    },
                    child: Text("Ναι!!"),
                  ),
                  Icon(Icons.favorite, color: Colors.white70),
                  Padding(
                    padding: const EdgeInsets.only(left: 25),
                    child: Icon(
                      Icons.do_not_disturb_on,
                      color: Colors.white70,
                    ),
                  ),
                  RaisedButton(
                    color: Colors.red,
                    splashColor: Colors.redAccent,
                    elevation: 50,
                    highlightElevation: 100,
                    onPressed: () {
                      setState(() {
                        _maintext = ":(";
                      });
                    },
                    child: Text("Οχι....."),
                  ),
                  Icon(
                    Icons.do_not_disturb_on,
                    color: Colors.white70,
                  )]));
  }}

0 个答案:

没有答案