Flutter onTap method for Containers

后端 未结 5 912
粉色の甜心
粉色の甜心 2021-02-03 17:56

Been developing a flutter app and dynamicly building some containers from some Firebase data. I wanted to know if there is a way to get a onTap method for containers (or any wi

5条回答
  •  清酒与你
    2021-02-03 18:33

    Apart from what others have said in answers, if you use Card inside InkWell, then InkWell will hide away the ripply effect on Android—you can see it happening in the background but not on the card itself.

    Solution to that is to create an InkWell inside the Card.

    return Card(
      child: InkWell(
        child: Row(
          // Row content
        ),
        onTap: () => {
          print("Card tapped.");
        },
      ),
      elevation: 2,
    );
    

    This will help you gain the ripple effect and perform the tap captures on Android too.

提交回复
热议问题