gpt4 book ai didi

flutter 取消选择 RadioListTile 按钮

转载 作者:行者123 更新时间:2023-12-03 03:15:21 30 4
gpt4 key购买 nike

几天来,我一直试图弄清楚我的错误在哪里,但仍然无法解决。 Flutter 的绝对新手,我正在构建多项选择测验应用程序。我有多项选择问题屏幕,它从如下所示的 radio_button.dart 文件中导入 radiolisttile 选项。

一切正常,除了我无法取消选择按钮后。换句话说,如果我点击每个按钮,它们都会被选中。

 import "package:flutter/material.dart";

class RB extends StatefulWidget {
RB({this.choice, this.value});

final String choice;
final String value;

@override
_RBState createState() => _RBState();

}
class _RBState extends State<RB> {
bool dense=false;
String _selection = '';
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Material(
elevation: 5.0,
child: RadioListTile(
title: Text(widget.choice, style: TextStyle(color: Colors.blue,),),
value: widget.choice,
groupValue: _selection,
dense: dense,
activeColor: Colors.green,
onChanged:( val) { setState(() { _selection = val; print(val);}); },

),
),
);
}
}

Here the question_screen snippet
Column(
children: <Widget>[
Container(child: RB(choice:'A',value:'All of above',)),
Container(child: RB(choice:'B',value:'None of the above'))

最佳答案

现在,在 2020 年 9 月,正确答案应该是使用 toggleable属性。

RadioListTile(
title: Text("xxx"),
value: index,
groupValue: _seletedIndex,
toggleable: true,
onChanged: (value) {
onAlertChange(value, alert);
},
)

关于 flutter 取消选择 RadioListTile 按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60403984/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com