0

我是 Flutter 的新手,如何在 gridview.count 中获取 onTap 命令

我试图使图像可点击,但我无法在 gridview.count 中获取命令 onTap

 Widget buildBody() {
    return SafeArea(
        child: Container(
      padding: EdgeInsets.all(20.0),
      child: Column(
        children: <Widget>[
          Expanded(
              child: GridView.count(
            crossAxisCount: 2,
            padding: EdgeInsets.all(20),
            crossAxisSpacing: 20,
            mainAxisSpacing: 20,
            children: _products
                .map(((item) => Card(
                      child: Container(
                        decoration: BoxDecoration(
                            image: DecorationImage(
                                image: Image.asset(item.imageUrl),
                                fit: BoxFit.fill)),
                      ),
                    )))
                .toList(),
          )),
        ],
      ),
    ));
  }

这是我得到的图像列表

List<Product> _products = <Product>[
  Product("Özel Kesim Magnet", "Özel Kesim Magnet", "assets/icons/ökm.png"),
  Product("Kuşe Etiketler", "kş", "assets/icons/ke.png"),
  Product("Opak Etiketler", "oe", "assets/icons/oe.png"),
  Product("Şeffaf Etiketler", "şe", "assets/icons/şe.png"),
  Product("Kutu Kesim", "ks", "assets/icons/kk.png"),
  Product("Tam Kesim", "tk", "assets/icons/tk.png"),
  Product("Özel Kesim", "ÖK", "assets/icons/ök.png"),
  Product("Folyo Kesim", "fk", "assets/icons/fk.png")
];
4

1 回答 1

1

GestureDetector用或包裹您的卡片InkWell

GestureDetector(
  onTap: () {},
  child: Card(...),
);
于 2021-08-01T19:41:17.047 回答