1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import 'package:flutter/material.dart';
@immutable
class BrandColors extends ThemeExtension<BrandColors> {
const BrandColors({required this.banner, required this.onBanner});
final Color banner;
final Color onBanner;
@override
BrandColors copyWith({Color? banner, Color? onBanner}) => BrandColors(
banner: banner ?? this.banner,
onBanner: onBanner ?? this.onBanner,
);
@override
BrandColors lerp(ThemeExtension<BrandColors>? other, double t) {
if (other is! BrandColors) return this;
return BrandColors(
banner: Color.lerp(banner, other.banner, t)!,
onBanner: Color.lerp(onBanner, other.onBanner, t)!,
);
}
}
ThemeData lightTheme() {
final ColorScheme scheme = ColorScheme.fromSeed(seedColor: const Color(0xFF1565C0));
return ThemeData(
useMaterial3: true,
colorScheme: scheme,
extensions: const <ThemeExtension<dynamic>>[
BrandColors(banner: Color(0xFFE3F2FD), onBanner: Color(0xFF0D47A1)),
],
);
}
ThemeData darkTheme() {
final ColorScheme scheme = ColorScheme.fromSeed(
seedColor: const Color(0xFF1565C0),
brightness: Brightness.dark,
);
return ThemeData(
useMaterial3: true,
colorScheme: scheme,
extensions: const <ThemeExtension<dynamic>>[
BrandColors(banner: Color(0xFF0D47A1), onBanner: Color(0xFFE3F2FD)),
],
);
}
extension BrandColorsX on BuildContext {
BrandColors get brand => Theme.of(this).extension<BrandColors>()!;
}