如何解决如何在 Flutter 2.2.1 的 CheckboxListTile 中应用单选?
此设计包括从发票数据列表中进行的一个选择。例如,用户选择了要提交的“公司数据”选项。代码包含用于选择选项的 CheckBoxListTile。它只需要在四个选项中选择一个。我是扑的新手。
这是我使用的代码:
//Declare Model
List<CheckBoxListTileModel> checkBoxListTileModel =
CheckBoxListTileModel.getUsers();
//UI Setup
Container(
height: 240.0,child: Padding(
padding: EdgeInsets.fromLTRB(18.0,15.0,18.0,2.0),child: StatefulBuilder(
builder: (context,_setState) => new ListView.builder(
itemCount: checkBoxListTileModel.length,itemBuilder: (BuildContext context,int index) {
return new CheckBoxListTile(
activeColor: HexColor('#34c47e'),dense: true,//font change
title: new Text(
checkBoxListTileModel[index].title,style: TextStyle(
fontSize: 14,),value: checkBoxListTileModel[index].isCheck,onChanged: (newValue) {
_setState(() => {
checkBoxListTileModel[index].isCheck = newValue!
});
});
}),);
//Model Class
class CheckBoxListTileModel {
int userId;
String title;
bool isCheck;
CheckBoxListTileModel(
{required this.userId,required this.title,required this.isCheck});
static List<CheckBoxListTileModel> getUsers() {
return <CheckBoxListTileModel>[
CheckBoxListTileModel(userId: 1,title: "Personal Data",isCheck: true),CheckBoxListTileModel(userId: 2,title: "Company Data",isCheck: false),CheckBoxListTileModel(
userId: 3,title: "Without VAT/Final Consumer",CheckBoxListTileModel(userId: 4,title: "Other",];
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。