Skip to content

TextField's onTapOutside is triggered even if textfield wasn't focused #134341

@burakmartin

Description

@burakmartin

Is there an existing issue for this?

Steps to reproduce

  1. Add two text fields in a column
  2. For one of them, add a onTapOutside callback with a debug print.
  3. For the second one, do nothing
  4. Click inside the textfield that does not have the onTapOutside defined
  5. Click anwhere outside of the textfield

Expected results

The callback should only be invoke only if the textfield had been focused before.

The comment of the callback states:

Called for each tap that occurs outside of the[TextFieldTapRegion] group when the text field is focused.

Actual results

The callback of the first textfield is called

Code sample

Code sample
import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          actions: [],
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            TextField(
              key: const ValueKey("1"),
              decoration: const InputDecoration(
                hintText: "1",
              ),
              onTapOutside: (event) {
                debugPrint("Callback from 1");
              },
            ),
            const TextField(
              key: ValueKey("2"),
              decoration: InputDecoration(
                hintText: "2",
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

Logs
Callback from 1

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.13.3, on macOS 13.5.1 22G90 darwin-arm64, locale en-DE)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.3)
[✓] IntelliJ IDEA Ultimate Edition (version 2023.2)
[✓] VS Code (version 1.81.1)
[✓] Connected device (3 available)            
[✓] Network resources

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: text inputEntering text in a text field or keyboard related problemsf: focusFocus traversal, gaining or losing focusf: material designflutter/packages/flutter/material repository.found in release: 3.13Found to occur in 3.13found in release: 3.14Found to occur in 3.14frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages teamtriaged-designTriaged by Design Languages team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions