Skip to content

Commit ae7eb38

Browse files
committed
split custom colors
1 parent 6034ef3 commit ae7eb38

File tree

7 files changed

+94
-64
lines changed

7 files changed

+94
-64
lines changed

lib/config/custom_colors.dart

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import 'package:flutter/material.dart' show Color, ThemeExtension, immutable;
22

33
@immutable
4-
class CustomColors extends ThemeExtension<CustomColors> {
5-
const CustomColors({
4+
class GameColors extends ThemeExtension<GameColors> {
5+
const GameColors({
66
required this.initial,
77
required this.green,
88
required this.yellow,
99
required this.notInWord,
1010
required this.borderInactive,
1111
required this.borderActive,
12-
required this.historyGreen,
13-
required this.historyRed,
14-
required this.historyYellow,
1512
});
1613

1714
/// Initial color for keyboard
@@ -32,50 +29,79 @@ class CustomColors extends ThemeExtension<CustomColors> {
3229
/// Border colors for tile
3330
final Color? borderActive;
3431

35-
final Color? historyGreen;
36-
final Color? historyRed;
37-
final Color? historyYellow;
38-
3932
@override
40-
CustomColors copyWith({
33+
GameColors copyWith({
4134
Color? initial,
4235
Color? green,
4336
Color? yellow,
4437
Color? notInWord,
4538
Color? borderInactive,
4639
Color? borderActive,
47-
Color? historyGreen,
48-
Color? historyRed,
49-
Color? historyYellow,
5040
}) {
51-
return CustomColors(
41+
return GameColors(
5242
initial: initial ?? this.initial,
5343
green: green ?? this.green,
5444
yellow: yellow ?? this.yellow,
5545
notInWord: notInWord ?? this.notInWord,
5646
borderInactive: borderInactive ?? this.borderInactive,
5747
borderActive: borderActive ?? this.borderActive,
58-
historyGreen: historyGreen ?? this.historyGreen,
59-
historyRed: historyRed ?? this.historyRed,
60-
historyYellow: historyYellow ?? this.historyYellow,
6148
);
6249
}
6350

6451
@override
65-
CustomColors lerp(CustomColors? other, double t) {
66-
if (other is! CustomColors) {
52+
GameColors lerp(GameColors? other, double t) {
53+
if (other is! GameColors) {
6754
return this;
6855
}
69-
return CustomColors(
56+
return GameColors(
7057
initial: Color.lerp(initial, other.initial, t),
7158
green: Color.lerp(green, other.green, t),
7259
yellow: Color.lerp(yellow, other.yellow, t),
7360
notInWord: Color.lerp(notInWord, other.notInWord, t),
7461
borderInactive: Color.lerp(borderInactive, other.borderInactive, t),
7562
borderActive: Color.lerp(borderActive, other.borderActive, t),
76-
historyGreen: Color.lerp(historyGreen, other.historyGreen, t),
77-
historyRed: Color.lerp(historyRed, other.historyGreen, t),
78-
historyYellow: Color.lerp(historyYellow, other.historyGreen, t),
63+
);
64+
}
65+
}
66+
67+
class HistoryColors extends ThemeExtension<HistoryColors> {
68+
const HistoryColors({
69+
required this.green,
70+
required this.yellow,
71+
required this.red,
72+
});
73+
74+
/// When user guessed word correctly
75+
final Color? green;
76+
77+
/// When game is incomplete
78+
final Color? yellow;
79+
80+
/// When user did not guess word correctly
81+
final Color? red;
82+
83+
@override
84+
HistoryColors copyWith({
85+
Color? green,
86+
Color? yellow,
87+
Color? red,
88+
}) {
89+
return HistoryColors(
90+
green: green ?? this.green,
91+
yellow: yellow ?? this.yellow,
92+
red: red ?? this.red,
93+
);
94+
}
95+
96+
@override
97+
HistoryColors lerp(HistoryColors? other, double t) {
98+
if (other is! HistoryColors) {
99+
return this;
100+
}
101+
return HistoryColors(
102+
green: Color.lerp(green, other.green, t),
103+
yellow: Color.lerp(yellow, other.yellow, t),
104+
red: Color.lerp(red, other.red, t),
79105
);
80106
}
81107
}

lib/config/themes.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import 'package:flutter/material.dart';
2-
import 'package:red_owl/config/shared.dart' show CustomColors;
2+
import 'package:red_owl/config/shared.dart' show GameColors, HistoryColors;
33

44
final lightTheme = ThemeData(
55
colorScheme: ColorScheme.fromSeed(
@@ -8,17 +8,19 @@ final lightTheme = ThemeData(
88
),
99
brightness: Brightness.light,
1010
extensions: const <ThemeExtension<dynamic>>[
11-
CustomColors(
11+
GameColors(
1212
initial: Color.fromRGBO(211, 214, 218, 1),
1313
yellow: Color.fromRGBO(201, 180, 88, 1),
1414
green: Color.fromRGBO(106, 170, 100, 1),
1515
notInWord: Color.fromRGBO(120, 124, 126, 1),
1616
borderInactive: Color.fromRGBO(211, 214, 218, 1),
1717
borderActive: Color.fromRGBO(135, 138, 140, 1),
18-
historyGreen: Color.fromRGBO(72, 199, 142, 1),
19-
historyRed: Color.fromRGBO(255, 82, 113, 1),
20-
historyYellow: Color.fromRGBO(255, 193, 0, 1),
2118
),
19+
HistoryColors(
20+
green: Color.fromRGBO(72, 199, 142, 1),
21+
red: Color.fromRGBO(255, 82, 113, 1),
22+
yellow: Color.fromRGBO(255, 193, 0, 1),
23+
)
2224
],
2325
);
2426

@@ -29,16 +31,18 @@ final darkTheme = ThemeData(
2931
),
3032
brightness: Brightness.dark,
3133
extensions: const <ThemeExtension<dynamic>>[
32-
CustomColors(
34+
GameColors(
3335
initial: Color.fromRGBO(129, 131, 132, 1),
3436
yellow: Color.fromRGBO(181, 159, 59, 1),
3537
green: Color.fromRGBO(83, 141, 78, 1),
3638
notInWord: Color.fromRGBO(58, 58, 60, 1),
3739
borderInactive: Color.fromRGBO(58, 58, 60, 1),
3840
borderActive: Color.fromRGBO(86, 87, 88, 1),
39-
historyGreen: Color.fromRGBO(0, 76, 48, 1),
40-
historyRed: Color.fromRGBO(101, 10, 30, 1),
41-
historyYellow: Color.fromRGBO(180, 145, 0, 1),
4241
),
42+
HistoryColors(
43+
green: Color.fromRGBO(0, 76, 48, 1),
44+
red: Color.fromRGBO(101, 10, 30, 1),
45+
yellow: Color.fromRGBO(180, 145, 0, 1),
46+
)
4347
],
4448
);

lib/routes/game/game_page.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
33
import 'package:flutter/services.dart'
44
show KeyDownEvent, KeyRepeatEvent, KeyUpEvent, ServicesBinding;
55
import 'package:red_owl/config/shared.dart'
6-
show CustomColors, LetterStatus, animationTiming, keyboardStatus;
6+
show GameColors, LetterStatus, animationTiming, keyboardStatus;
77
import 'package:red_owl/riverpod/shared.dart' show gridProvider;
88
import 'package:red_owl/routes/game/widgets/shared.dart';
99
import 'package:red_owl/util/shared.dart' show dateToString;
@@ -68,29 +68,29 @@ class _WordlePageState extends ConsumerState<WordlePage> {
6868
children: [
6969
HelpTile(
7070
background: Theme.of(context)
71-
.extension<CustomColors>()!
71+
.extension<GameColors>()!
7272
.notInWord!,
7373
letter: 'S'),
7474
const SizedBox(width: 5),
7575
HelpTile(
7676
background: Theme.of(context)
77-
.extension<CustomColors>()!
77+
.extension<GameColors>()!
7878
.notInWord!,
7979
letter: 'T'),
8080
const SizedBox(width: 5),
8181
HelpTile(
8282
background:
83-
Theme.of(context).extension<CustomColors>()!.green!,
83+
Theme.of(context).extension<GameColors>()!.green!,
8484
letter: 'A'),
8585
const SizedBox(width: 5),
8686
HelpTile(
8787
background:
88-
Theme.of(context).extension<CustomColors>()!.yellow!,
88+
Theme.of(context).extension<GameColors>()!.yellow!,
8989
letter: 'R'),
9090
const SizedBox(width: 5),
9191
HelpTile(
9292
background: Theme.of(context)
93-
.extension<CustomColors>()!
93+
.extension<GameColors>()!
9494
.notInWord!,
9595
letter: 'E'),
9696
],

lib/routes/game/widgets/letter.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_riverpod/flutter_riverpod.dart';
3-
import 'package:red_owl/config/shared.dart' show CustomColors, LetterStatus;
3+
import 'package:red_owl/config/shared.dart' show GameColors, LetterStatus;
44
import 'package:red_owl/riverpod/shared.dart';
55

66
class Letter extends ConsumerWidget {
@@ -14,20 +14,20 @@ class Letter extends ConsumerWidget {
1414
var grid = ref.watch(gridProvider);
1515
switch (grid.keyboardStatus[letter]) {
1616
case LetterStatus.initial:
17-
backgroundColor = Theme.of(context).extension<CustomColors>()?.initial;
17+
backgroundColor = Theme.of(context).extension<GameColors>()?.initial;
1818
break;
1919
case LetterStatus.green:
20-
backgroundColor = Theme.of(context).extension<CustomColors>()?.green;
20+
backgroundColor = Theme.of(context).extension<GameColors>()?.green;
2121
textColor = Colors.white;
2222
break;
2323
case LetterStatus.yellow:
24-
backgroundColor = Theme.of(context).extension<CustomColors>()?.yellow;
24+
backgroundColor = Theme.of(context).extension<GameColors>()?.yellow;
2525
textColor = Colors.white;
2626
break;
2727
case LetterStatus.notInWord:
2828
case null:
2929
backgroundColor =
30-
Theme.of(context).extension<CustomColors>()?.notInWord;
30+
Theme.of(context).extension<GameColors>()?.notInWord;
3131
textColor = Colors.white;
3232
break;
3333
}

lib/routes/game/widgets/tile.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'dart:math' as math;
44
import 'package:flutter/material.dart';
55
import 'package:flutter_riverpod/flutter_riverpod.dart';
66
import 'package:red_owl/config/shared.dart'
7-
show CustomColors, LetterStatus, SharedPreferencesKeys, animationTiming;
7+
show GameColors, LetterStatus, SharedPreferencesKeys, animationTiming;
88
import 'package:red_owl/riverpod/shared.dart' show gridProvider;
99
import 'package:red_owl/models/shared.dart' show Grid;
1010
import 'package:red_owl/util/shared.dart'
@@ -48,7 +48,7 @@ class _TileState extends ConsumerState<Tile>
4848
Widget build(BuildContext context) {
4949
Grid grid = ref.watch(gridProvider);
5050
Color borderColor =
51-
Theme.of(context).extension<CustomColors>()!.borderInactive!;
51+
Theme.of(context).extension<GameColors>()!.borderInactive!;
5252
bool hasFlipAnimationPlayed = widget.hasFlipAnimationPlayed;
5353

5454
if (widget.index < grid.tiles.length) {
@@ -88,22 +88,22 @@ class _TileState extends ConsumerState<Tile>
8888
case LetterStatus.initial:
8989
backgroundColor = null;
9090
borderColor =
91-
Theme.of(context).extension<CustomColors>()!.borderActive!;
91+
Theme.of(context).extension<GameColors>()!.borderActive!;
9292
break;
9393
case LetterStatus.green:
94-
backgroundColor = Theme.of(context).extension<CustomColors>()!.green!;
94+
backgroundColor = Theme.of(context).extension<GameColors>()!.green!;
9595
borderColor = Colors.transparent;
9696
textColor = Colors.white;
9797
break;
9898
case LetterStatus.yellow:
9999
backgroundColor =
100-
Theme.of(context).extension<CustomColors>()!.yellow!;
100+
Theme.of(context).extension<GameColors>()!.yellow!;
101101
borderColor = Colors.transparent;
102102
textColor = Colors.white;
103103
break;
104104
case LetterStatus.notInWord:
105105
backgroundColor =
106-
Theme.of(context).extension<CustomColors>()!.notInWord!;
106+
Theme.of(context).extension<GameColors>()!.notInWord!;
107107
borderColor = Colors.transparent;
108108
textColor = Colors.white;
109109
break;
@@ -112,7 +112,7 @@ class _TileState extends ConsumerState<Tile>
112112
// Set default values to variables so that tile rebuilds.
113113
// By default it does not when Navigator pops settingsPage back to GamePage
114114
backgroundColor = null;
115-
borderColor = Theme.of(context).extension<CustomColors>()!.borderActive!;
115+
borderColor = Theme.of(context).extension<GameColors>()!.borderActive!;
116116
hasFlipAnimationPlayed = false;
117117
}
118118

lib/routes/stats/stats_page.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:red_owl/config/shared.dart'
3-
show CustomColors, SharedPreferencesKeys;
3+
show HistoryColors, SharedPreferencesKeys;
44
import 'package:red_owl/routes/stats/widgets/shared.dart';
55
import 'package:red_owl/util/shared.dart'
66
show SharedPreferenceService, getWinRate;
@@ -48,8 +48,8 @@ Check out my Wordle! stats!
4848
text: 'Green',
4949
style: TextStyle(
5050
backgroundColor: Theme.of(context)
51-
.extension<CustomColors>()!
52-
.historyGreen),
51+
.extension<HistoryColors>()!
52+
.green),
5353
),
5454
TextSpan(
5555
text: ' means you guessed correctly.',
@@ -67,8 +67,8 @@ Check out my Wordle! stats!
6767
text: 'Yellow',
6868
style: TextStyle(
6969
backgroundColor: Theme.of(context)
70-
.extension<CustomColors>()!
71-
.historyYellow),
70+
.extension<HistoryColors>()!
71+
.yellow),
7272
),
7373
TextSpan(
7474
text: ' means the game was incomplete.',
@@ -86,8 +86,8 @@ Check out my Wordle! stats!
8686
text: 'Red',
8787
style: TextStyle(
8888
backgroundColor: Theme.of(context)
89-
.extension<CustomColors>()!
90-
.historyRed),
89+
.extension<HistoryColors>()!
90+
.red),
9191
),
9292
TextSpan(
9393
text: " means you didn't guess the word.",
@@ -105,21 +105,21 @@ Check out my Wordle! stats!
105105
dateString: '2024-05-23',
106106
word: 'BURNT',
107107
backgroundColor:
108-
Theme.of(context).extension<CustomColors>()!.historyGreen!,
108+
Theme.of(context).extension<HistoryColors>()!.green!,
109109
),
110110
const SizedBox(height: 8),
111111
HistoryTile(
112112
dateString: '2024-05-22',
113113
word: 'WHISK',
114114
backgroundColor:
115-
Theme.of(context).extension<CustomColors>()!.historyYellow!,
115+
Theme.of(context).extension<HistoryColors>()!.yellow!,
116116
),
117117
const SizedBox(height: 8),
118118
HistoryTile(
119119
dateString: '2024-05-21',
120120
word: 'IDEAS',
121121
backgroundColor:
122-
Theme.of(context).extension<CustomColors>()!.historyRed!,
122+
Theme.of(context).extension<HistoryColors>()!.red!,
123123
),
124124
],
125125
),

lib/routes/stats/widgets/history.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'package:drift/drift.dart';
22
import 'package:flutter/material.dart';
3-
import 'package:red_owl/config/shared.dart' show CustomColors;
3+
import 'package:red_owl/config/shared.dart' show HistoryColors;
44
import 'package:red_owl/database/database.dart';
55
import 'package:red_owl/routes/stats/widgets/history_tile.dart';
66
import 'package:red_owl/util/shared.dart' show dateToString;
@@ -67,15 +67,15 @@ class _HistoryState extends State<History> {
6767
switch (gameState) {
6868
case GameState.won:
6969
backgroundColor =
70-
Theme.of(context).extension<CustomColors>()!.historyGreen!;
70+
Theme.of(context).extension<HistoryColors>()!.green!;
7171
break;
7272
case GameState.lost:
7373
backgroundColor =
74-
Theme.of(context).extension<CustomColors>()!.historyRed!;
74+
Theme.of(context).extension<HistoryColors>()!.red!;
7575
break;
7676
case GameState.incomplete:
7777
backgroundColor =
78-
Theme.of(context).extension<CustomColors>()!.historyYellow!;
78+
Theme.of(context).extension<HistoryColors>()!.yellow!;
7979
break;
8080
}
8181

0 commit comments

Comments
 (0)