Skip to content

flutter: prefer const for Color class - #197

Merged
bernaferrari merged 2 commits into
bernaferrari:refactorfrom
ZeroNetX:flutter-const-class
Mar 17, 2025
Merged

bernaferrari merged 2 commits into
bernaferrari:refactorfrom
ZeroNetX:flutter-const-class

Conversation

@canewsin

Copy link
Copy Markdown
Contributor

No description provided.

@canewsin
canewsin force-pushed the flutter-const-class branch from e2ae2aa to 9c2ffcf Compare March 11, 2025 09:14
@bernaferrari

bernaferrari commented Mar 12, 2025 •

Copy link
Copy Markdown
Owner

I could merge this, but if you are thinking in adding to other things, it will be very hard. You will never be satisfied with const in Flutter. What do you think? Because lint will now complain BorderSide is not const.

@canewsin

Copy link
Copy Markdown
Contributor Author

I thought about addingconst to other classes, yup it's hard to estimate as well as impl because I need to add more logic that will check non const children, thus thinking where it would be more relevant and less error-prone.

@bernaferrari

bernaferrari commented Mar 12, 2025 •

Copy link
Copy Markdown
Owner

Const will not bring any benefit to your code. I can merge this, but really don't worry. If your app has 2000 const or none, it could be 1% faster. I once added hundreds of const and had no difference in benchmarks.

@canewsin

Copy link
Copy Markdown
Contributor Author

Most likely the compiler will optimise, but due to some lint rules we follow at work this will stop those screams at least.

@bernaferrari

bernaferrari commented Mar 12, 2025 •

Copy link
Copy Markdown
Owner

Yeah, but the issue is that everything else except const will still scream :( so this is just moving the lint error to somewhere else, but will definitely still happen. I think there is a dart fix that auto-fixes that now, so you will still need to run it, or disable the lint (I recommend disabling the lint)

@canewsin
canewsin force-pushed the flutter-const-class branch from 9c2ffcf to 2b4ed14 Compare March 13, 2025 09:45
@bernaferrari

Copy link
Copy Markdown
Owner

In Flutter, the correct syntax is Colors.white without const. The Colors class in Flutter provides predefined color constants, and white is one of those constants.

@canewsin
canewsin force-pushed the flutter-const-class branch from 1030e1c to 8e763f1 Compare March 15, 2025 05:02
Comment thread packages/backend/src/flutter/builderImpl/flutterColor.ts Outdated
Comment thread packages/backend/src/flutter/builderImpl/flutterColor.ts Outdated
@bernaferrari
bernaferrari merged commit 0132452 into bernaferrari:refactor Mar 17, 2025
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.

2 participants