为什么无线电按钮不更改颜色打开的颜色-Flutter?
我的底部模态表中有2个自定义的无线电按钮。当我单击Onpressed
方法时,它们不会立即更改颜色。关闭并再次打开模态菜单后,将正确设置颜色。
Widget customRadio(String text, int index){
return OutlinedButton(
onPressed: () {
setState((){
selected = index;
});
},
child: Text(
text, style: TextStyle(color: (selected == index) ?Colors.white: Colors.grey),
),
style: OutlinedButton.styleFrom(
primary: Colors.white,
backgroundColor: (selected == index)?Colors.deepOrange: Colors.white,
),
);
}
I have 2 custom radio buttons inside my bottom modal sheet. when i click onPressed
method, they don't change color instantly. After I close and open again the modal menu, color is set properly.
Widget customRadio(String text, int index){
return OutlinedButton(
onPressed: () {
setState((){
selected = index;
});
},
child: Text(
text, style: TextStyle(color: (selected == index) ?Colors.white: Colors.grey),
),
style: OutlinedButton.styleFrom(
primary: Colors.white,
backgroundColor: (selected == index)?Colors.deepOrange: Colors.white,
),
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
创建新的
statefulwidget
widget bottomSheet ,addint selected = 0;
移动到dialogStatefull
尝试此演示;
Create new
statefulWidget
for widgetBottomSheet
, addint selected = 0;
move toDialogStatefull
Try this demo;
如果您需要在同一屏幕上的底部表格,那么您需要使用statefulbuilder与statateSetter argumen一起使用
该函数,作为小部件中的参数,您需要更改UI,
这是底部的底部发言
If you want bottomsheet on same screen then you need to use StatefulBuilder with StateSetter argumen
pass the function as argument in your widget that you need to change the ui
here is the bottomsheet with list of widgets