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

Skip to content

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

@JoshMart

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,
      ),
    );
  }
}

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.team-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