Skip to content

Color Preview in VSCode is fooled when using custom classes ending with "Colors". #2857

Closed

Description

@HosseinYousefi

Describe the bug
If the name of the class finishes with Colors, VSCode shows a preview as if the class name was Colors. (see the screenshot)

To Reproduce
You can use this code:

import 'dart:ui';

class MyColors {
  static const red = Color(0xff00ff00);
}

class NoColorHere {
  static const red = Color(0xff00ff00);
}

void somefunction() {
  final someOtherColor = NoColorHere.red;
  final someColor = MyColors.red;
}

Expected behavior
Preferably it should show the actual color in all cases, but a quick fix could be to not show the color preview when the class is not "Colors".

Screenshots
Screenshot 2020-10-08 at 10 49 29

Versions (please complete the following information):

  • VS Code version: 1.49.3
  • Dart extension version: 3.15.0
  • Dart/Flutter SDK version: 2.8.4/Flutter 1.17.5

Activity

  1. added this to the v3.16.0 milestone on Oct 8, 2020
  2. added
    in editorRelates to code editing or language features
    in flutterRelates to running Flutter apps
    on Oct 8, 2020
  3. DanTup commented on Oct 8, 2020

    @DanTup
    Member

    I'll fix this to only allow Colors, though I don't think we can make this completely reliably (some colours may not be known statically, and you could also create your own Colors class too). In the future this may move into the server (with LSP), so perhaps it will be easier to make it more reliable there (that's #2167).

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

    in editorRelates to code editing or language featuresin flutterRelates to running Flutter appsis bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions