Skip to content
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

Merged
merged 10 commits into from
Apr 2, 2020

Conversation

impure
Copy link
Contributor

@impure impure commented Mar 20, 2020

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 new dropdownColor 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

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I signed the [CLA].
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read [Handling breaking changes].

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.

@fluttergithubbot fluttergithubbot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Mar 20, 2020
@chunhtai
Copy link
Contributor

For test, you expanded dropdown like this example

testWidgets('Dropdown in ListView', (WidgetTester tester) async {

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
void verifyPaintedShadow(Finder customPaint, int elevation) {

Copy link
Contributor

@chunhtai chunhtai left a 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
Copy link
Contributor

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,
Copy link
Contributor

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

@impure
Copy link
Contributor Author

impure commented Mar 31, 2020

OK, I made those changes.

Copy link
Contributor

@chunhtai chunhtai left a 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 {
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is Material required?

Copy link
Contributor Author

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,
Copy link
Contributor

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(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: indent seems off

@chunhtai
Copy link
Contributor

chunhtai commented Apr 1, 2020

It also seems the branch is behind, can you rebase off the master?

@impure
Copy link
Contributor Author

impure commented Apr 1, 2020

OK, done

@fluttergithubbot fluttergithubbot merged commit 191f86e into flutter:master Apr 2, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
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.

4 participants