flutter - 如何从字符串数组中对单选按钮列表进行分组。单击时单选按钮指向所有项目。在所有项目中选择单选列表磁贴
问题描述
我正在使用 flutter-SQLite-Dart 开发移动应用程序。使用单选列表磁贴,我分配了一个单选按钮并传递了一个索引值。执行应用程序时,我可以单击所有单选按钮。我需要使单选按钮列表只能单击一次,当我选择了一个单选按钮时,不应选择其他单选按钮。这是要求。
return InkWell(
onTap: press,
child: Container(
child: Row(
children: <Widget>[
Expanded(
child: Container(
height: 60.0,
child: Theme(
data: Theme.of(context).copyWith(
unselectedWidgetColor: Colors.grey,
disabledColor: Colors.blue),
child: Column(children: [
RadioListTile(
title: Text("${sample[index]}",
style:
TextStyle(color: Colors.black)),
groupValue: id,
value: index,
activeColor: Colors.green,
onChanged: (val) {
setState(() {
id = val;
debugPrint('val answer$val');
});
},
toggleable: true,
),
]),
)),
),
],
),
),
);
应用程序的输出
解决方案
试试下面的代码,你会用 groupValue 声明一个字符串。
String _groupValue;
return InkWell(
onTap: press,
child: Container(
child: Row(
children: <Widget>[
Expanded(
child: Container(
height: 60.0,
child: Theme(
data: Theme.of(context).copyWith(
unselectedWidgetColor: Colors.grey,
disabledColor: Colors.blue),
child: Column(children: [
RadioListTile(
title: Text("${sample[index]}",
style:
TextStyle(color: Colors.black)),
groupValue: _groupValue,
value: index,
activeColor: Colors.green,
onChanged: (val) {
setState(() {
_groupValue = val;
debugPrint('val answer$val');
});
},
),
]),
)),
),
],
),
),
);
推荐阅读
- ruby - 自动缩放延迟的作业服务器 Rails?
- node.js - 在 Next.js 的 getInitialProps 中重定向时出现无限循环
- reactjs - 将redux-form库initialValue注入
- graphics - 将相机居中/适合对象
- oracle - 此系统不支持 Oracle Apex RAS
- java - 写入()的 ChannelPromise 的 Netty ClosedChannelException
- javascript - REACT 组件到 REACT 函数
- java - 在嵌套的 for 循环中全局声明变量会在 Java 中过早地中断循环
- python - 启发式选择使点积最大化的五列数组
- python - 通过重启和关闭执行机器人任务