我有一个ListView.builder
,它返回一个InkWell
,其子Container
保存一个数组的值,我在onTap
_selectedIndex = index;
内部实现了这样做,以 Select 所单击的数组中的每一项,并在另一项被单击时取消 Select ,这非常有效,但现在我喜欢一种可以使我在一行中 Select 多项的变通方法(例如:如果我有一个项[1,2,3]的数组,则允许单击1-2-2-3,但当try 单击1-3时,它不应该被允许并显示错误消息).以下是我的代码:
String time_slot;
int _selectedIndex = -1;
Container(
height: 50,
child:new ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: dataSchedule == null ? 0 : dataSchedule.length,
itemBuilder: (BuildContext context, int index){
return InkWell(onTap: (){ setState(() {
time_slot = dataSchedule[index]['time_slot'];
_selectedIndex= index;
});
},
child: Container(
padding: EdgeInsets.all(0),
child: Card(
color: Colors.white,
elevation: 0,
semanticContainer: true,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5.0),
),
child: Container(
decoration:
BoxDecoration(
color: Colors.white,
borderRadius:
BorderRadius
.circular(
3.0),
border:Border.all(color:scheduleField=="field require"?Colors.red: index== _selectedIndex ?
colorBlue :
Colors.grey[200],width: 2)),
padding: EdgeInsets.all(10),
child:Center(
child: Text(
dataSchedule[index]['time_slot'],style:TextStyle(fontFamily: 'Montserrat',
color: colorBlack, fontWeight: FontWeight.bold,
fontSize: 15),
textAlign: TextAlign.center,
),
),))));
}
),
),
我将非常感谢任何贡献,如果有任何需要的信息,我将很乐意提供.先谢谢你.