Skip to content

[Windows] Focusing a nested popup closes both popups and sends the main window behind other applications #193782

Description

@josh-audio

This issue occurs on Windows, but not on Linux. I haven't tested on other platforms.

Steps to reproduce

  1. Create a new Flutter project, paste the code sample below into main.dart, and run with -d windows
  2. Click to open the first popup, and then click the button to focus it - this works as intended
  3. Click the button to open the second popup, then click to focus it

Expected results

The popups both remain open, and the main window remains on top.

Actual results

The popups both close, and the window is sent behind other open windows.

Code sample

Code sample
import 'package:flutter/widgets.dart';
import 'package:flutter/src/foundation/_features.dart' as experimental;
import 'package:flutter/src/widgets/_window.dart';
import 'package:flutter/src/widgets/_window_positioner.dart';

void main() {
  experimental.isWindowingEnabled = true;
  WidgetsFlutterBinding.ensureInitialized();
  final window = _RunnerWindow();
  final popups = ValueNotifier<List<PopupWindowController>>([]);

  void openPopup() {
    if (popups.value.length == 2) return;
    late final PopupWindowController popup;
    popup = PopupWindowController(
      // The first popup belongs to the runner window; the second to the first.
      parent: popups.value.isEmpty ? window : popups.value.last,
      anchorRect: popups.value.isEmpty
          ? const Rect.fromLTWH(40, 80, 1, 1)
          : const Rect.fromLTWH(280, 0, 1, 1),
      positioner: const WindowPositioner(
        parentAnchor: WindowPositionerAnchor.topLeft,
        childAnchor: WindowPositionerAnchor.topLeft,
      ),
      delegate: _PopupDelegate(() {
        popups.value = popups.value.where((p) => p != popup).toList();
      }),
    );
    popups.value = [...popups.value, popup];
  }

  Widget button(String label, VoidCallback onTap) => GestureDetector(
    onTap: onTap,
    child: Container(
      margin: const EdgeInsets.only(top: 12),
      padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
      decoration: BoxDecoration(
        color: const Color(0xffffffff),
        border: Border.all(),
      ),
      child: Text(label),
    ),
  );

  Widget popupPanel(
    String title,
    Color color, {
    VoidCallback? openSecond,
  }) => Focus(
    child: Builder(
      builder: (context) => ColoredBox(
        color: color,
        child: SizedBox(
          width: 280,
          child: Padding(
            padding: const EdgeInsets.all(12),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Text(title),
                Text(
                  Focus.of(context).hasFocus
                      ? 'Flutter focus: focused'
                      : 'Flutter focus: not focused',
                ),
                // Request focus in this popup only when its button is pressed.
                button(
                  'Focus this popup',
                  () => Focus.of(context).requestFocus(),
                ),
                if (openSecond != null) button('Open second popup', openSecond),
              ],
            ),
          ),
        ),
      ),
    ),
  );

  runApp(
    Directionality(
      textDirection: TextDirection.ltr,
      child: DefaultTextStyle(
        style: const TextStyle(color: Color(0xff000000), fontSize: 18),
        child: ValueListenableBuilder(
          valueListenable: popups,
          builder: (context, controllers, _) => ViewAnchor(
            // Each popup renders into its own native view.
            view: ViewCollection(
              views: [
                for (final (index, controller) in controllers.indexed)
                  PopupWindow(
                    key: ObjectKey(controller),
                    controller: controller,
                    child: popupPanel(
                      index == 0 ? 'First popup' : 'Second popup',
                      index == 0
                          ? const Color(0xffc8f2cc)
                          : const Color(0xffffd0b3),
                      openSecond: index == 0 ? openPopup : null,
                    ),
                  ),
              ],
            ),
            child: ColoredBox(
              color: const Color(0xffc8e6ff),
              child: Center(
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    const Text('Main window'),
                    button('Open first popup', () {
                      if (popups.value.isEmpty) openPopup();
                    }),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    ),
  );
}

// Only rootView is needed to use the standard runner window as a popup parent.
class _RunnerWindow extends RegularWindowController {
  _RunnerWindow() : super.empty() {
    rootView = WidgetsBinding.instance.platformDispatcher.implicitView!;
  }

  @override
  dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
}

class _PopupDelegate extends PopupWindowControllerDelegate {
  _PopupDelegate(this.onDestroyed);
  final VoidCallback onDestroyed;

  @override
  void onWindowDestroyed() => onDestroyed();
}

Screenshots or Video

Screenshots / Video demonstration Image

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.47.6, on Microsoft Windows [Version 10.0.26200.9457], locale en-US) [356ms]
    • Flutter version 3.47.6 on channel stable at C:\Users\qbgee\Documents\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5fc346839b (3 days ago), 2026-09-30 15:02:49 -0700
    • Engine revision 692136cb65
    • Dart version 3.13.5
    • DevTools version 2.60.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android,
      enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager,
      omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration

[✓] Windows Version (Windows 11 or higher, 25H2, 2009) [1,584ms]

[✗] Android toolchain - develop for Android devices [129ms]
    ✗ Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/to/windows-android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[✓] Chrome - develop for the web [99ms]
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[✓] Visual Studio - develop Windows apps (Visual Studio Community 2026 18.4.2) [97ms]
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\18\Community
    • Visual Studio Community 2026 version 18.4.11620.152
    • Windows 10 SDK version 10.0.26100.0

[✓] Connected device (3 available) [136ms]
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26200.9457]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 149.0.7827.201
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 154.0.4258.53

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

! Doctor found issues in 1 category.

Activity

  1. added
    in triage
    on Oct 5, 2026
  2. puneetkukreja98 commented on Oct 5, 2026

    @puneetkukreja98
    Contributor

    @josh-audio Thanks for reporting it, I was able to reproduce it.
    flutter doctor -v:

    [√] Flutter (Channel stable, 3.47.2, on Microsoft Windows [Version 10.0.26200.9168], locale en-IN) [369ms]
        • Flutter version 3.47.2 on channel stable at C:\Developer\flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision d3b14c8769 (6 weeks ago), 2026-08-26 16:07:51 -0700
        • Engine revision a804b26164
        • Dart version 3.13.2
        • DevTools version 2.60.0
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android,
          enable-ios, cli-animations, enable-native-assets, enable-record-use, enable-swift-package-manager,
          omit-legacy-version-file, enable-lldb-debugging, enable-uiscene-migration
    
    [√] Windows Version (Windows 11 or higher, 25H2, 2009) [1,085ms]
    
    [√] Android toolchain - develop for Android devices (Android SDK version 37.0.0) [2.5s]
        • Android SDK at C:\Users\Puneet\AppData\Local\Android\sdk
        • Emulator version 36.6.11.0 (build_id 15507667) (CL:N/A)
        • Platform android-37.1, build-tools 37.0.0
        • Java binary at: C:\Program Files\Android\Android Studio1\jbr\bin\java
          This is the JDK bundled with the latest Android Studio installation on this machine.
          To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version OpenJDK Runtime Environment (build 21.0.10+-14961533-b1163.108)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web [124ms]
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop Windows apps (Visual Studio Community 2026 18.3.2) [123ms]
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\18\Community
        • Visual Studio Community 2026 version 18.3.11520.95
        • Windows 10 SDK version 10.0.26100.0
    
    [√] Connected device (3 available) [561ms]
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.26200.9168]
        • Chrome (web)      • chrome  • web-javascript • Google Chrome 153.0.8010.53
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 154.0.4258.53
    
    [√] Network resources [567ms]
        • All expected network resources are available.
    
    • No issues found!
  3. added
    a: desktop
    a: multi window
    team-windows
    and removed
    in triage
    on Oct 5, 2026
  4. self-assigned this
    on Oct 7, 2026
  5. added
    triaged-windows
    P2
    on Oct 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2a: desktopa: multi windowteam-windowstriaged-windows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions