Skip to content

Conversation

@AlexDochioiu
Copy link

@AlexDochioiu AlexDochioiu commented Nov 30, 2025

  • Consolidate rgb() and rgba() parsing into single implementation
  • Add support for space-separated color values
  • Add support for percentage-based RGB values
  • Add support for slash (/) separator before alpha channel
  • Handle both comma and space delimiters
  • Add comprehensive test coverage for various color formats

This PR solves flutter/flutter#179261

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

@github-actions github-actions bot added p: vector_graphics triage-engine Should be looked at in engine triage labels Nov 30, 2025
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the color parsing logic for rgb() and rgba() to support modern CSS syntax, including space-separated values, percentage-based values, and the slash separator for the alpha channel. The implementation is consolidated, and the old rgb parsing logic is removed. Comprehensive tests have been added to cover the new parsing capabilities.

The changes are well-structured and the added tests are thorough. I have one suggestion to improve the strictness of the parsing to better align with CSS standards.

@stuartmorgan-g
Copy link
Collaborator

Thanks for the contribution! Once you've completed the checklist, please mark the PR as ready for review.

Please make sure to follow the linked style guide.

@stuartmorgan-g stuartmorgan-g marked this pull request as draft November 30, 2025 15:53
@AlexDochioiu AlexDochioiu marked this pull request as ready for review December 1, 2025 07:53
@AlexDochioiu AlexDochioiu marked this pull request as draft December 1, 2025 07:53
@AlexDochioiu AlexDochioiu marked this pull request as ready for review December 1, 2025 08:10
@AlexDochioiu
Copy link
Author

@stuartmorgan-g Completed the checklist. This is my first PR to any flutter/dart repo. If anything is not exactly correct, please let me know and I'll address.

@AlexDochioiu
Copy link
Author

Ping @stuartmorgan-g . Any chance we can get this fix reviewed/merged?

@stuartmorgan-g
Copy link
Collaborator

I can do an initial review, but this will need a review from the engine team. Review capacity tends to be low in December, which is probably why this hasn't been picked up yet.

…rn CSS syntax

- Consolidate rgb() and rgba() parsing into single implementation
- Add support for space-separated color values
- Add support for percentage-based RGB values
- Add support for slash (/) separator before alpha channel
- Handle both comma and space delimiters
- Add comprehensive test coverage for various color formats
- Add parseRgbFunction in colors.dart with character-by-character
  state machine parser for stricter CSS compliance
- Support modern (space-separated with slash) and legacy (comma-separated)
  syntax variations
- Clamp out-of-bounds values instead of throwing
- Add comprehensive tests for valid syntax, out-of-bounds values,
  and invalid syntax detection
Replace character-by-character state machine with cleaner split-based
approach using standard string operations (split, trim, where).
@AlexDochioiu
Copy link
Author

Thank you for the review @stuartmorgan-g . I completely re-wrote to a fresh implementation that checks strictly for the format and handles correctly all the cases (including weird ones such as R G,B,A -- where R G are space delimited) that seem to work on web.

I also added tests for a lot of invalid cases.

Bonus: I also added handling for

  1. R,G,B values being double instead of int (which seems to be supported on web).
  2. Values being out of bounds, which just clamp to the bounds on web rather than failing to parse

@AlexDochioiu
Copy link
Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the CSS color parsing for rgb() and rgba() to support modern syntax, including space-separated values, percentage values, and the slash separator for the alpha channel. The implementation is consolidated into a new parseRgbFunction, and the old parsing logic is removed. Comprehensive tests are added to cover various valid and invalid color formats.

I've found one minor bug in the new parsing logic for mixed comma and space-separated values, and I've left a comment with a suggested fix. Otherwise, the changes look good and the test coverage is excellent.

…B parsing

Handle multiple spaces in first value of comma-separated syntax by
filtering empty strings after split.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: vector_graphics triage-engine Should be looked at in engine triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants