我只用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,
)]));
}}