Repository navigation
Providing Container a color and decoration produces an unclear error message #119484
Copy link
Copy link
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: error messageError messages from the Flutter frameworkError messages from the Flutter frameworkd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Description
Similar to #36161, but that issue was closed with the incorrect error message in place.
Steps to Reproduce
- Create a
Containerwith any validcolorproperty. - Add the
decorationproperty to the container. - Give
decorationaBoxDecorationwith a validcolorproperty. - An exception is caught and an error message is printed.
Expected results:
An error message that clearly defines the issue and optionally provides a way to fix the error.
Actual results:
════════ Exception caught by widgets library ═══════════════════════════════════
The following assertion was thrown building Themes(dirty, dependencies: [_InheritedTheme, _LocalizationsScope-[GlobalKey#50d61]]):
Cannot provide both a color and a decoration
To provide both, use "decoration: BoxDecoration(color: color)".
The error message clearly defines the issue, however the suggested fix reads: To provide both, use "decoration: BoxDecoration(color: color)".
This is an incorrect suggestion because Container has checks to verify it was NOT provided both. The error message should clearly communicate the proper condition--which is passing Container.color OR Container.decoration, not both like the error message is suggesting.
Example:
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new HomePage(),
));
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => new _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
width: 50.0,
height: 50.0,
color: Colors.blue,
decoration: BoxDecoration(
color: Colors.blue,
),
);
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P2Important issues not at the top of the work listImportant issues not at the top of the work lista: error messageError messages from the Flutter frameworkError messages from the Flutter frameworkd: api docsIssues with https://api.flutter.dev/Issues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.flutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamOwned by Framework teamtriaged-frameworkTriaged by Framework teamTriaged by Framework team
Activity
darshankawar commentedon Jan 30, 2023
Thanks for the report @JoshMart
The
Containerwidget's documentation says:Indicating you should not do below:
And that's what the error message in console also indicates:
Which I think is well explained and this assertion also helps to indicate what changes you need to make in your code implementation.
Let us know if this helps to address the issue you raised.
JoshMart commentedon Jan 30, 2023
Thanks for the response. I would agree that within the context of the
Containerdocumentation this error messages begins to make more sense. However the user does not see the additional comment block you provided unless they start digging through the source code. From the perspective of the user:Cannot provide both a color and a decoration To provide both, use "decoration: BoxDecoration(color: color)"..The error message is vague because it contradicts itself by saying
Cannot provide both... To provide both. In fact, you had to go into the source code and provide documentation fromContainerin order to put the error message in context and provide more clarity. That is another smell the error message isn't clear enough to stand on its own--the user shouldn't have to dig through source code in order to understand an error message.The error message also makes it sound like you can still provide both--which the second part of the error message says you can do-- by using the exact
decorationgiven in the error message. It would be more clear ifTo provide bothwas dropped from the second part of the error message and replaced with entirely different wording. Maybe something likeTo set a color with a decoration, ....darshankawar commentedon Jan 31, 2023
Thanks for the feedback. I am keeping this issue open for team's thoughts on current error message displayed and if there's any scope to improve per OP.
4 remaining items
Improve Container color/decoration error message clarity
Improve Container color/decoration error message clarity
Improve Container color/decoration error message clarity
baoyachi commentedon Dec 4, 2025
I can confirm this assertion is very confusing for newcomers. As a beginner, when I first encountered this "To provide both..." message, I was thoroughly confused and wasted significant time trying to follow the contradictory instruction. This is a severe hurdle for new users.
It's nearly the end of 2025, and this issue appears to be left in the dust of history.
Fix misleading error message for color/decoration conflict
Improve Container color/decoration error message clarity (#178823)
Fix misleading error message for color/decoration conflict
github-actions commentedon Jan 19, 2026
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.Fix misleading error message for color/decoration conflict
Fix misleading error message for color/decoration conflict (relands #…
Fix misleading error message for color/decoration conflict (relands f…
Fix misleading error message for color/decoration conflict (relands f…