Skip to content

Conversation

@QuncCccccc
Copy link
Contributor

@QuncCccccc QuncCccccc commented Jun 29, 2023

Fixes #125199

This PR is to add a new property expandedInsets so that the DropdownMenu can be expandable and has some margins around.

Example: Setting `expandedInsets` to `EdgeInsets.zero`
import 'package:flutter/material.dart';

void main() => runApp(const DropdownMenuExample());

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

  @override
  State<DropdownMenuExample> createState() => _DropdownMenuExampleState();
}

class _DropdownMenuExampleState extends State<DropdownMenuExample> {
  final TextEditingController colorController = TextEditingController();
  ColorLabel? selectedColor;

  @override
  Widget build(BuildContext context) {
    final List<DropdownMenuEntry<ColorLabel>> colorEntries = <DropdownMenuEntry<ColorLabel>>[];
    for (final ColorLabel color in ColorLabel.values) {
      colorEntries.add(
        DropdownMenuEntry<ColorLabel>(value: color, label: color.label, enabled: color.label != 'Grey'),
      );
    }

    return MaterialApp(
      theme: ThemeData(
        useMaterial3: true,
        colorSchemeSeed: Colors.green,
      ),
      home: Scaffold(
        body: Center(
          child: Container(
            width: 500,
            height: 500,
            color: Colors.orange,
            child: DropdownMenu<ColorLabel>(
              expandedInsets: EdgeInsets.zero,
              inputDecorationTheme: const InputDecorationTheme(
                filled: true,
                fillColor: Colors.white,
                border: OutlineInputBorder(),
              ),
              controller: colorController,
              dropdownMenuEntries: colorEntries,
              onSelected: (ColorLabel? color) {
                setState(() {
                  selectedColor = color;
                });
              },
              // expandedInsets: EdgeInsets.only(left: 35.0, right: 20.0, top: 80),
            ),
          ),
        ),
      ),
    );
  }
}

enum ColorLabel {
  blue('Blue', Colors.blue),
  pink('Pink', Colors.pink),
  green('Green', Colors.green),
  yellow('Yellow', Colors.yellow),
  grey('Grey', Colors.grey);

  const ColorLabel(this.label, this.color);
  final String label;
  final Color color;
}
Screenshot 2023-06-28 at 11 33 20 PM

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

@QuncCccccc QuncCccccc changed the title Add expanded feature DropdownMenu can be expanded to its parent size Jun 29, 2023
@QuncCccccc QuncCccccc force-pushed the add_expanded_feature branch from 8f6af01 to 0f8e29a Compare June 29, 2023 22:14
@github-actions github-actions bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Jun 29, 2023
@QuncCccccc QuncCccccc force-pushed the add_expanded_feature branch from bcda162 to f18bd2f Compare July 5, 2023 23:57
@QuncCccccc QuncCccccc requested a review from HansMuller July 6, 2023 05:56
@QuncCccccc QuncCccccc marked this pull request as ready for review July 6, 2023 05:56
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some feedback about the API doc

/// will be expanded to its parent size. The values of [expandedInsets] are
/// margins for the text field. In other words, If this is [EdgeInsets.zero],
/// the width of the text field will be the same as its parent's width.
///
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make sure that it's clear; could add one more statement:

The [expandedInsets]' top and bottom are ignored, only its left and right properties are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Thanks for helping review this! Just updated!

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a few more tweaks to the API doc

@HansMuller HansMuller added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 11, 2023
@auto-submit auto-submit bot merged commit 12acff8 into master Jul 11, 2023
@auto-submit auto-submit bot deleted the add_expanded_feature branch July 11, 2023 17:08
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 12, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 12, 2023
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Jul 12, 2023
Roll Flutter from 3ec96a8 to 544d30d (66 revisions)

flutter/flutter@3ec96a8...544d30d

