Flutter 更改开关-窗体生成器开关-颤振的颜色
如果正常,我想更改开关的颜色,如果已切换。在Material.dart中我找到了一些东西,但写得不对。如果你能举一些例子,那就太好了。多谢各位Flutter 更改开关-窗体生成器开关-颤振的颜色,flutter,android-studio,dart,flutter-layout,flutter-animation,Flutter,Android Studio,Dart,Flutter Layout,Flutter Animation,如果正常,我想更改开关的颜色,如果已切换。在Material.dart中我找到了一些东西,但写得不对。如果你能举一些例子,那就太好了。多谢各位 FormBuilderSwitch( name: "public", title: Text("Wird noch ein Mitspieler gesucht?"), initialValue: widge
FormBuilderSwitch(
name: "public",
title: Text("Wird noch ein Mitspieler gesucht?"),
initialValue: widget.event?.public ?? false,
controlAffinity: ListTileControlAffinity.leading,
decoration: InputDecoration(border: InputBorder.none),
),
你可以用bool来做 例如:
bool switched = false; //Based on which state you want it to be on init
触发开关功能的小部件
FormBuilderSwitch(
onChanged: (bool) {
setState(() {
bool = !bool;
switched = bool;
});
},
)
这是一个基于bool的颜色变化示例
Container(
color: switched? Colors.white : Colors.blue,
)
更新:
这是密码
FormBuilderSwitch(
name: "public",
title: Text("Wird noch ein Mitspieler gesucht?"),
initialValue: false,
controlAffinity: ListTileControlAffinity.leading,
decoration: InputDecoration(border: InputBorder.none),
onChanged: (bool) {
setState(() {
bool = !bool;
switched = bool;
});
},
),
Container(
height: 20,
width: 20,
color: switched ? Colors.black54 : Colors.blue,
),
输出
更新:
FormBuilderSwitch(
name: "public",
title: Text("Wird noch ein Mitspieler gesucht?"),
initialValue: false,
controlAffinity: ListTileControlAffinity.leading,
activeColor: Colors.red
decoration: InputDecoration(border: InputBorder.none),
onChanged: (bool) {
setState(() {
bool = !bool;
switched = bool;
});
},
),
Container(
height: 20,
width: 20,
color: switched ? Colors.red : Colors.black,
),
非常感谢。但是我不想要一个新的开关,而是formbuilderswitch。我如何处理代码中的开关?我用formbuilderswitch@AndreasSüßbauerThanks对它进行了很多更新,但它对我不起作用。颜色不变。您能详细说明您想更改什么颜色吗@Andreasüßbauert容器的颜色从黑色变为红色(我选择了红色,因为蓝色是开关的标准颜色),但正如您所看到的,开关保持蓝色。例如,我也想把开关涂成红色。