Skip to content

Commit 3ad08d0

Browse files
committed
Add support for html 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. This change adds dart contants for the 140 named html colors. It modifies `stringToColor` to check if the input is one of the named colors, and returns the value if found. Web colors are case insensitive.
1 parent e14689b commit 3ad08d0

File tree

4 files changed

+480
-5
lines changed

4 files changed

+480
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
### Fixed
2020

2121
- Fixed `View.of(context)` calls throwing when used with the `screenshot` package [#2662](https://github.com/singerdmx/flutter-quill/pull/2662).
22+
- Fixed support for html named colors [#2675](https://github.com/singerdmx/flutter-quill/pull/2675)
2223

2324
### Added
2425

@@ -81,7 +82,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8182

8283
### Fixed
8384

84-
- Explicitly schedule frame on secondary click to ensure context menu is shown on Windows [#2507](https://github.com/singerdmx/flutter-quill/pull/2507).
85+
- Explicitly schedule frame on secondary click to ensure context menu is shown on Windows [#2507](https://github.com/singerdmx/flutter-quill/pull/2507).
8586

8687
## [11.1.0] - 2025-03-11
8788

@@ -126,8 +127,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
126127
- Rewrite the image save functionality for [`flutter_quill_extensions`](https://pub.dev/packages/flutter_quill_extensions) [#2403](https://github.com/singerdmx/flutter-quill/pull/2403).
127128
- Migrate [quill_native_bridge](https://pub.dev/packages/quill_native_bridge) to `11.0.0` [#2403](https://github.com/singerdmx/flutter-quill/pull/2403).
128129
- Avoid using deprecated APIs in Flutter 3.27.0 [#2416](https://github.com/singerdmx/flutter-quill/pull/2416):
129-
- Migrate from `withOpacity` to `withValues` according to [Color wide gamut - Opacity migration](https://docs.flutter.dev/release/breaking-changes/wide-gamut-framework#opacity).
130-
- Avoid using the deprecated `Color.value` getter.
130+
- Migrate from `withOpacity` to `withValues` according to [Color wide gamut - Opacity migration](https://docs.flutter.dev/release/breaking-changes/wide-gamut-framework#opacity).
131+
- Avoid using the deprecated `Color.value` getter.
131132
- Ignore `unreachable_switch_default` warning (introduced in Dart 3.6) [#2416](https://github.com/singerdmx/flutter-quill/pull/2416).
132133
- Update `intl` dependency to support versions `0.19.0` and `0.20.0` [#2416](https://github.com/singerdmx/flutter-quill/pull/2416).
133134
- Restore [base button options](https://github.com/singerdmx/flutter-quill/pull/2338/commits/1f51935f1eaa229f01c4d14398708ab2d3bd05b0), now works without the inherited widgets, and support buttons of `flutter_quill_extensions`.

lib/src/common/utils/color.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'web_colors.dart';
23

34
import '../../editor/widgets/default_styles.dart';
45

@@ -115,7 +116,12 @@ Color stringToColor(String? s,
115116
return Colors.brown;
116117
}
117118

118-
if (s!.startsWith('rgba')) {
119+
// is it an html named color?
120+
if (WebColors.namedColors.containsKey(s!.toLowerCase())) {
121+
return WebColors.namedColors[s.toLowerCase()]!;
122+
}
123+
124+
if (s.startsWith('rgba')) {
119125
s = s.substring(5); // trim left 'rgba('
120126
s = s.substring(0, s.length - 1); // trim right ')'
121127
final arr = s.split(',').map((e) => e.trim()).toList();
@@ -129,7 +135,7 @@ Color stringToColor(String? s,
129135
}
130136

131137
if (!s.startsWith('#')) {
132-
throw UnsupportedError('Color code not supported');
138+
throw UnsupportedError('Color code not supported: $s');
133139
}
134140

135141
var hex = s.replaceFirst('#', '');

0 commit comments

Comments
 (0)