Skip to content

[Material3] IconButton's isSelected not visible to screen readers #127145

Description

@chrisbobbe

Is there an existing issue for this?

Steps to reproduce

  1. Run my sample, pasted below.
  2. Tap the button in the center a few times. It has two states: selected and unselected.
  3. Activate a screen reader (I used VoiceOver on iOS)
  4. Use the screen reader to cause the button to be "pressed". (With VoiceOver, I found this is done with a double-tap.)
  5. Notice that its tooltip ("hello") is read, but the selected/unselected state is not.

Expected results

I expected the selected/unselected state to be read aloud.

Actual results

The selected/unselected state was not read aloud.

Code sample

Code sample
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(
      theme: Theme.of(context).copyWith(useMaterial3: true),
      home: const Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Button:'),
              MyButton(),
            ],
          ),
        ),
      ),
    );
  }
}

class MyButton extends StatefulWidget {
  const MyButton({Key? key}) : super(key: key);

  @override
  State<MyButton> createState() => _MyButtonState();
}

class _MyButtonState extends State<MyButton> {
  bool _selected = false;

  @override
  Widget build(BuildContext context) {
    return IconButton(
      onPressed: () {
        setState(() {
          _selected = !_selected;
        });
      },
      tooltip: 'hello',
      isSelected: _selected,
      icon: const Icon(Icons.arrow_left),
      selectedIcon: const Icon(Icons.arrow_right),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

N/A

Logs

Logs

No errors logged or expected.

Flutter Doctor output

Doctor output
$ flutter doctor -v
[✓] Flutter (Channel main, 3.11.0-6.0.pre.35, on macOS 13.3.1 22E772610a darwin-x64, locale en-US)
    • Flutter version 3.11.0-6.0.pre.35 on channel main at /Users/chrisbobbe/.local/lib/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 37fe1e9d77 (7 days ago), 2023-05-11 12:43:40 -0400
    • Engine revision f38f46f66e
    • Dart version 3.1.0 (build 3.1.0-94.0.dev)
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at /Users/chrisbobbe/Library/Android/sdk
    • Platform android-33, build-tools 30.0.3
    • ANDROID_HOME = /Users/chrisbobbe/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E222b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.78.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • Chris’s iPhone (mobile) • 00008110-000924383632801E • ios            • iOS 16.4.1 20E252
    • macOS (desktop)         • macos                     • darwin-x64     • macOS 13.3.1 22E772610a darwin-x64
    • Chrome (web)            • chrome                    • web-javascript • Google Chrome 113.0.5672.126
    ! Error: Chris’s Apple Watch needs to connect to determine its availability. Check the connection between the
      device and its companion iPhone, and the connection between the iPhone and Xcode. Both devices may also need to
      be restarted and unlocked. (code 1)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Activity

  1. chrisbobbe commented on May 18, 2023

    @chrisbobbe
    ContributorAuthor

    The following simple change does make the state visible to screen readers:

    diff --git packages/flutter/lib/src/material/icon_button.dart packages/flutter/lib/src/material/icon_button.dart
    index 7acd75762..2281d3318 100644
    --- packages/flutter/lib/src/material/icon_button.dart
    +++ packages/flutter/lib/src/material/icon_button.dart
    @@ -874,7 +874,10 @@ class _SelectableIconButtonState extends State<_SelectableIconButton> {
           onPressed: widget.onPressed,
           variant: widget.variant,
           toggleable: toggleable,
    -      child: widget.child,
    +      child: Semantics(
    +        toggled: widget.isSelected,
    +        child: widget.child),
         );
       }
     }

    Ideally, though, IconButton would let its callers choose whether to represent the state with SemanticsProperties.checked or SemanticsProperties.toggled. I think callers could reasonably choose either under the Material 3 spec.

  2. chrisbobbe commented on May 18, 2023

    @chrisbobbe
    ContributorAuthor

    Linking #106437 for context; that's when the isSelected param was added.

  3. added
    in triagePresently being triaged by the triage team
    on May 19, 2023
  4. huycozy commented on May 19, 2023

    @huycozy
    Member

    Thanks for the report. Reproduced the issue on the latest stable and master channels.

    Verified on VoiceOver (iOS) and TalkBack (Android).

    flutter doctor -v (stable and master)
    [✓] Flutter (Channel stable, 3.10.1, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
        • Flutter version 3.10.1 on channel stable at /Users/huynq/Documents/GitHub/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision d3d8effc68 (26 hours ago), 2023-05-16 17:59:05 -0700
        • Engine revision b4fb11214d
        • Dart version 3.0.1
        • DevTools version 2.23.1
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 32.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E222b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.78.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.64.0
    
    [✓] Connected device (3 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
        • macOS (desktop)  • macos            • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
        • Chrome (web)     • chrome           • web-javascript • Google Chrome 113.0.5672.126
    
    [✓] Network resources
        • All expected network resources are available.
    
    • No issues found!
    [!] Flutter (Channel master, 3.11.0-6.0.pre.153, on macOS 13.0.1 22A400 darwin-x64, locale en-VN)
        • Flutter version 3.11.0-6.0.pre.153 on channel master at /Users/huynq/Documents/GitHub/flutter_master
        ! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        ! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision e49d35d3a6 (35 minutes ago), 2023-05-18 22:26:29 -0400
        • Engine revision bca11a423f
        • Dart version 3.1.0 (build 3.1.0-125.0.dev)
        • DevTools version 2.23.1
        • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at /Users/huynq/Library/Android/sdk
        • Platform android-33, build-tools 32.0.0
        • ANDROID_HOME = /Users/huynq/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 14.3)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 14E222b
        • CocoaPods version 1.11.3
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 2022.2)
        • Android Studio at /Applications/Android Studio.app/Contents
        • Flutter plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/9212-flutter
        • Dart plugin can be installed from:
          🔨 https://plugins.jetbrains.com/plugin/6351-dart
        • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    
    [✓] VS Code (version 1.78.1)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.64.0
    
    [✓] Connected device (3 available)
        • RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64  • Android 11 (API 30)
        • macOS (desktop)  • macos            • darwin-x64     • macOS 13.0.1 22A400 darwin-x64
        • Chrome (web)     • chrome           • web-javascript • Google Chrome 113.0.5672.126
    
    [✓] Network resources
        • All expected network resources are available.
    
    ! Doctor found issues in 1 category.
  5. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    a: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on May 19, 2023
  6. added a commit that references this issue on Jun 9, 2023
    af7a8f6
  7. github-actions commented on Jun 23, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  8. locked as resolved and limited conversation to collaborators on Jun 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)found in release: 3.10Found to occur in 3.10found in release: 3.11Found to occur in 3.11frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packages

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions