这个元素叫什么?二维复选框/单选框?

huangapple go评论70阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年6月30日 02:14:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76583654.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定