Learn/Core Widgets/GestureDetector & InkWell

GestureDetector & InkWell

Detect taps, swipes, long presses and add ripple effects

5 min~4 min read+30 FX

You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.

Table of Contents

  1. 1. Gesture UX Principles
  2. 2. This Lesson In Simple Words
  3. 3. Your level focus
  4. 4. One practical habit
  5. 5. Deep Understanding Guide
  6. 6. Why this lesson matters
  7. 7. Study flow for better retention
  8. 8. Quick Glossary

Having trouble? AI is here to help

Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.

Use the AI button at the bottom of the screen

GestureDetector & InkWell

Flutter provides two primary ways to detect touch gestures:

  • GestureDetector detects any gesture but provides no visual feedback on its own.
  • InkWell provides a Material ripple effect on tap, making it the preferred choice for interactive UI elements like cards and list items.
dart
1// ── GestureDetector ──
2GestureDetector(
3 onTap: () => print('Tapped!'),
4 onDoubleTap: () => print('Double tapped!'),
5 onLongPress: () => print('Long pressed!'),
6 onHorizontalDragEnd: (details) {
7 if (details.velocity.pixelsPerSecond.dx > 0) {
8 print('Swiped right');
9 }
10 },
11 child: Container(
12 width: 100,
13 height: 100,
14 color: Colors.blue,
15 child: const Center(child: Text('Tap me')),
16 ),
17)
dart
1// ── InkWell - Material ripple effect ──
2InkWell(
3 onTap: () => print('Tapped with ripple!'),
4 onLongPress: () => print('Long pressed!'),
5 borderRadius: BorderRadius.circular(12), // clips the ripple
6 child: Container(
7 padding: const EdgeInsets.all(16),
8 child: const Text('Tap for ripple'),
9 ),
10)
11
12// ── Wrap Container in Material for InkWell to show on colors ──
13Material(
14 color: Colors.transparent,
15 child: InkWell(
16 onTap: () {},
17 splashColor: Colors.blue.withOpacity(0.3),
18 child: Container(
19 width: 200, height: 60,
20 decoration: BoxDecoration(
21 color: Colors.blue,
22 borderRadius: BorderRadius.circular(8),
23 ),
24 child: const Center(child: Text('Button', style: TextStyle(color: Colors.white))),
25 ),
26 ),
27)

When to Use Which

💡 When to Use Which

Use InkWell for Material UI elements such as cards, buttons, and list items where the expected ripple effect enhances the user experience. Use GestureDetector for custom widgets where a ripple does not fit, or when you need complex gestures like swipe, pinch, or rotate.

Gesture UX Principles

Interaction should feel obvious and reliable:

  • keep gesture behavior predictable
  • avoid hidden gestures for critical actions
  • provide immediate visual feedback for taps
  • prevent accidental gesture conflicts in nested widgets

If users need to guess how to interact, gesture design needs simplification.

Gesture Safety Checklist

  • Important actions are available through visible controls.
  • Gestures do not conflict with parent scroll views.
  • Tap feedback is clear and timely.
  • Long press and double tap are optional enhancements, not required basics.

This Lesson In Simple Words

Detect taps, swipes, long presses and add ripple effects. Animation gives feedback and personality to UI when it supports user intent clearly.

Your level focus

Build confidence with basics first; speed comes later.

One practical habit

Animate only what helps understanding, and keep transition timing consistent.

Deep Understanding Guide

Why this lesson matters

Good motion guides attention; bad motion distracts and can hurt performance.

Study flow for better retention

  1. Read one section, run one tiny example, then explain the idea in your own words.
  2. Prefer simple implicit animations first, then move to explicit control for complex flows.
  3. If you can teach it in 45 seconds without notes, you understood it.

Common Mistakes To Avoid

  • Adding animation everywhere without UX purpose.
  • Rebuilding large widget trees for tiny animated changes.
  • Using inconsistent durations that make flows feel random.
  • Ignoring accessibility needs for users sensitive to motion.

Practice Sprint (15-25 Minutes)

  • Before running sample code, predict output and behavior in one sentence.
  • Create one implicit and one explicit animation for the same component.
  • Use Hero transition between two screens with meaningful shared element.
  • Profile animation frame times and remove one avoidable rebuild hotspot.
  • Complete the required exercises without using hints on the first attempt.
  • Answer this question out loud before checking quiz options: "What is the visual difference between GestureDetector and InkWell?".

Quick Glossary

  • widget: A reusable UI building block in Flutter.

Code Comprehension Drill

  • State the purpose of the code block in one line before reading details.
  • Mark inputs, state changes, and final output.
  • Change one small value and predict what should happen before running.
  • Run again and compare your prediction with actual behavior.

Lesson Completion Checklist

  • I can explain "GestureDetector & InkWell" in simple words without reading notes.
  • I can describe one real app situation where this concept is required.
  • I know at least one mistake to avoid: Adding animation everywhere without UX purpose.
  • I can modify one code sample and correctly predict the behavior change.
  • I can finish required exercises with understanding, not trial-and-error guesses.

Frequently Asked Questions

What is the visual difference between GestureDetector and InkWell?

InkWell provides the Material Design ink ripple animation on tap. GestureDetector detects gestures but has no built-in visual feedback.

Which gesture does onLongPress detect?

onLongPress fires when the user holds down on the widget for approximately 500 milliseconds.

Why wrap a colored Container with Material when using InkWell?

InkWell's ripple draws on the nearest Material ancestor. Without wrapping in Material, the container color may hide the ripple effect.

Suggest Improvement

Something seems incorrect, unclear, or missing? Let us know.

About The Author

FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.

Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.

Sign in to continue with exercises and quiz for this lesson.

Sign In to Continue