Skip to content

Providing Container a color and decoration produces an unclear error message #119484

Description

@JoshMart

Similar to #36161, but that issue was closed with the incorrect error message in place.

Steps to Reproduce

  1. Create a Container with any valid color property.
  2. Add the decoration property to the container.
  3. Give decoration a BoxDecoration with a valid color property.
  4. 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,
      ),
    );
  }
}

Activity

  1. darshankawar commented on Jan 30, 2023

    @darshankawar
    Member

    Thanks for the report @JoshMart
    The Container widget's documentation says:

    /// The `color` and `decoration` arguments cannot both be supplied, since
      /// it would potentially result in the decoration drawing over the background
      /// color. To supply a decoration with a color, use `decoration:
      /// BoxDecoration(color: color)`.
    

    Indicating you should not do below:

    color: Colors.blue,
    decoration: BoxDecoration(
    color: Colors.blue,
    ),

    And that's what the error message in console also indicates:

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

    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.

  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 30, 2023
  3. JoshMart commented on Jan 30, 2023

    @JoshMart
    Author

    Thanks for the response. I would agree that within the context of the Container documentation 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:

    1. A user provides both a color and decoration
    2. They receive an error message saying says Cannot provide both a color and a decoration To provide both, use "decoration: BoxDecoration(color: color)"..
    3. The user wants to provide both, so they follow the error message by providing both and using the decoration formatted to how the error message printed it out.
    4. The user gets the same error message and the loop continues until they break it by finally digging in the the source code or searching for an answer elsewhere.

    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 from Container in 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 decoration given in the error message. It would be more clear if To provide both was dropped from the second part of the error message and replaced with entirely different wording. Maybe something like To set a color with a decoration, ....

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Jan 30, 2023
  5. darshankawar commented on Jan 31, 2023

    @darshankawar
    Member

    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.

  6. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    a: error messageError messages from the Flutter framework
    and removed
    in triagePresently being triaged by the triage team
    on Jan 31, 2023
  7. added
    P2Important issues not at the top of the work list
    on Feb 7, 2023
  8. 4 remaining items

  9. added 3 commits that reference this issue on Nov 19, 2025
    011917a
    d420480
    db3b47e
  10. baoyachi commented on Dec 4, 2025

    @baoyachi

    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.

  11. added a commit that references this issue on Dec 31, 2025
    a634f08
  12. added
    r: fixedIssue is closed as already fixed in a newer version
    on Jan 5, 2026
  13. github-actions commented on Jan 19, 2026

    @github-actions

    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 -v and a minimal reproduction of the issue.

  14. locked as resolved and limited conversation to collaborators on Jan 19, 2026
  15. added a commit that references this issue on Feb 12, 2026
    5f49837
  16. added a commit that references this issue on Feb 19, 2026
    28d2518
  17. added a commit that references this issue on Mar 26, 2026
    4f6be4f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: error messageError messages from the Flutter frameworkd: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.r: fixedIssue is closed as already fixed in a newer versionteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions