Skip to content

Commit a0c0d9e

Browse files
authored
Merge pull request #14 from DutchCodingCompany/feature/kleurplaat
Kleurplaat
2 parents 0c90a46 + 130d2ff commit a0c0d9e

13 files changed

+746
-0
lines changed

lib/common/extensions/build_context.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:dcc_toolkit/style/kleurplaat/katjas_kleurplaat.dart';
2+
import 'package:dcc_toolkit/style/text_style/text_themes_decorator.dart';
13
import 'package:flutter/material.dart';
24

35
/// Extension for [BuildContext] to get theme related data.
@@ -10,4 +12,13 @@ extension ThemingExtensions on BuildContext {
1012

1113
/// Get Theme [TextTheme] from [BuildContext].
1214
TextTheme get textThemes => theme.textTheme;
15+
16+
/// Get [TextThemesDecorator] from [BuildContext].
17+
TextThemesDecorator get textThemesDecorator => TextThemesDecorator(
18+
textThemes,
19+
katjasKleurPlaat,
20+
);
21+
22+
/// Get [KatjasKleurplaat] from [BuildContext].
23+
KatjasKleurplaat get katjasKleurPlaat => theme.extension<KatjasKleurplaat>()!;
1324
}

lib/dcc_toolkit.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export 'common/extensions/color.dart';
55
export 'common/extensions/iterable.dart';
66
export 'common/result/result.dart';
77
export 'logger/bolt_logger.dart';
8+
export 'style/style.dart';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import 'package:dcc_toolkit/style/kleurplaat/katjas_kleurplaat.dart';
2+
3+
/// {@template color_group}
4+
/// Group of colors defined for [KatjasKleurplaat].
5+
/// {@endtemplate}
6+
abstract interface class ColorGroupInterface<T> {
7+
/// {@template color}
8+
/// The color on the background.
9+
/// {@endtemplate}
10+
T get color;
11+
12+
/// {@template on_color}
13+
/// The color on the foreground. Usually on top of the [color].
14+
/// {@endtemplate}
15+
T get onColor;
16+
17+
/// {@template on_color_subtle}
18+
/// The color on the foreground, but more subtle. Usually on top of the [color].
19+
/// {@endtemplate}
20+
T? get onColorSubtle;
21+
22+
/// Linearly interpolate with another object.
23+
ColorGroupInterface<T> lerp(
24+
covariant ColorGroupInterface<T>? other,
25+
double t,
26+
);
27+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import 'package:dcc_toolkit/style/interface/color_group_interface.dart';
2+
import 'package:dcc_toolkit/style/interface/surface_group_interface.dart';
3+
import 'package:dcc_toolkit/style/kleurplaat/katjas_kleurplaat.dart';
4+
5+
/// {@template kleurplaat}
6+
/// Group of colors defined for [KatjasKleurplaat].
7+
/// {@endtemplate}
8+
abstract interface class KleurplaatInterface<T> {
9+
/// {@template primary}
10+
/// The primary color group.
11+
/// {@endtemplate}
12+
ColorGroupInterface<T> get primary;
13+
14+
/// {@template primaryFill}
15+
/// The primary fill color group.
16+
/// {@endtemplate}
17+
ColorGroupInterface<T> get primaryFill;
18+
19+
/// {@template content}
20+
/// The content color group.
21+
/// {@endtemplate}
22+
ColorGroupInterface<T> get content;
23+
24+
/// {@template contentFill}
25+
/// The content fill color group.
26+
/// {@endtemplate}
27+
ColorGroupInterface<T> get contentFill;
28+
29+
/// {@template error}
30+
/// The error color group.
31+
/// {@endtemplate}
32+
ColorGroupInterface<T> get error;
33+
34+
/// {@template errorFill}
35+
/// The error fill color group.
36+
/// {@endtemplate}
37+
ColorGroupInterface<T> get errorFill;
38+
39+
/// {@template success}
40+
/// The success color group.
41+
/// {@endtemplate}
42+
ColorGroupInterface<T> get success;
43+
44+
/// {@template successFill}
45+
/// The success fill color group.
46+
/// {@endtemplate}
47+
ColorGroupInterface<T> get successFill;
48+
49+
/// {@template surface}
50+
/// The surface group.
51+
/// {@endtemplate}
52+
SurfaceGroupInterface<T> get surface;
53+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import 'package:dcc_toolkit/style/kleurplaat/katjas_kleurplaat.dart';
2+
3+
/// {@template surface_group}
4+
/// Group of colors defined for surfaces in [KatjasKleurplaat].
5+
/// {@endtemplate}
6+
abstract interface class SurfaceGroupInterface<T> {
7+
/// {@template color}
8+
/// The color of the surface.
9+
/// {@endtemplate}
10+
T get color;
11+
12+
/// {@template onColorContrastPlus}
13+
/// The color on the surface with a higher contrast.
14+
/// {@endtemplate}
15+
T get onColorContrastPlus;
16+
17+
/// {@template onColorContrastMinus}
18+
/// The color on the surface with a lower contrast.
19+
/// {@endtemplate}
20+
T get onColorContrastMinus;
21+
22+
/// {@template onColorSubtlePlus}
23+
/// The color on the surface with a higher contrast, but more subtle.
24+
/// {@endtemplate}
25+
T get onColorSubtlePlus;
26+
27+
/// {@template onColorSubtleMinus}
28+
/// The color on the surface with a lower contrast, but more subtle.
29+
/// {@endtemplate}
30+
T get onColorSubtleMinus;
31+
32+
/// {@template containerLowest}
33+
/// The color of the lowest container.
34+
/// {@endtemplate}
35+
T get containerLowest;
36+
37+
/// {@template containerLow}
38+
/// The color of the low container.
39+
/// {@endtemplate}
40+
T get containerLow;
41+
42+
/// {@template container}
43+
/// The color of the container.
44+
/// {@endtemplate}
45+
T get container;
46+
47+
/// {@template containerHigh}
48+
/// The color of the high container.
49+
/// {@endtemplate}
50+
T get containerHigh;
51+
52+
/// {@template containerHighest}
53+
/// The color of the highest container.
54+
/// {@endtemplate}
55+
T get containerHighest;
56+
57+
/// Linearly interpolate with another object.
58+
SurfaceGroupInterface<T> lerp(
59+
covariant SurfaceGroupInterface<T>? other,
60+
double t,
61+
);
62+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'dart:ui';
2+
3+
import 'package:dcc_toolkit/style/interface/color_group_interface.dart';
4+
5+
/// {@macro color_group}
6+
class ColorGroup implements ColorGroupInterface<Color> {
7+
/// {@macro color_group}
8+
const ColorGroup({
9+
required this.color,
10+
required this.onColor,
11+
this.onColorSubtle,
12+
});
13+
14+
@override
15+
final Color color;
16+
17+
@override
18+
final Color onColor;
19+
20+
@override
21+
final Color? onColorSubtle;
22+
23+
@override
24+
ColorGroup lerp(ColorGroup? other, double t) {
25+
if (other is! ColorGroup) {
26+
return this;
27+
}
28+
29+
return ColorGroup(
30+
color: Color.lerp(color, other.color, t) ?? color,
31+
onColor: Color.lerp(onColor, other.onColor, t) ?? onColor,
32+
onColorSubtle: onColorSubtle == null || other.onColorSubtle == null
33+
? null
34+
: Color.lerp(onColorSubtle, other.onColorSubtle, t),
35+
);
36+
}
37+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
import 'package:dcc_toolkit/style/interface/kleurplaat_interface.dart';
2+
import 'package:dcc_toolkit/style/kleurplaat/color_group.dart';
3+
import 'package:dcc_toolkit/style/kleurplaat/surface_group.dart';
4+
import 'package:flutter/material.dart';
5+
6+
/// {@macro kleurplaat}
7+
class KatjasKleurplaat extends ThemeExtension<KatjasKleurplaat>
8+
implements KleurplaatInterface<Color> {
9+
/// {@macro kleurplaat}
10+
const KatjasKleurplaat({
11+
required this.primary,
12+
required this.primaryFill,
13+
required this.content,
14+
required this.contentFill,
15+
required this.error,
16+
required this.errorFill,
17+
required this.success,
18+
required this.successFill,
19+
required this.surface,
20+
});
21+
22+
@override
23+
final ColorGroup primary;
24+
25+
@override
26+
final ColorGroup primaryFill;
27+
28+
@override
29+
final ColorGroup content;
30+
31+
@override
32+
final ColorGroup contentFill;
33+
34+
@override
35+
final ColorGroup error;
36+
37+
@override
38+
final ColorGroup errorFill;
39+
40+
@override
41+
final ColorGroup success;
42+
43+
@override
44+
final ColorGroup successFill;
45+
46+
@override
47+
final SurfaceGroup surface;
48+
49+
@override
50+
ThemeExtension<KatjasKleurplaat> copyWith({
51+
ColorGroup? primary,
52+
ColorGroup? primaryFill,
53+
ColorGroup? content,
54+
ColorGroup? contentFill,
55+
ColorGroup? error,
56+
ColorGroup? errorFill,
57+
ColorGroup? success,
58+
ColorGroup? successFill,
59+
SurfaceGroup? surface,
60+
}) =>
61+
KatjasKleurplaat(
62+
primary: primary ?? this.primary,
63+
primaryFill: primaryFill ?? this.primaryFill,
64+
content: content ?? this.content,
65+
contentFill: contentFill ?? this.contentFill,
66+
error: error ?? this.error,
67+
errorFill: errorFill ?? this.errorFill,
68+
success: success ?? this.success,
69+
successFill: successFill ?? this.successFill,
70+
surface: surface ?? this.surface,
71+
);
72+
73+
@override
74+
KatjasKleurplaat lerp(KatjasKleurplaat? other, double t) {
75+
if (other is! KatjasKleurplaat) return this;
76+
77+
return KatjasKleurplaat(
78+
primary: primary.lerp(other.primary, t),
79+
primaryFill: primaryFill.lerp(other.primaryFill, t),
80+
content: content.lerp(other.content, t),
81+
contentFill: contentFill.lerp(other.contentFill, t),
82+
error: error.lerp(other.error, t),
83+
errorFill: errorFill.lerp(other.errorFill, t),
84+
success: success.lerp(other.success, t),
85+
successFill: successFill.lerp(other.successFill, t),
86+
surface: surface.lerp(other.surface, t),
87+
);
88+
}
89+
90+
/// Converts the [KatjasKleurplaat] to a [ColorScheme].
91+
ColorScheme toColorScheme({Brightness brightness = Brightness.light}) =>
92+
ColorScheme(
93+
brightness: brightness,
94+
primary: primary.color,
95+
primaryContainer: primary.color,
96+
onPrimary: primary.onColor,
97+
onPrimaryContainer: primary.onColor,
98+
secondary: content.color,
99+
secondaryContainer: content.color,
100+
onSecondary: content.onColor,
101+
onSecondaryContainer: content.onColor,
102+
tertiary: error.color,
103+
onTertiary: error.onColor,
104+
error: error.color,
105+
onError: error.onColor,
106+
surface: surface.color,
107+
onSurface: surface.onColorContrastPlus,
108+
);
109+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import 'dart:ui';
2+
3+
import 'package:dcc_toolkit/style/interface/surface_group_interface.dart';
4+
5+
/// {@macro surface_group}
6+
class SurfaceGroup implements SurfaceGroupInterface<Color> {
7+
/// {@macro surface_group}
8+
const SurfaceGroup({
9+
required this.color,
10+
required this.onColorContrastPlus,
11+
required this.onColorContrastMinus,
12+
required this.onColorSubtlePlus,
13+
required this.onColorSubtleMinus,
14+
required this.containerLowest,
15+
required this.containerLow,
16+
required this.container,
17+
required this.containerHigh,
18+
required this.containerHighest,
19+
});
20+
21+
@override
22+
final Color color;
23+
24+
@override
25+
final Color onColorContrastPlus;
26+
27+
@override
28+
final Color onColorContrastMinus;
29+
30+
@override
31+
final Color onColorSubtlePlus;
32+
33+
@override
34+
final Color onColorSubtleMinus;
35+
36+
@override
37+
final Color containerLowest;
38+
39+
@override
40+
final Color containerLow;
41+
42+
@override
43+
final Color container;
44+
45+
@override
46+
final Color containerHigh;
47+
48+
@override
49+
final Color containerHighest;
50+
51+
@override
52+
SurfaceGroup lerp(SurfaceGroup? other, double t) {
53+
if (other == null) return this;
54+
55+
return SurfaceGroup(
56+
color: Color.lerp(color, other.color, t)!,
57+
onColorContrastPlus:
58+
Color.lerp(onColorContrastPlus, other.onColorContrastPlus, t)!,
59+
onColorContrastMinus:
60+
Color.lerp(onColorContrastMinus, other.onColorContrastMinus, t)!,
61+
onColorSubtlePlus:
62+
Color.lerp(onColorSubtlePlus, other.onColorSubtlePlus, t)!,
63+
onColorSubtleMinus:
64+
Color.lerp(onColorSubtleMinus, other.onColorSubtleMinus, t)!,
65+
containerLowest: Color.lerp(containerLowest, other.containerLowest, t)!,
66+
containerLow: Color.lerp(containerLow, other.containerLow, t)!,
67+
container: Color.lerp(container, other.container, t)!,
68+
containerHigh: Color.lerp(containerHigh, other.containerHigh, t)!,
69+
containerHighest:
70+
Color.lerp(containerHighest, other.containerHighest, t)!,
71+
);
72+
}
73+
}

lib/style/style.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export 'kleurplaat/color_group.dart';
2+
export 'kleurplaat/katjas_kleurplaat.dart';
3+
export 'kleurplaat/surface_group.dart';
4+
export 'text_style/text_style_color_group.dart';
5+
export 'text_style/text_style_decorator.dart';
6+
export 'text_style/text_style_surface_group.dart';
7+
export 'text_style/text_themes_decorator.dart';

0 commit comments

Comments
 (0)