What is an input gesture in Flutter?

An input gesture in Flutter allows users to interact with an application. Users can control the application by touching the screen, mouse, or keyboard.

List of input gestures in Flutter

  • Tap: This means to touch the screen from the fingertip or mouse for a short time. This gesture has the following events:
    • onTapDown
    • onTapUp
    • onTap
    • onTapCancel
  • Double tap: This means tapping the screen twice from the fingertip or double-clicking using a mouse. This gesture has the following events:

    • onDoubleTap
  • Long press: Touch the screen from the fingertip or mouse for a long period. This gesture has the following events:

    • onLongPress
  • Drag and drop: Press the screen from the fingertip and then drag it to another location. This gesture allows the drag functionalities in two ways:

    1. Horizontal drag: Horizontal drag gesture has the following events:
      • onHorizontalDragStart
      • onHorizontalDragUpdate
      • onHorizontalDragEnd
    2. Vertical drag: Vertical drag gesture has the following events:
      • onVerticalDragStart
      • onVerticalDragStart
      • onVerticalDragStart
  • Pan: Press the screen with the fingertip and move anywhere without releasing it. This gesture has the following events:

    • onPanStart
    • onPanUpdate
    • onPanEnd
  • Pinch: Zoom in or out with two fingers.

Example of onTapUp

Let’s discuss the example of the onTap event that will be executed when the user touches the screen:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _FirstApp createState() => _FirstApp();
}

class _FirstApp extends State<MyApp> {
  Color _rectangle = Colors.green;

  void _blockColor() {
    setState(() {
      _rectangle = _rectangle == Colors.green ? Colors.red : Colors.green;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: GestureDetector(
          onTap: _blockColor,
          child: Container(
            width: 1000,
            height: 1000,
            color: _rectangle,
          ),
        ),
      ),
    );
  }
}




The onTapUp gesture detector

Explanation

Lines 13–17: The _blockColor() function will be called when the user taps the screen. This function will change the color on each tap from green to red and red to green.

Lines 24–28: We have set the container widget. This widget has a width of 1000, a height of 100, and a background color is set to _rectangle. This _rectangle will change color on each tap.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved