Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@777genius
Copy link
Contributor

@777genius 777genius commented Nov 19, 2025

Description

This PR improves the clarity of the error message shown when developers provide both color and decoration parameters to a Container widget.

Problem

The previous assertion message was confusing and contradictory:

Cannot provide both a color and a decoration
To provide both, use "decoration: BoxDecoration(color: color)".

This message stated "Cannot provide both" but then suggested "To provide both, use...", which confused developers about the actual requirement. The suggestion appeared to offer a workaround to use both parameters together, when in fact it was explaining how to migrate from using color to using decoration exclusively.

Solution

Updated the assertion message to clearly explain:

  • The color parameter is a shorthand for decoration: BoxDecoration(color: color)
  • Developers should use either color OR decoration, not both
  • To use both a color and other decoration properties (like borders, shadows, etc.), set the color within the BoxDecoration instead

New message:

Cannot provide both a color and a decoration.
The color argument is just a shorthand for "decoration: BoxDecoration(color: color)".
To use both a color and other decoration properties, set the color in the BoxDecoration instead.

Related Issues

Fixes #119484

Pre-launch Checklist

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Nov 19, 2025
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the clarity of an error message in the Container widget. The assertion message for when both color and decoration are provided has been rewritten to be more explanatory and less confusing. A corresponding test case has been added to verify that the new, clearer error message is thrown as expected. The changes are correct and improve the developer experience.

The previous assertion message was confusing because it stated
'Cannot provide both' but then suggested 'To provide both, use...',
which contradicted the restriction. This confused developers about
the actual requirement.

Updated the message to clearly explain:
- The color parameter is a shorthand for decoration: BoxDecoration(color: color)
- Developers should use either color OR decoration, not both
- To use both color and other decoration properties, set the color
  within BoxDecoration

Fixes flutter#119484
@777genius 777genius force-pushed the fix-container-error-message-119484 branch from d420480 to db3b47e Compare November 19, 2025 19:40
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests or get an explicit test exemption before merging.

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. If you believe this PR qualifies for a test exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@Piinks Piinks requested a review from dkwingsmt December 9, 2025 23:22
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM 👍 . Thanks for improving this! From the issue it looks like indeed this was tripping people up.

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

Great writeup. Thanks!

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 30, 2025
@auto-submit auto-submit bot added this pull request to the merge queue Dec 31, 2025
Merged via the queue into flutter:master with commit a634f08 Dec 31, 2025
71 checks passed
@flutter-dashboard flutter-dashboard bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Dec 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Providing Container a color and decoration produces an unclear error message

3 participants