Skip to content

Using BlockSemantics in an OverlayPortal does not block portal siblings #176533

@davidhicks980

Description

@davidhicks980

Steps to reproduce

  1. Run example
  2. Turn on TalkBack
  3. Open "Menu Button 0"
  4. Navigate forward and backward

Alternatively, enabling showSemanticsDebugger and open Menu Button 0

This is expected behavior since OverlayPortal does not move the semantics tree of its overlay, but it also makes it difficult to replicate semantic focus trapping on mobile platforms.

Expected results

Menu Button 1 should not be able to obtain accessibility focus

Actual results

Menu Button 1 can obtain accessibility focus

Code sample

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

void main(List<String> args) {
  runApp(const App());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(home: Material(child: Example()));
  }
}

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

  @override
  State<Example> createState() => _ExampleState();
}

class _ExampleState extends State<Example> with SingleTickerProviderStateMixin {
  @override
  Widget build(BuildContext context) {
    final List<MenuController> controllers = <MenuController>[
      MenuController(),
      MenuController(),
    ];
    return Center(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          for (int i = 0; i < 2; i++)
            RawMenuAnchor(
              controller: controllers[i],
              builder: (BuildContext context, MenuController menuController, Widget? child) {
                return ElevatedButton(
                  onPressed: () {
                    if (menuController.isOpen) {
                      menuController.close();
                    } else {
                      for (final MenuController controller in controllers) {
                        controller.close();
                      }
                      menuController.open();
                    }
                  },
                  child: Text('Menu Button $i'),
                );
              },
              overlayBuilder: (BuildContext context, RawMenuOverlayInfo info) {
                return Positioned(
                  top: info.anchorRect.bottom,
                  left: info.anchorRect.left,
                  child: BlockSemantics(
                    child: Container(
                      color: Color.fromARGB(255, i.isEven ? 255 : 100, 200, 200),
                      height: 200,
                      width: 200,
                      child: Column(
                        children: <Widget>[
                          MenuItemButton(
                            onPressed: () {
                              MenuController.maybeOf(context)?.close();
                            },
                            child: const Text('Edit'),
                          ),
                          MenuItemButton(
                            onPressed: () {
                              MenuController.maybeOf(context)?.close();
                            },
                            child: const Text('Share'),
                          ),
                        ],
                      ),
                    ),
                  ),
                );
              },
            ),
        ],
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration
Screen_Recording_20251004_231324.mp4

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.35.5, on macOS 15.5 24F74 darwin-arm64, locale en-US) [402ms]
    • Flutter version 3.35.5 on channel stable at /Users/davidhicks/fvm/versions/stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ac4e799d23 (8 days ago), 2025-09-26 12:05:09 -0700
    • Engine revision d3d45dcf25
    • Dart version 3.9.2
    • DevTools version 2.48.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios,
      cli-animations, enable-lldb-debugging

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [2.1s]
    • Android SDK at /Users/davidhicks/Library/Android/sdk
    • Emulator version 35.4.9.0 (build_id 13025442) (CL:N/A)
    • Platform android-36, build-tools 35.0.0
    • ANDROID_HOME = /Users/davidhicks/Library/Android/sdk
    • Java binary at: /Library/Java/JavaVirtualMachines/jdk-17.0.2.jdk/Contents/Home/bin/java
      This JDK is specified in your Flutter configuration.
      To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version Java(TM) SE Runtime Environment (build 17.0.2+8-LTS-86)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 16.4) [1,296ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16F6
    • CocoaPods version 1.16.2

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

[✓] Android Studio (version 2024.3) [10ms]
    • 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 21.0.6+-13355223-b631.42)

[✓] VS Code (version 1.104.2) [7ms]
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.120.0

[✓] Connected device (4 available) [6.1s]
    • SM G990U2 (wireless) (mobile)      • adb-R5CTB04978W-5wZCzb._adb-tls-connect._tcp • android-arm64  • Android 15 (API 35)
    • David’s iPhone (wireless) (mobile) • 00008030-00121812342B802E                    • ios            • iOS 26.0 23A5308g
    • macOS (desktop)                    • macos                                        • darwin-arm64   • macOS 15.5 24F74 darwin-arm64
    • Chrome (web)                       • chrome                                       • web-javascript • Google Chrome 140.0.7339.214

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

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: accessibilityAccessibility, e.g. VoiceOver or TalkBack. (aka a11y)f: material designflutter/packages/flutter/material repository.found in release: 3.35Found to occur in 3.35found in release: 3.37Found to occur in 3.37frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-accessibilityOwned by Framework Accessibility team (i.e. responsible for accessibility code in flutter/flutter)triaged-accessibilityTriaged by Framework Accessibility team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions