【发布时间】:2023-01-10 15:33:00
【问题描述】:
滚动时,焦点在两个 CircleAvatar 上,我在每个 CircleAvatar 上面放了 OnTap 以在单击其中一个时添加特定操作,但问题是 OnTap 不起作用。如何使用相同的附加代码解决这个问题?
请帮忙,谢谢。
代码 :
class AddUserPage extends StatefulWidget {
const AddUserPage({Key? key}) : super(key: key);
@override
State<AddUserPage> createState() => _AddUserPageState();
}
class _AddUserPageState extends State<AddUserPage> {
final List<String> profiles = [
'http://www.the-able-company.com/uploads/3/2/0/9/32099781/5kids-05_orig.png',
'http://www.the-able-company.com/uploads/3/2/0/9/32099781/5kids-04_orig.png',
'http://www.the-able-company.com/uploads/3/2/0/9/32099781/5kids-01_orig.png',
'http://www.the-able-company.com/uploads/3/2/0/9/32099781/5kids-02_orig.png',
'http://www.the-able-company.com/uploads/3/2/0/9/32099781/5kids-03_orig.png',
// 'http://www.the-able-company.com/uploads/3/2/0/9/32099781/5kids-05_orig.png',
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Padding(
padding: const EdgeInsets.all(20),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(
height: 250,
child: ListWheelScrollView.useDelegate(
squeeze: 1.4,
itemExtent: 150,
diameterRatio: 9,
onSelectedItemChanged: (value) {},
physics: const FixedExtentScrollPhysics(),
childDelegate: ListWheelChildBuilderDelegate(
childCount: profiles.length ~/ 2 + profiles.length % 2,
builder: (context, index) => Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
GestureDetector(
onTap: () {},
CircleAvatar(
radius: 50,
backgroundImage: NetworkImage(profiles[2 * index]),
),),
if (2 * index + 1 < profiles.length)
GestureDetector(
onTap: () {},
CircleAvatar(
radius: 50,
backgroundImage:
NetworkImage(profiles[2 * index + 1]),
),),
],
),
),
),
),
],
),
),
);
}
}
【问题讨论】: