File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,3 +86,6 @@ members:
8686- ` paint ` : creates a new ` Paint ` with the color specified. ` Paint ` is a non-` const ` class, so this
8787 method actually creates a brand new instance every time it's called. It's safe to cascade
8888 mutations to this.
89+
90+ It also exposes helper methods to derive a new ` PaletteEntry ` by transforming the underlying color,
91+ such as ` withRed ` or ` lighten ` .
Original file line number Diff line number Diff line change 11import 'dart:ui' ;
22
3+ import 'package:flame/extensions.dart' ;
4+
35class PaletteEntry {
46 final Color color;
57
@@ -22,6 +24,14 @@ class PaletteEntry {
2224 PaletteEntry withBlue (int blue) {
2325 return PaletteEntry (color.withBlue (blue));
2426 }
27+
28+ PaletteEntry darken (double amount) {
29+ return PaletteEntry (color.darken (amount));
30+ }
31+
32+ PaletteEntry brighten (double amount) {
33+ return PaletteEntry (color.brighten (amount));
34+ }
2535}
2636
2737class BasicPalette {
Original file line number Diff line number Diff line change 1+ import 'package:flame/palette.dart' ;
2+ import 'package:test/test.dart' ;
3+
4+ void main () {
5+ group ('Palette' , () {
6+ test ('updates color' , () {
7+ const entry = BasicPalette .red;
8+ expect (entry.color, const Color (0xFFFF0000 ));
9+ expect (entry.withAlpha (100 ).color, const Color (0x64FF0000 ));
10+ expect (entry.withRed (100 ).color, const Color (0xFF640000 ));
11+ expect (entry.withGreen (100 ).color, const Color (0xFFFF6400 ));
12+ expect (entry.withBlue (100 ).color, const Color (0xFFFF0064 ));
13+ });
14+
15+ test ('darkens and brightens color' , () {
16+ const entry = BasicPalette .red;
17+ expect (entry.color, const Color (0xFFFF0000 ));
18+ expect (entry.darken (0.5 ).color, const Color (0xFF800000 ));
19+ expect (entry.brighten (0.5 ).color, const Color (0xFFFF8080 ));
20+ });
21+ });
22+ }
You can’t perform that action at this time.
0 commit comments