英文:
What is this element called? Two dimensional checkbox/radiobox?
问题
I'm developing a Flutter app and I'm trying to find what this is called:
Essentially, it's a checklist that only allows one input and is two-dimensional.
In this image, the top-left box is selected.
I'd appreciate any help in trying to find what this element is called.
英文:
I'm developing a Flutter app and I'm trying to find what this is called:
Essentially, it's a checklist that only allows one input and is two dimensional.
In this image, the top left box is selected.
I'd appreciate any help in trying to find what this element is called.
答案1
得分: 1
从我在Flutter中所了解的情况来看,我认为Flutter目前还没有这个小部件。所以这是我解决的方法。
我创建单独的ListTiles或者任何你选择的小部件。然后在onPressed/onClick属性中,我将该小部件分配的数字与我的全局变量进行比较,如果为真,就将isSelected设置为true。
每次都有效。
int globalNum = 3;
// 在你的小部件树中的某处
ListTile(
selected: globalNum == 1 ? true : false,
selectedTileColor: Colors.red,
onTap: () => globalNum = 1,
),
ListTile(
selected: globalNum == 2 ? true : false,
selectedTileColor: Colors.red,
onTap: () => globalNum = 2,
),
你可以将你的脚手架包装在一个主题中,这样你就不需要单独设置selectedTileColor。但是为了演示,这是你会这样做的方式。
英文:
From what i know in flutter, i don't think flutter has that widget yet. So this is what i do to get around.
I create separate listTiles or boxes or any widget of choice. And in the onpressed/onclicked property, i compared the number assigned to that widget with my global variable and if it's true, set isSelected to true
Works everytime
int globalNum=3;
//somewhere in your widget tree
ListTile(
selected:globalNum==1?true:false,
selectedTileColor:Colors.red,
onTap:()=>globalNum=1,
),
ListTile(
selected:globalNum==2?true:false,
selectedTileColor:Colors.red,
onTap:()=>globalNum=2,
),
You can wrap your scaffold in a theme so that you don't set the individual selectedTileColor. But for demostration this is how you'll do it.
答案2
得分: 1
如果控件只允许一次选择一个项目,那就是单选按钮。请查看详细文档。
英文:
If the control permits only one item at a time, it's a Radio. See the docs for details.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论