Add support for html named colors #2675
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Adds support for handling web named colors.
Quill deltas often contain named colors from the standard HTML color palette. This is especially true if the delta was created using Quill on web. These named colors could not be handled by flutter_quill, and so an exception was thrown when rendering the delta.
This change adds constants for the 140 named web colors, based on the list here: https://github.com/vincevargadev/kolors_flutter/blob/main/lib/kolors.dart
I've also added values for the obsolete CSS2 system colors, such as
windowtext. We have seen these show up when our users paste text from Microsoft Word into Quill on web. W3C recommends using a default value for these colors.Finally, modifies
stringToColorto check if the input is one of the named colors, and returns the value if found, and adds tests.One thing I did notice is that the existing code in
stringToColorreturns a MaterialColor for common colors like red, yellow, etc. However these are not always the same value as expected in web - eg MaterialColor.yellow is not0xffffff00. I don't think that really matters here though.Related Issues
Type of Change