伙计们,我会尝试在单击时更改按钮上的文本...
我的代码:
bool pressGeoON = false;
bool cmbscritta = false;
RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)),
color: pressGeoON ? Colors.blue: Colors.red,
textColor: Colors.white,
child: cmbscritta ? Text("GeoOn"): Text("GeoOFF"),
// style: TextStyle(fontSize: 14)
onPressed: () {
setState(() => pressGeoON = !pressGeoON);
setState(() => cmbscritta = !cmbscritta);
},
)
没有来自 dart Analysis 的建议,但不起作用...帮助!
你的类必须是有状态的改变状态活动的
该变量也必须全局声明
class MyClass extends StatefulWidget {
@override
_MyClassState createState() => _MyClassState();
}
class _MyClassState extends State<MyClass> {
bool pressGeoON = false;
bool cmbscritta = false;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RaisedButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(18.0),
side: BorderSide(color: Colors.red)),
color: pressGeoON ? Colors.blue : Colors.red,
textColor: Colors.white,
child: cmbscritta ? Text("GeoOn") : Text("GeoOFF"),
// style: TextStyle(fontSize: 14)
onPressed: () {
setState(() {
pressGeoON = !pressGeoON;
cmbscritta = !cmbscritta;
});
}
),
),
);
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)