Flutter onTap method for Containers

后端 未结 5 979
粉色の甜心
粉色の甜心 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:30

    Screenshot:


    You shouldn't use GestureDetector because it won't show you any ripple effect (which is core part of a Material design app), so you can use InkWell, here is the basic example.

    Widget _buildContainer() {
      return Material(
        color: Colors.blue,
        child: InkWell(
          onTap: () => print("Container pressed"), // handle your onTap here
          child: Container(height: 200, width: 200),
        ),
      );
    }
    

提交回复
热议问题