Skip to content

Commit

Permalink
Create DropdownMenu Widget to Support Material 3 (#116088)
Browse files Browse the repository at this point in the history
* Created ComboBox

* Fixed failing tests

* Reverted the menu style tests change

* Addressed comments

* Updated documentation and rename foregroundColor variable

* Remamed ComboBox to DropdownMenu

* Removed a unused import

* Removed unused import

Co-authored-by: Qun Cheng <[email protected]>
  • Loading branch information
QuncCccccc and QuncCccccc authored Nov 29, 2022
1 parent 1cb16a1 commit 8b86d23
Show file tree
Hide file tree
Showing 9 changed files with 2,257 additions and 36 deletions.
74 changes: 74 additions & 0 deletions examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// Flutter code sample for [DropdownMenu]s. The first dropdown menu has an outlined border
/// which is the default configuration, and the second one has a filled input decoration.
import 'package:flutter/material.dart';

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

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

List<DropdownMenuEntry> getEntryList() {
final List<DropdownMenuEntry> entries = <DropdownMenuEntry>[];

for (int index = 0; index < EntryLabel.values.length; index++) {
// Disabled item 1, 2 and 6.
final bool enabled = index != 1 && index != 2 && index != 6;
entries.add(DropdownMenuEntry(label: EntryLabel.values[index].label, enabled: enabled));
}
return entries;
}

@override
Widget build(BuildContext context) {
final List<DropdownMenuEntry> dropdownMenuEntries = getEntryList();

return MaterialApp(
theme: ThemeData(
useMaterial3: true,
colorSchemeSeed: Colors.green
),
home: Scaffold(
body: SafeArea(
child: Padding(
padding: const EdgeInsets.only(top: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
DropdownMenu(
label: const Text('Label'),
dropdownMenuEntries: dropdownMenuEntries,
),
const SizedBox(width: 20),
DropdownMenu(
enableFilter: true,
leadingIcon: const Icon(Icons.search),
label: const Text('Label'),
dropdownMenuEntries: dropdownMenuEntries,
inputDecorationTheme: const InputDecorationTheme(filled: true),
)
],
),
)
),
),
);
}
}

enum EntryLabel {
item0('Item 0'),
item1('Item 1'),
item2('Item 2'),
item3('Item 3'),
item4('Item 4'),
item5('Item 5'),
item6('Item 6');

const EntryLabel(this.label);
final String label;
}
2 changes: 2 additions & 0 deletions packages/flutter/lib/material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export 'src/material/drawer.dart';
export 'src/material/drawer_header.dart';
export 'src/material/drawer_theme.dart';
export 'src/material/dropdown.dart';
export 'src/material/dropdown_menu.dart';
export 'src/material/dropdown_menu_theme.dart';
export 'src/material/elevated_button.dart';
export 'src/material/elevated_button_theme.dart';
export 'src/material/elevation_overlay.dart';
Expand Down
Loading

0 comments on commit 8b86d23

Please sign in to comment.