Skip to content

Disable implicit casts #13815

@DanTup

Description

@DanTup

I was just doing some testing and changed the colour in the Stocks app and hot reloaded:

   switch (_configuration.stockMode) {
      case StockMode.optimistic:
        return new ThemeData(
            brightness: Brightness.light, primarySwatch: Colors.black);// This was Colors.blue
      case StockMode.pessimistic:
        return new ThemeData(
            brightness: Brightness.dark, accentColor: Colors.redAccent);
    }
    assert(_configuration.stockMode != null);
    return null;

When I hit hot reload I got this:

══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
type 'Color' is not a subtype of type 'MaterialColor' of 'primarySwatch' where
Color is from dart:ui
MaterialColor is from package:flutter/src/material/colors.dart
int is from dart:core
Either the assertion indicates an error in the framework itself, or we should provide substantially
more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new
When the exception was thrown, this was the stack:
════════════════════════════════════════════════════════════════════════════════════════════════════
Reloaded 13 of 506 libraries in 871ms.

I don't know if this is actually a Flutter issue or not, but it seems like if it's not valid to use Colors.black that it shouldn't be in the code-completion and it should provide an error in the editor?

Metadata

Metadata

Assignees

Labels

c: contributor-productivityTeam-specific productivity, code health, technical debt.dependency: dartDart team may need to help usframeworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions