Skip to content

Pressing tab does select all content when app is resumed for TextFields which were not focused #177650

@bleroux

Description

@bleroux

Steps to reproduce

  1. Run the code sample on desktop.
  2. Set the focus to another window.
  3. Come back the Flutter application.
  4. Press tab.
  5. Observe the selection for the second TextField.

Expected results

The whole content of the second TextField is selected:

Screen.Recording.2025-10-28.at.13.48.58.mov

Actual results

The previous selection is used (selection collapsed at end as set initially in the code):

Screen.Recording.2025-10-28.at.13.48.22.mov

Code sample

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

void main() => runApp(const ReproApp());

class ReproApp extends StatefulWidget {
  const ReproApp({super.key});

  @override
  State<ReproApp> createState() => _ReproAppState();
}

class _ReproAppState extends State<ReproApp> {
  static TextEditingValue collapsedAtEnd(String text) {
    return TextEditingValue(
      text: text,
      selection: TextSelection.collapsed(offset: text.length),
    );
  }

  final TextEditingController controller1 = TextEditingController.fromValue(
    collapsedAtEnd('Flutter!!!'),
  );
  final TextEditingController controller2 = TextEditingController.fromValue(
    collapsedAtEnd('Dart!!!'),
  );

  @override
  void dispose() {
    controller1.dispose();
    controller2.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Column(
          children: [
            TextField(autofocus: true, controller: controller1),
            TextField(controller: controller2),
          ],
        ),
      ),
    );
  }
}

Screenshots or Video

No response

Logs

Flutter Doctor output

Doctor output
Flutter (Channel [user-branch], 3.38.0-1.0.pre-246, on macOS 15.6.1 24G90 darwin-arm64, locale en-FR)

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopa: text inputEntering text in a text field or keyboard related problemsfound in release: 3.35Found to occur in 3.35found in release: 3.38Found to occur in 3.38frameworkflutter/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-text-inputOwned by Text Input team

Type

No type

Projects

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions