forked from firebase/flutterfire
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoauth_provider_button_style.dart
85 lines (73 loc) · 2.32 KB
/
oauth_provider_button_style.dart
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import 'package:flutter/services.dart';
/// {@template ui.oauth.themed_value}
/// An object that is used to resolve the value base on the current theme
/// brightness.
/// {@endtemplate}
class ThemedValue<T> {
/// The value that should be used to when the dark theme is used.
final T dark;
/// The value that should be used to when the light theme is used.
final T light;
const ThemedValue(this.dark, this.light);
T getValue(Brightness brightness) {
switch (brightness) {
case Brightness.dark:
return dark;
case Brightness.light:
return light;
}
}
}
class ThemedColor extends ThemedValue<Color> {
const ThemedColor(Color dark, Color light) : super(dark, light);
}
class ThemedIconSrc extends ThemedValue<String> {
const ThemedIconSrc(
String dark,
String light,
) : super(dark, light);
}
/// {@template ui.oauth.themed_oauth_provider_button_style}
/// An object that is being used to resolve a style of the button.
/// {@endtemplate}
abstract class ThemedOAuthProviderButtonStyle {
ThemedIconSrc get iconSrc;
ThemedColor get backgroundColor;
ThemedColor get color;
ThemedColor get iconBackgroundColor => backgroundColor;
ThemedColor get borderColor => backgroundColor;
double get iconPadding => 0;
String get assetsPackage;
/// A custom label string.
///
/// Required for custom OAuth providers.
String? get label => null;
/// {@macro ui.oauth.themed_oauth_provider_button_style}
const ThemedOAuthProviderButtonStyle();
OAuthProviderButtonStyle withBrightness(Brightness brightness) {
return OAuthProviderButtonStyle(
iconSrc: iconSrc.getValue(brightness),
backgroundColor: backgroundColor.getValue(brightness),
color: color.getValue(brightness),
borderColor: borderColor.getValue(brightness),
assetsPackage: assetsPackage,
iconBackgroundColor: iconBackgroundColor.getValue(brightness),
);
}
}
class OAuthProviderButtonStyle {
final String iconSrc;
final Color backgroundColor;
final Color color;
final Color borderColor;
final String assetsPackage;
final Color iconBackgroundColor;
OAuthProviderButtonStyle({
required this.iconSrc,
required this.backgroundColor,
required this.color,
required this.borderColor,
required this.assetsPackage,
required this.iconBackgroundColor,
});
}