Skip to content

Flutter material popup menu doesn't consume the latest context #43824

Closed

Description

@jkurtw

Flutter material popup menu doesn't consume the latest context but the one passed in its constructor. This can be observed if you toggle to dark mode in a popup menu, for example.

Details in b/140223471

Activity

  1. escamoteur commented on Oct 30, 2019

    @escamoteur
    Contributor

    Can you please elaborate on this?
    Please post the output of flutter doctor -v here and tell us if this happens on Android and iOS or only on one platform.

    It would be helpful if you could show us your code.

  2. added
    p: material_uimaterial_ui package in flutter/packages
    frameworkflutter/packages/flutter repository. See also f: labels.
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Oct 30, 2019
  3. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Nov 20, 2019
  4. jefflim-google commented on Feb 8, 2020

    @jefflim-google

    There is code and information in the internal bug b/140223471 and example fix code in cl/266109089

  5. wytesk133 commented on Apr 7, 2022

    @wytesk133
    Contributor

    Here's a minimal repro:

    import 'package:flutter/material.dart';
    
    void main() => runApp(const MyApp());
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
            colorScheme: const ColorScheme.light(),
            popupMenuTheme: PopupMenuThemeData(
              color: const ColorScheme.light().surface,
            ),
          ),
          darkTheme: ThemeData(
            colorScheme: const ColorScheme.dark(),
            popupMenuTheme: PopupMenuThemeData(
              color: const ColorScheme.dark().surface,
            ),
          ),
          home: const HomePage(),
        );
      }
    }
    
    class HomePage extends StatelessWidget {
      const HomePage({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: const Text('Hello Flutter'),
            actions: [
              PopupMenuButton<int>(
                itemBuilder: (context) => <PopupMenuEntry<int>>[
                  const PopupMenuItem<int>(value: 1, child: Text('Item 1')),
                  const PopupMenuItem<int>(value: 2, child: Text('Item 2')),
                  const PopupMenuItem<int>(value: 3, child: Text('Item 3')),
                ],
              )
            ],
          ),
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: const [Text('Nothing here')],
            ),
          ),
        );
      }
    }

    Steps to reproduce:

    1. Open the popup menu
    2. While the menu is opened, toggle system theme (e.g. using Android's Quick Settings)
    3. Observe the popup menu's background color

    Current behavior:
    https://user-images.githubusercontent.com/3948279/162324895-08f0a810-ef49-4d21-9433-e1d53d8deb5f.mp4


    Interesting scenario to try: if we remove these lines,

            popupMenuTheme: PopupMenuThemeData(
              color: const ColorScheme.light().surface,
            ),
            popupMenuTheme: PopupMenuThemeData(
              color: const ColorScheme.dark().surface,
            ),

    the popup menu will now respond to the system theme changes:
    https://user-images.githubusercontent.com/3948279/162324916-3783e1cd-125a-49d7-b8d4-ac0202384d66.mp4

  6. 11 remaining items

  7. moved this from Issue closed with comment to In progress in Nevercodeon Sep 17, 2025
  8. moved this from In progress to No status in Nevercodeon Sep 17, 2025
  9. moved this to In progress in Nevercodeon Sep 17, 2025
  10. moved this from In progress to PR submitted in Nevercodeon Sep 18, 2025
  11. moved this from PR submitted to Done (PR merged) in Nevercodeon Oct 8, 2025
  12. added
    r: fixedIssue is closed as already fixed in a newer version
    on Oct 8, 2025
  13. github-actions commented on Oct 22, 2025

    @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.

  14. locked as resolved and limited conversation to collaborators on Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.p: material_uimaterial_ui package in flutter/packagesr: 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