Skip to content
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

Color const constructor #694

Open
grahamsmith opened this issue Dec 9, 2024 · 4 comments
Open

Color const constructor #694

grahamsmith opened this issue Dec 9, 2024 · 4 comments

Comments

@grahamsmith
Copy link

It would improve the devX if Color allowed a const constructor. The would allow defaults to be used in methods and other constructors, which at the moment won't work as defaults need to be const.

Happy to help but would like to know if this would be acceptable ahead of time.

@grahamsmith
Copy link
Author

grahamsmith commented Dec 9, 2024

Example

At the moment we have to pass the colours in.

ChartRequest({
    required List<ChartDataPoint> dataPoints,
    required this.width,
    required this.height,
    required this.minLineColor,
    required this.maxLineColor,
    this.font,
  })

This is not allowed as there is no const constructor for the colour.

ChartRequest({
    required List<ChartDataPoint> dataPoints,
    required this.width,
    required this.height,
    this.minLineColor =  ColorRgba8(0, 0, 0, 255),
    this.maxLineColor = ColorRgba8(0, 0, 0, 255),
    this.font,
  })

@brendan-duncan
Copy link
Owner

brendan-duncan commented Dec 13, 2024

Hmm, the problem is that ColorUint8 has a Uint8List data member, so it's not const compatible as it is.
I'll have to make a new color class that stores the channels in an int, so that it can be made const.
If minLineColor is a Color and not specifically a ColorUint8, then you'd be able to use this new color class.

@brendan-duncan
Copy link
Owner

I added ConstColorRgba8 and ConstColorRgb8, which are immutable const compatible Color classes.

@brendan-duncan
Copy link
Owner

Added to published version 4.5.0

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

No branches or pull requests

2 participants