2023-07-12 engine-flutter-autoroll@skia.org Roll Packages from 188a846 to 2508714 (14 revisions) (flutter/flutter#130418)
2023-07-12 tessertaha@gmail.com Update `RadioListTile` tests format for M2/M3 (flutter/flutter#130391)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from d68ea304eeda to 5c887028810d (2 revisions) (flutter/flutter#130413)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from c7317a58466e to d68ea304eeda (1 revision) (flutter/flutter#130410)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 3dbe7dbeb5d4 to c7317a58466e (1 revision) (flutter/flutter#130402)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 73093fdd77c3 to 3dbe7dbeb5d4 (1 revision) (flutter/flutter#130399)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 29c5c41eeb19 to 73093fdd77c3 (2 revisions) (flutter/flutter#130398)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 3482e05776a7 to 29c5c41eeb19 (1 revision) (flutter/flutter#130393)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 7de68c62742d to 3482e05776a7 (2 revisions) (flutter/flutter#130390)
2023-07-12 104349824+huycozy@users.noreply.github.com Make new issue template for 1P package (flutter/flutter#130065)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 1b44d7ee1a60 to 7de68c62742d (4 revisions) (flutter/flutter#130384)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from e109a3c0c347 to 1b44d7ee1a60 (3 revisions) (flutter/flutter#130380)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from d00590fde18c to e109a3c0c347 (1 revision) (flutter/flutter#130371)
2023-07-12 engine-flutter-autoroll@skia.org Roll Flutter Engine from 875d87e02276 to d00590fde18c (5 revisions) (flutter/flutter#130369)
2023-07-12 polinach@google.com Enable not GCed leak tracking. (flutter/flutter#130159)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from e2df01610fb3 to 875d87e02276 (3 revisions) (flutter/flutter#130359)
2023-07-11 cbobbe@zulip.com autocomplete: Remove mistaken paragraph in `onSelected` doc (flutter/flutter#130190)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 59f234645dd2 to e2df01610fb3 (3 revisions) (flutter/flutter#130357)
2023-07-11 thkim1011@users.noreply.github.com Refactor refresh_indicator.1.dart to not use shrinkwrap (flutter/flutter#129377)
2023-07-11 info@ttanimichi.com Links in `material` library docs are outdated (flutter/flutter#129891)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from afee1db31e5e to 59f234645dd2 (2 revisions) (flutter/flutter#130352)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 75ada1bdf9fd to afee1db31e5e (1 revision) (flutter/flutter#130349)
2023-07-11 polinach@google.com Upgrade leak_tracker to 7.0.6. (flutter/flutter#130346)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 0011db79d41f to 75ada1bdf9fd (2 revisions) (flutter/flutter#130345)
2023-07-11 137456488+flutter-pub-roller-bot@users.noreply.github.com Roll pub packages (flutter/flutter#130289)
2023-07-11 36861262+QuncCccccc@users.noreply.github.com `DropdownMenu` can be expanded to its parent size (flutter/flutter#129753)
2023-07-11 engine-flutter-autoroll@skia.org Roll Packages from 4469c5e to 188a846 (6 revisions) (flutter/flutter#130340)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from d75c70870f86 to 0011db79d41f (2 revisions) (flutter/flutter#130337)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 5e9f0d61a42a to d75c70870f86 (1 revision) (flutter/flutter#130332)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 417c50199e14 to 5e9f0d61a42a (1 revision) (flutter/flutter#130330)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from bfda8f173fea to 417c50199e14 (2 revisions) (flutter/flutter#130324)
2023-07-11 tessertaha@gmail.com Add `Badge` widget to `NavigationBar` and `NavigationRail` examples (flutter/flutter#129834)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 2139c8a90822 to bfda8f173fea (2 revisions) (flutter/flutter#130321)
2023-07-11 ian@hixie.ch Update labeler for recent changes (flutter/flutter#130168)
2023-07-11 hey@darshanrander.com fix: `ExpansionTileTheme.shape` assignment in `ExpansionTile` (flutter/flutter#127749)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 12aa98177cf2 to 2139c8a90822 (2 revisions) (flutter/flutter#130316)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 767f2fb8ab03 to 12aa98177cf2 (1 revision) (flutter/flutter#130315)
2023-07-11 ian@hixie.ch Implement preferPaintInterior correctly for _CompoundBorder (flutter/flutter#129851)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 153d9e1d598a to 767f2fb8ab03 (1 revision) (flutter/flutter#130313)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 2c82dd7ec54b to 153d9e1d598a (2 revisions) (flutter/flutter#130311)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 312e4813a880 to 2c82dd7ec54b (1 revision) (flutter/flutter#130309)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 95316fbc25a7 to 312e4813a880 (2 revisions) (flutter/flutter#130307)
2023-07-11 robert.ancell@canonical.com Add Linux implementation of the platform view example (flutter/flutter#123731)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from daecd616f5a7 to 95316fbc25a7 (4 revisions) (flutter/flutter#130305)
2023-07-11 engine-flutter-autoroll@skia.org Roll Flutter Engine from 2a0dd9d2f28e to daecd616f5a7 (3 revisions) (flutter/flutter#130298)
2023-07-10 engine-flutter-autoroll@skia.org Roll Flutter Engine from 7d054abf842c to 2a0dd9d2f28e (4 revisions) (flutter/flutter#130296)
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Material 3] DropdownMenu not expanding according to its parent's width.

2 participants