Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
336d60d2
Unverified
Commit
336d60d2
authored
Aug 30, 2023
by
Hans Muller
Committed by
GitHub
Aug 30, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated DropdownMenu example and added a test (#133592)
parent
1e770c38
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
114 additions
and
47 deletions
+114
-47
check_code_samples.dart
dev/bots/check_code_samples.dart
+0
-1
dropdown_menu.0.dart
examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart
+59
-46
dropdown_menu.0_test.dart
...api/test/material/dropdown_menu/dropdown_menu.0_test.dart
+55
-0
No files found.
dev/bots/check_code_samples.dart
View file @
336d60d2
...
...
@@ -321,7 +321,6 @@ final Set<String> _knownMissingTests = <String>{
'examples/api/test/material/scrollbar/scrollbar.1_test.dart'
,
'examples/api/test/material/scrollbar/scrollbar.0_test.dart'
,
'examples/api/test/material/dropdown_menu/dropdown_menu.1_test.dart'
,
'examples/api/test/material/dropdown_menu/dropdown_menu.0_test.dart'
,
'examples/api/test/material/radio/radio.toggleable.0_test.dart'
,
'examples/api/test/material/radio/radio.0_test.dart'
,
'examples/api/test/material/search_anchor/search_anchor.0_test.dart'
,
...
...
examples/api/lib/material/dropdown_menu/dropdown_menu.0.dart
View file @
336d60d2
...
...
@@ -2,13 +2,45 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// which is the default configuration, and the second one has a filled input decoration.
import
'package:flutter/material.dart'
;
/// Flutter code sample for [DropdownMenu]s. The first dropdown menu has an outlined border.
// Flutter code sample for [DropdownMenu]s. The first dropdown menu
// has the default outlined border and demos using the
// [DropdownMenuEntry] style parameter to customize its appearance.
// The second dropdown menu customizes the appearance of the dropdown
// menu's text field with its [InputDecorationTheme] parameter.
void
main
(
)
{
runApp
(
const
DropdownMenuExample
());
}
// DropdownMenuEntry labels and values for the first dropdown menu.
enum
ColorLabel
{
blue
(
'Blue'
,
Colors
.
blue
),
pink
(
'Pink'
,
Colors
.
pink
),
green
(
'Green'
,
Colors
.
green
),
yellow
(
'Orange'
,
Colors
.
orange
),
grey
(
'Grey'
,
Colors
.
grey
);
const
ColorLabel
(
this
.
label
,
this
.
color
);
final
String
label
;
final
Color
color
;
}
// DropdownMenuEntry labels and values for the second dropdown menu.
enum
IconLabel
{
smile
(
'Smile'
,
Icons
.
sentiment_satisfied_outlined
),
cloud
(
'Cloud'
,
Icons
.
cloud_outlined
,
),
brush
(
'Brush'
,
Icons
.
brush_outlined
),
heart
(
'Heart'
,
Icons
.
favorite
);
void
main
(
)
=>
runApp
(
const
DropdownMenuExample
());
const
IconLabel
(
this
.
label
,
this
.
icon
);
final
String
label
;
final
IconData
icon
;
}
class
DropdownMenuExample
extends
StatefulWidget
{
const
DropdownMenuExample
({
super
.
key
});
...
...
@@ -25,18 +57,6 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
@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'
),
);
}
final
List
<
DropdownMenuEntry
<
IconLabel
>>
iconEntries
=
<
DropdownMenuEntry
<
IconLabel
>>[];
for
(
final
IconLabel
icon
in
IconLabel
.
values
)
{
iconEntries
.
add
(
DropdownMenuEntry
<
IconLabel
>(
value:
icon
,
label:
icon
.
label
));
}
return
MaterialApp
(
theme:
ThemeData
(
useMaterial3:
true
,
...
...
@@ -55,20 +75,30 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
initialSelection:
ColorLabel
.
green
,
controller:
colorController
,
label:
const
Text
(
'Color'
),
dropdownMenuEntries:
colorEntries
,
onSelected:
(
ColorLabel
?
color
)
{
setState
(()
{
selectedColor
=
color
;
});
},
dropdownMenuEntries:
ColorLabel
.
values
.
map
<
DropdownMenuEntry
<
ColorLabel
>>(
(
ColorLabel
color
)
{
return
DropdownMenuEntry
<
ColorLabel
>(
value:
color
,
label:
color
.
label
,
enabled:
color
.
label
!=
'Grey'
,
style:
MenuItemButton
.
styleFrom
(
foregroundColor:
color
.
color
,
),
);
}
).
toList
(),
),
const
SizedBox
(
width:
2
0
),
const
SizedBox
(
width:
2
4
),
DropdownMenu
<
IconLabel
>(
controller:
iconController
,
enableFilter:
true
,
leadingIcon:
const
Icon
(
Icons
.
search
),
label:
const
Text
(
'Icon'
),
dropdownMenuEntries:
iconEntries
,
inputDecorationTheme:
const
InputDecorationTheme
(
filled:
true
,
contentPadding:
EdgeInsets
.
symmetric
(
vertical:
5.0
),
...
...
@@ -78,7 +108,16 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
selectedIcon
=
icon
;
});
},
)
dropdownMenuEntries:
IconLabel
.
values
.
map
<
DropdownMenuEntry
<
IconLabel
>>(
(
IconLabel
icon
)
{
return
DropdownMenuEntry
<
IconLabel
>(
value:
icon
,
label:
icon
.
label
,
leadingIcon:
Icon
(
icon
.
icon
),
);
},
).
toList
(),
),
],
),
),
...
...
@@ -105,29 +144,3 @@ class _DropdownMenuExampleState extends State<DropdownMenuExample> {
);
}
}
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
;
}
enum
IconLabel
{
smile
(
'Smile'
,
Icons
.
sentiment_satisfied_outlined
),
cloud
(
'Cloud'
,
Icons
.
cloud_outlined
,
),
brush
(
'Brush'
,
Icons
.
brush_outlined
),
heart
(
'Heart'
,
Icons
.
favorite
);
const
IconLabel
(
this
.
label
,
this
.
icon
);
final
String
label
;
final
IconData
icon
;
}
examples/api/test/material/dropdown_menu/dropdown_menu.0_test.dart
0 → 100644
View file @
336d60d2
// 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.
import
'package:flutter/material.dart'
;
import
'package:flutter_api_samples/material/dropdown_menu/dropdown_menu.0.dart'
as
example
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
testWidgets
(
'DropdownMenu'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
const
example
.
DropdownMenuExample
(),
);
expect
(
find
.
text
(
'You selected a Blue Smile'
),
findsNothing
);
final
Finder
colorMenu
=
find
.
byType
(
DropdownMenu
<
example
.
ColorLabel
>);
final
Finder
iconMenu
=
find
.
byType
(
DropdownMenu
<
example
.
IconLabel
>);
expect
(
colorMenu
,
findsOneWidget
);
expect
(
iconMenu
,
findsOneWidget
);
Finder
findMenuItem
(
String
label
)
{
return
find
.
widgetWithText
(
MenuItemButton
,
label
).
last
;
}
await
tester
.
tap
(
colorMenu
);
await
tester
.
pumpAndSettle
();
expect
(
findMenuItem
(
'Blue'
),
findsOneWidget
);
expect
(
findMenuItem
(
'Pink'
),
findsOneWidget
);
expect
(
findMenuItem
(
'Green'
),
findsOneWidget
);
expect
(
findMenuItem
(
'Orange'
),
findsOneWidget
);
expect
(
findMenuItem
(
'Grey'
),
findsOneWidget
);
await
tester
.
tap
(
findMenuItem
(
'Blue'
));
// The DropdownMenu's onSelected callback is delayed
// with SchedulerBinding.instance.addPostFrameCallback
// to give the focus a chance to return to where it was
// before the menu appeared. The pumpAndSettle()
// give the callback a chance to run.
await
tester
.
pumpAndSettle
();
await
tester
.
tap
(
iconMenu
);
await
tester
.
pumpAndSettle
();
expect
(
findMenuItem
(
'Smile'
),
findsOneWidget
);
expect
(
findMenuItem
(
'Cloud'
),
findsOneWidget
);
expect
(
findMenuItem
(
'Brush'
),
findsOneWidget
);
expect
(
findMenuItem
(
'Heart'
),
findsOneWidget
);
await
tester
.
tap
(
findMenuItem
(
'Smile'
));
await
tester
.
pumpAndSettle
();
expect
(
find
.
text
(
'You selected a Blue Smile'
),
findsOneWidget
);
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment