如何设置 Flutter Form Builder Radio Group 选项的样式?

发布于 2025-01-10 20:54:31 字数 876 浏览 3 评论 0原文

我正在使用 Flutter Form BuilderFormBuilderRadioGroup 但我不知道了解如何设置始终为黑色的选项的样式。更改应用程序的主要样本没有任何区别。下面代码中的颜色选项也不起作用。标签样式有效,但选项内容样式无效。所选选项始终为蓝色。

我的表单有深色背景,我需要选项内容为白色。

FormBuilderRadioGroup(
  name: "role",
  decoration: InputDecoration(
    labelText: "Role",
    labelStyle: TextStyle(color: personLabelColor, fontSize: _user.fontsize, fontWeight: FontWeight.normal),
    fillColor: Colors.red,
    focusColor: Colors.blue,
    hoverColor: Colors.yellow,
  ),
  options: const [
    FormBuilderFieldOption(value: 0),
    FormBuilderFieldOption(value: 1),
    FormBuilderFieldOption(value: 2),
    FormBuilderFieldOption(value: 3),
    FormBuilderFieldOption(value: 4),
    FormBuilderFieldOption(value: 5),
  ],
  initialValue: _person.role,
),

I am using Flutter Form Builder with a FormBuilderRadioGroup but I can't figure out how to style the options which are always black. Changing the app's primary swatch makes no difference. The color options in the code below also have no effect. The label style works but not the options content style. The selected option is always blue.

My form has a dark background and I need the options content to be white.

FormBuilderRadioGroup(
  name: "role",
  decoration: InputDecoration(
    labelText: "Role",
    labelStyle: TextStyle(color: personLabelColor, fontSize: _user.fontsize, fontWeight: FontWeight.normal),
    fillColor: Colors.red,
    focusColor: Colors.blue,
    hoverColor: Colors.yellow,
  ),
  options: const [
    FormBuilderFieldOption(value: 0),
    FormBuilderFieldOption(value: 1),
    FormBuilderFieldOption(value: 2),
    FormBuilderFieldOption(value: 3),
    FormBuilderFieldOption(value: 4),
    FormBuilderFieldOption(value: 5),
  ],
  initialValue: _person.role,
),

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情绪 2025-01-17 20:54:31

使用主题中的 unselectedWidgetColor 更改单选按钮上的默认黑色/灰色。
或者您可以使用 radioThemefillColor 来更改此设置。

Theme(
  data: Theme.of(context).copyWith(
    ///selected radio button color
    selectedRowColor: Colors.green, 
    
    // unselected radio button
    unselectedWidgetColor: Colors.yellow, 
    radioTheme: Theme.of(context).radioTheme.copyWith(
          fillColor: MaterialStateProperty.all(Colors.purple),
        ),
  ),
  child: FormBuilderRadioGroup(

FormBuilderRadioGroup 上的 activeColor 更改所选单选按钮的默认蓝色。

child: FormBuilderRadioGroup(
  name: "role",
  activeColor: Colors.white, // this

Using unselectedWidgetColor from theme, change the default black/gray color on radio button.
Or you can use radioTheme's fillColor to change this.

Theme(
  data: Theme.of(context).copyWith(
    ///selected radio button color
    selectedRowColor: Colors.green, 
    
    // unselected radio button
    unselectedWidgetColor: Colors.yellow, 
    radioTheme: Theme.of(context).radioTheme.copyWith(
          fillColor: MaterialStateProperty.all(Colors.purple),
        ),
  ),
  child: FormBuilderRadioGroup(

activeColor on FormBuilderRadioGroup change the default blue color of selected radio button.

child: FormBuilderRadioGroup(
  name: "role",
  activeColor: Colors.white, // this
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文