我想为我的GridView
启用多选功能,但是当我单击任意一个图块时,所有图块都被自动选中,我想启用图块单击时选中和取消选中的图块。请帮助选择和取消选择多个标签。
这是代码:
void toggleSelection() {
setState(() {
if (_isSelected) {
// mycolor=Colors.white;
_textColor = Colors.deepOrange[400];
_borderColor = Colors.deepOrange[300].withOpacity(0.8);
_isSelected = false;
} else {
// mycolor=Colors.grey[300];
_textColor = Colors.black;
_borderColor = Colors.white;
_isSelected = true;
}
});
}
List<Widget> _getTiles() {
final List<Widget> tiles = <Widget>[];
for (int i = 0; i < listResponseData.length; i++) {
bool isSelected = _serviceindex == i;
tiles.add(Container(
//decoration: BoxDecoration(borderRadius: BorderRadius.circular(6), color: Colors.grey),
child: ListTile(
selected: _isSelected,
title: new GestureDetector(
child: new Card(
elevation: 5.0,
child: new Container(
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
border: Border.all(color: _borderColor),
color: Colors.white,
),
child: new Text(listResponseData[i].nativeText,
style: TextStyle(fontSize: 20, color: _textColor),
),
),
),
onTap: () {
toggleSelection();
},
),
),
));
}
return tiles;
}
答案 0 :(得分:0)
我已经解决了这个问题,这是工作代码。
set testfile to (choose file) -- The name testdir for a file is confusing
set {name:Nm, name extension:Ex} to info for testfile