Skip to content

[CP] Fix TextField not responding to taps when wrapped in a GestureDetector #129577

@Renzo-Olivares

Description

@Renzo-Olivares

Issue Link

#129161

Commit Hash

3c366b7

Target

stable

PR Link

#129576

Changelog Description

A change in the GestureRecognizers used by the TextField caused a regression in TextField where it would not fire the onTapDown or onTapUp callbacks which made selection not work as expected. This fixes that regression.

Impacted Users

Users that utilize a TextField wrapped with a GestureDetector.

Impact Description

The issue created a regression in the UI experience of TextField when used with a GestureDetector caused by the internal gesture recognizers of TextField losing the down and up events they are meant to fire for the onTapDown and onTapUp callbacks. Users are unable to focus the TextField with a tap in these cases.

Workaround

No workaround.

Risk

low

Test Coverage

yes

Validation Steps

Running this sample code from the original issue. The TextField that is wrapped in a GestureDetector should be focusable with a tap.

Sample code
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            GestureDetector(
              onTap: () {
                print('single tap');
              },
              onDoubleTap: () {
                print('double tap');
              },
              // this textfield can't be selected
              child: TextField(
                controller: TextEditingController()..text = 'Initial Text',
              ),
            ),
            // this textfield can be selected
            TextField(
              controller: TextEditingController()..text = 'Initial Text',
            ),
          ],
        ),
      ),
    );
  }
}

Metadata

Metadata

Assignees

Labels

cp: approvedApproved cherry-pick requestcp: merge-to-stableCherry-picks that should be merged to stablecp: mergedCherry-pick has been merged to the release branch.cp: reviewCherry-picks in the review queue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions