[Flutter] GestureDetector

멋진감자·2025년 7월 24일
0

Flutter

목록 보기
21/25

Text 위젯에 인터렉션 넣기

유저가 Text() 위젯을 눌렀을 때 상세페이지를 띄우고 싶을 수도 있음
근데 onPressed 같은 게 없으니 이 때 GestureDetector() 위젯으로 싸맨다.

GestureDetector(child: Text('싸매 me'), onTap: (){});

onPressed 말고 onTap을 쓸 수 있다.
길게 눌렀을 때 인터렉션 주려면 onLongPress
두 번 눌렀을 때 인터렉션을 주려면 onDoubleTap
핀치(확대 모션)할 때 주려면 onScaleStart
왼쪽으로 스와이프 했을 때 코드 실행하려면 onHorizontalDragStart

이런식으로 특정 동작에 따라 코드 실행시킬 때 GestureDetector() 써보기.
상세페이지는 Navigator.push()로 구현해보자.

onTap: () {
  Navigator.push(
    context,
    MaterialPageRoute(builder: (c) => Text('상세페이지')),
  );
},

결과물

우와 생긴거

profile
난멋져

0개의 댓글