Flutter Form Builder Radio Group 没有选项标签

发布于 2025-01-10 16:24:34 字数 830 浏览 3 评论 0原文

在 flutter 应用程序中,我使用 flutter_form_builder 在更新表单中实现 FormBuilderRadioGroup。

我有一个用于用户角色的整数字段和一个我想在表单中设置的布尔字段用户活动。在单选按钮组和下拉小部件中,只有一个值选项,而不是预期的标签/值对。

有没有简单的方法来处理这个问题而不是围绕它编写代码?

这是我的代码,这些值作为整数而不是字符串存储在我的数据库中

FormBuilderRadioGroup(
  name: "role",
   decoration: InputDecoration(
     labelText: "Role",
     labelStyle: TextStyle(color: personLabelColor, fontSize: _user.fontsize, fontWeight: FontWeight.normal)
  ),
  options: const [
    FormBuilderFieldOption(value: "Role1"),
    FormBuilderFieldOption(value: "Role2"),
    FormBuilderFieldOption(value: "Role3"),
    FormBuilderFieldOption(value: "Role4"),
    FormBuilderFieldOption(value: "Role5"),
    FormBuilderFieldOption(value: "Role6"),
 ],
 initialValue: _person.role,
                          ),                       

In a flutter app I using flutter_form_builder to implement a FormBuilderRadioGroup in a update form.

I have an integer field for user role and a boolean field user active which I want to set in a form. In both the radio group and drop down widgets there is only one option for a value instead of the expected label / value pair.

Is there any easy way to handle this rather than code around it?

Here is my code, the values are stored in my database as integers, not strings

FormBuilderRadioGroup(
  name: "role",
   decoration: InputDecoration(
     labelText: "Role",
     labelStyle: TextStyle(color: personLabelColor, fontSize: _user.fontsize, fontWeight: FontWeight.normal)
  ),
  options: const [
    FormBuilderFieldOption(value: "Role1"),
    FormBuilderFieldOption(value: "Role2"),
    FormBuilderFieldOption(value: "Role3"),
    FormBuilderFieldOption(value: "Role4"),
    FormBuilderFieldOption(value: "Role5"),
    FormBuilderFieldOption(value: "Role6"),
 ],
 initialValue: _person.role,
                          ),                       

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文