Skip to content

Add option to control whether the root DropdownMenu can be closed or not #139269

@josh-burton

Description

@josh-burton

Steps to reproduce

  1. Created nested MenuAnchors
  2. Select a MenuItem from the child MenuAnchor

Expected results

The child Menu is closed (or a configuration option exists to control whether the root menu will be closed)

Actual results

The child and parent menus are both closed

Code sample

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

const Color darkBlue = Color.fromARGB(255, 18, 32, 47);

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.dark().copyWith(
        scaffoldBackgroundColor: darkBlue,
      ),
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: MyWidget(),
        ),
      ),
    );
  }
}

class MyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: Center(
          child: MenuAnchor(
            menuChildren: [
              ParentMenuModal(),
            ],
            builder: (context, controller, widget) {
              return ElevatedButton(
                child: const Text("Click me"),
                onPressed: () {
                  controller.open();
                },
              );
            },
          ),
        )
    );
  }
}

class ParentMenuModal extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return DropdownMenu(
      label: const Text('Menu'),
      initialSelection: "1",
      dropdownMenuEntries: ["1", "2", "3"]
          .map(
            (it) =>
            DropdownMenuEntry(
              value: it,
              label: it,
            ),
      )
          .toList(),
    );
  }
}

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterf: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.r: 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