Skip to content

TextButton.icon breaks focus traversal and ink effect when toggling icon #173944

@bleroux

Description

@bleroux

Steps to reproduce

  1. Run the code sample
  2. Press tab two times to move the focus on the second TextButton which label is "TextButton.icon"
  3. Click on the button or press enter

Expected results

The icon appears and the focus stays on the button

Actual results

The icon appears and the focus move to the first button
(Also the Ink animation is interrupted)

Code sample

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

/// Flutter code sample for [SegmentedButton].

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

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

  @override
  State<SegmentedButtonApp> createState() => _SegmentedButtonAppState();
}

class _SegmentedButtonAppState extends State<SegmentedButtonApp> {
  bool showIcon = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: TextButtonTheme(
          data: const TextButtonThemeData(
            style: ButtonStyle(
              backgroundColor: WidgetStateProperty.fromMap(<WidgetStatesConstraint, Color>{
                WidgetState.focused: Colors.greenAccent,
                WidgetState.any: Color(0xFFEEEEFF),
              }),
            ),
          ),
          child: Center(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              spacing: 16,
              children: [
                TextButton(onPressed: onPressed, child: const Text('TextButton')),
                TextButton.icon(
                  onPressed: onPressed,
                  icon: showIcon ? const Icon(Icons.check) : null,
                  label: const Text('TextButton.icon'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }

  void onPressed() {
    setState(() {
      showIcon = !showIcon;
    });
  }
}

Screenshots or Video

Screenshots / Video demonstration
Screen.Recording.2025-08-18.at.09.47.33.mov

Logs

Flutter Doctor output

Doctor output
Flutter (Channel [user-branch], 3.33.0-1.0.pre.401, on macOS 15.5 24F74 darwin-arm64, locale en-FR)

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listf: focusFocus traversal, gaining or losing focusf: material designflutter/packages/flutter/material repository.found in release: 3.33Found to occur in 3.33found in release: 3.35Found to occur in 3.35frameworkflutter/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

Status

Done (PR merged)

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions