我需要更改高架按钮的背景 colored颜色 ,单击以将其指示为选中.我已经试过这个了.
class _MyState extends State<MyPage> {
bool _flag = true;
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ElevatedButton(
onPressed: () => setState(() => _flag = !_flag),
child: Text(_flag ? 'Red' : 'Green'),
style: ElevatedButton.styleFrom(
backgroundColor: _flag ? Colors.red : Colors.teal,
),
),
),
);
}
}
在onPressed()上: colored颜色 没有改变