Skip to content

Commit 8b86d23

Browse files
authored
Create DropdownMenu Widget to Support Material 3 (#116088)
* 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]>
1 parent 1cb16a1 commit 8b86d23

File tree

9 files changed

+2257
-36
lines changed

9 files changed

+2257
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
/// Flutter code sample for [DropdownMenu]s. The first dropdown menu has an outlined border
6+
/// which is the default configuration, and the second one has a filled input decoration.
7+
8+
import 'package:flutter/material.dart';
9+
10+
void main() => runApp(const DropdownMenuExample());
11+
12+
class DropdownMenuExample extends StatelessWidget {
13+
const DropdownMenuExample({super.key});
14+
15+
List<DropdownMenuEntry> getEntryList() {
16+
final List<DropdownMenuEntry> entries = <DropdownMenuEntry>[];
17+
18+
for (int index = 0; index < EntryLabel.values.length; index++) {
19+
// Disabled item 1, 2 and 6.
20+
final bool enabled = index != 1 && index != 2 && index != 6;
21+
entries.add(DropdownMenuEntry(label: EntryLabel.values[index].label, enabled: enabled));
22+
}
23+
return entries;
24+
}
25+
26+
@override
27+
Widget build(BuildContext context) {
28+
final List<DropdownMenuEntry> dropdownMenuEntries = getEntryList();
29+
30+
return MaterialApp(
31+
theme: ThemeData(
32+
useMaterial3: true,
33+
colorSchemeSeed: Colors.green
34+
),
35+
home: Scaffold(
36+
body: SafeArea(
37+
child: Padding(
38+
padding: const EdgeInsets.only(top: 20),
39+
child: Row(
40+
mainAxisAlignment: MainAxisAlignment.center,
41+
children: <Widget>[
42+
DropdownMenu(
43+
label: const Text('Label'),
44+
dropdownMenuEntries: dropdownMenuEntries,
45+
),
46+
const SizedBox(width: 20),
47+
DropdownMenu(
48+
enableFilter: true,
49+
leadingIcon: const Icon(Icons.search),
50+
label: const Text('Label'),
51+
dropdownMenuEntries: dropdownMenuEntries,
52+
inputDecorationTheme: const InputDecorationTheme(filled: true),
53+
)
54+
],
55+
),
56+
)
57+
),
58+
),
59+
);
60+
}
61+
}
62+
63+
enum EntryLabel {
64+
item0('Item 0'),
65+
item1('Item 1'),
66+
item2('Item 2'),
67+
item3('Item 3'),
68+
item4('Item 4'),
69+
item5('Item 5'),
70+
item6('Item 6');
71+
72+
const EntryLabel(this.label);
73+
final String label;
74+
}

packages/flutter/lib/material.dart

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ export 'src/material/drawer.dart';
7777
export 'src/material/drawer_header.dart';
7878
export 'src/material/drawer_theme.dart';
7979
export 'src/material/dropdown.dart';
80+
export 'src/material/dropdown_menu.dart';
81+
export 'src/material/dropdown_menu_theme.dart';
8082
export 'src/material/elevated_button.dart';
8183
export 'src/material/elevated_button_theme.dart';
8284
export 'src/material/elevation_overlay.dart';

0 commit comments

Comments
 (0)