Skip to content

🐛 Resolves the referenced element before parsing colors #6768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 30, 2023

Conversation

AlexV525
Copy link
Member

@AlexV525 AlexV525 commented May 29, 2023

Fixes #5436.

Before After
image image

Implementation details

  • Colors and CupertinoColors are hard-coded to determine colored element. The condition has been removed, which means all elements will be predicated.
  • Referenced will be resolved before the element gets parsed by text directly.
  • All the additional checks will be called only if the element type is VAR_INIT (for declarations) or FUNCTION_BODY (for getters) to avoid too much performance regression.

Test case:

import 'package:flutter/material.dart' hide Colors;

const Color _c1 = Color(0xff000000);
final _c2 = _c1;
Color get _c3 => _c2;

void test() {
  const Color c1 = _c1;
  const Color c2 = Color(0xffffffff);
  const Color c3 = Color.fromARGB(255, 123, 231, 31);
  const Color c4 = Color(0xff923998);
  const Color c5 = c2;
  const Color c6 = TC.c1;
  const Color c7 = TC.c2;
  const Color c8 = TC.c3;
  const Color c9 = Colors.black;
}

class TC {
  static const Color c1 = Color(0xff449978);
  static const Color c2 = Color(0xffdb2f7f);
  static const Color c3 = Color.fromARGB(150, 66, 231, 31);
}

class Colors {
  static const Color white = Color(0xffaa9933);
  static const Color tests = Colors.white;
  static const Color black = Colors.tests;
  static const Color tcC1 = TC.c1;
  final Color tcC2 = TC.c2;
  Color get tcC3 => TC.c3;
}

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read the Flutter Style Guide recently, and have followed its advice.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@AlexV525 AlexV525 marked this pull request as draft May 29, 2023 04:43
@AlexV525 AlexV525 marked this pull request as ready for review May 29, 2023 05:56
@AlexV525 AlexV525 marked this pull request as draft May 29, 2023 06:09
@AlexV525 AlexV525 marked this pull request as ready for review May 29, 2023 06:19
Copy link
Member

@stevemessick stevemessick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@stevemessick stevemessick merged commit ad31c10 into flutter:master May 30, 2023
@stevemessick
Copy link
Member

I'm going to include this in the next release.

@AlexV525 AlexV525 deleted the fix/color-displays branch May 30, 2023 23:11
@AlexV525 AlexV525 restored the fix/color-displays branch June 1, 2023 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Display color icon for variables that can be dereferenced to known colors
2 participants