-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
utils.dart
125 lines (105 loc) · 3.81 KB
/
utils.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/// Checks if the config file contains a `platform`
bool hasPlatformConfig(Map<String, dynamic> config) {
final bool isHasPlatforms = config.containsKey('platforms');
if (isHasPlatforms) {
final platforms = config['platforms'] as Map<String, dynamic>;
final bool isHasPlatformSpecific = isNeedingNewAndroidIcon(platforms) ||
isNeedingNewIosIcon(platforms) ||
isNeedingNewMacOSIcon(platforms) ||
isNeedingNewWindowsIcon(platforms) ||
isNeedingNewWebIcon(platforms) ||
isNeedingNewLinuxIcon(platforms);
return isHasPlatformSpecific;
}
return false;
}
/// Checks if the config has android.
bool hasAndroidConfig(Map<String, dynamic> platforms) {
return platforms.containsKey('android');
}
/// Checks if the config need android.
bool isNeedingNewAndroidIcon(Map<String, dynamic> platforms) {
return hasAndroidConfig(platforms) && platforms['android']['enable'] == true;
}
/// Checks if the config has android adaptive.
bool hasAndroidAdaptiveConfig(Map<String, dynamic> platforms) {
return isNeedingNewAndroidIcon(platforms) &&
(platforms['android'].containsKey('adaptive_background_image') ||
platforms['android'].containsKey('adaptive_background_color')) &&
platforms['android'].containsKey('adaptive_foreground_image');
}
/// Checks if the config has ios.
bool hasIosConfig(Map<String, dynamic> platforms) {
return platforms.containsKey('ios');
}
/// Checks if the config need ios.
bool isNeedingNewIosIcon(Map<String, dynamic> platforms) {
return hasIosConfig(platforms) && platforms['ios']['enable'] == true;
}
/// Checks if the config has macos.
bool hasMacOSConfig(Map<String, dynamic> platforms) {
return platforms.containsKey('macos');
}
/// Checks if the config need macos.
bool isNeedingNewMacOSIcon(Map<String, dynamic> platforms) {
return hasMacOSConfig(platforms) && platforms['macos']['enable'] == true;
}
/// Checks if the config has windows.
bool hasWindowsConfig(Map<String, dynamic> platforms) {
return platforms.containsKey('windows');
}
/// Checks if the config need windows.
bool isNeedingNewWindowsIcon(Map<String, dynamic> platforms) {
return hasWindowsConfig(platforms) && platforms['windows']['enable'] == true;
}
/// Checks if the config has linux.
bool hasLinuxConfig(Map<String, dynamic> platforms) {
return platforms.containsKey('linux');
}
/// Checks if the config need linux.
bool isNeedingNewLinuxIcon(Map<String, dynamic> platforms) {
return hasLinuxConfig(platforms) && platforms['linux']['enable'] == true;
}
/// Checks if the config has web.
bool hasWebConfig(Map<String, dynamic> platforms) {
return platforms.containsKey('web');
}
/// Checks if the config need linux.
bool isNeedingNewWebIcon(Map<String, dynamic> platforms) {
return hasWebConfig(platforms) && platforms['web']['enable'] == true;
}
/// Checking color code
bool isValidHexaCode(String hexaCode) {
if (hexaCode[0] != '#') {
return false;
}
if (!(hexaCode.length == 4 || hexaCode.length == 7)) {
return false;
}
for (var i = 1; i < hexaCode.length; i++) {
if (!((hexaCode[i].codeUnitAt(0) <= '0'.codeUnitAt(0) &&
hexaCode[i].codeUnitAt(0) <= 9) ||
(hexaCode[i].codeUnitAt(0) >= 'a'.codeUnitAt(0) &&
hexaCode[i].codeUnitAt(0) <= 'f'.codeUnitAt(0)) ||
(hexaCode[i].codeUnitAt(0) >= 'A'.codeUnitAt(0) ||
hexaCode[i].codeUnitAt(0) <= 'F'.codeUnitAt(0)))) {
return false;
}
}
return true;
}
/// Checking valid image file
bool isImageFile(String fileName) {
return fileName.endsWith('.png') ||
fileName.endsWith('.jpg') ||
fileName.endsWith('.jpeg');
}
/// Get color xml content
String getColorXmlContent(String color) {
return '''
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="ic_launcher_background">${color.toUpperCase()}</color>
</resources>
''';
}