【问题标题】:Flutter GestureDetector on tap点击 Flutter GestureDetector
【发布时间】: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]),
                        ),),
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

【问题讨论】:

    标签: flutter flutter-animation


    【解决方案1】:

    你可能不得不使用这个包,

    https://pub.dev/packages/clickable_list_wheel_view

    https://pub.dev/packages/clickable_list_wheel_view

    您无需进行太多更改,因为此包与ListWheelScrollView 非常相似。

    因为,

    ListWheelScrollView 无法识别其子项上的 onTap()

    【讨论】:

      猜你喜欢
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多