Skip to content

Commit d1bca1a

Browse files
helin24gemini-code-assist[bot]pq
authored
Make color recognition more specific (#8824)
Fixes #7184 To manually test, check that the sample code with a non-color does not generate a color box: <img width="236" height="268" alt="Screenshot 2026-02-24 at 9 29 04 AM" src="https://github.com/user-attachments/assets/5f678813-b07c-4846-be35-ff5b72dc86ce" /> (`TestEnum.blue` has no color box, but `Colors.blue` does) --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Phil Quitslund <pq@users.noreply.github.com>
1 parent 9fef30b commit d1bca1a

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

src/io/flutter/editor/FlutterColorProvider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public Color getColorFrom(@NotNull PsiElement element) {
4545

4646
if (parent.getNode().getElementType() == DartTokenTypes.ARRAY_ACCESS_EXPRESSION) {
4747
// Colors.blue[200]
48+
if (!refExpr.getFirstChild().getText().equals("Colors") && !refExpr.getFirstChild().getText().equals("CupertinoColors")) {
49+
return null;
50+
}
4851
if (name.equals(refExpr.getFirstChild().getText()) && refExpr.getChildren().length > 1) {
4952
// Avoid duplicate resolves.
5053
return null;
@@ -116,7 +119,7 @@ else if (parent.getNode().getElementType() == DartTokenTypes.SIMPLE_TYPE) {
116119
// name.equals(refExpr.getFirstChild().getText()) -> Colors.blue
117120
final PsiElement idNode = refExpr.getFirstChild();
118121
if (idNode == null) return null;
119-
if (name.equals(idNode.getText())) {
122+
if ((name.equals("Colors") || name.equals("CupertinoColors")) && name.equals(idNode.getText())) {
120123
final PsiElement selectorNode = refExpr.getLastChild();
121124
if (selectorNode == null) return null;
122125
final String code = AstBufferUtil.getTextSkippingWhitespaceComments(selectorNode.getNode());

0 commit comments

Comments
 (0)