-
Notifications
You must be signed in to change notification settings - Fork 27.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added ability to change dropdown colour manually #52982
Conversation
For test, you expanded dropdown like this example
From there, you can grab the CustomPainter that paints the retangle by using find.ancestor. Once you have the CustomPainter, you can use expect(CustomPainter, paint.rrect(...)). See this example
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable change, however, a test is needed
@@ -1030,6 +1039,10 @@ class DropdownButton<T> extends StatefulWidget { | |||
/// {@macro flutter.widgets.Focus.autofocus} | |||
final bool autofocus; | |||
|
|||
/// The color of the dropdown's background color. If not provided the theme's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you break the If
into a new line?
/// The color of the dropdown's background color.
///
/// If it is null, the theme's canvas color will be used instead.
@@ -800,6 +808,7 @@ class DropdownButton<T> extends StatefulWidget { | |||
this.focusColor, | |||
this.focusNode, | |||
this.autofocus = false, | |||
this.dropdownColor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Somewhere in the DropdownButton doc string should mention how and when to use dropdownColor
OK, I made those changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, with some minor nits
@@ -174,6 +176,41 @@ void verifyPaintedShadow(Finder customPaint, int elevation) { | |||
); | |||
} | |||
|
|||
Future<void> checkDropdownColor(WidgetTester tester, {Color color}) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -789,6 +797,10 @@ class DropdownButton<T> extends StatefulWidget { | |||
/// The [elevation] and [iconSize] arguments must not be null (they both have | |||
/// defaults, so do not need to be specified). The boolean [isDense] and | |||
/// [isExpanded] arguments must not be null. | |||
/// | |||
/// The [dropdownColor] argument specifies the background color of the | |||
/// dropdown when it is open. If it is null the current theme's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is null, the current theme's...
@@ -1049,6 +1062,11 @@ class DropdownButton<T> extends StatefulWidget { | |||
/// {@macro flutter.widgets.Focus.autofocus} | |||
final bool autofocus; | |||
|
|||
/// The color of the dropdown's background color. | |||
/// | |||
/// If not provided the theme's [ThemeData.canvasColor] will be used instead. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is not provided, the theme's...
@@ -1049,6 +1062,11 @@ class DropdownButton<T> extends StatefulWidget { | |||
/// {@macro flutter.widgets.Focus.autofocus} | |||
final bool autofocus; | |||
|
|||
/// The color of the dropdown's background color. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The background color of the dropdown.
const String text = 'foo'; | ||
await tester.pumpWidget( | ||
MaterialApp( | ||
home: Material( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is Material required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MaterialApp can be replaced by TestApp and Material can be replaced by Scaffold, but it appears to be required.
|
||
expect( | ||
find.ancestor( | ||
of: find.text(text).last, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indent seems off
await tester.pump(); | ||
|
||
expect( | ||
find.ancestor( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: indent seems off
It also seems the branch is behind, can you rebase off the master? |
OK, done |
Description
Before there was no way to manually set the colour of a dropdown (when it is open) and is always set to the theme's
canvasColor
. This is a bit weird as most other widgets have an option to override their default colour. This PR adds that ability using the newdropdownColor
parameter.Related Issues
Tests
No tests as I could not find a way to easily start a dropdown as expanded. Did add a hook in /packages/flutter/test/material/dropdown_test.dart to test the functionality though.'DropdownButton uses default color when expanded' and 'DropdownButton hint displays properly when selectedItemBuilder is defined' in dropdown_test.dart.
Checklist
///
).flutter analyze --flutter-repo
) does not report any problems on my PR.Breaking Change
Did any tests fail when you ran them? Please read [Handling breaking changes].