Flutter onTap method for Containers

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

    Difference

    InkWell is a material widget and it can show you a Ripple Effect whenever a touch was received.

    GestureDetector is more general-purpose, not only for touch but also for other gestures.

    In Flutter, InkWell is a material widget that responds to touch action.

    InkWell(
        child: Container(......),
        onTap: () { 
            print("Click event on Container"); 
        },
    );
    

    GestureDetector is a widget that detects the gestures.

    GestureDetector(
        onTap: () { 
            print("Click event on Container"); 
        },
        child: Container(.......),
    )
    

提交回复
热议问题