-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
Issue Link
Commit Hash
Target
stable
PR Link
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',
),
],
),
),
);
}
}