Skip to content

Commit 1a976c0

Browse files
authored
♻️ update android_12 key in pubspec to android_12_and_above (#46)
1 parent 8ddcecf commit 1a976c0

File tree

4 files changed

+33
-25
lines changed

4 files changed

+33
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dependencies:
4848
# bottom, fill_vertical, center_horizontal, top, end, left, right, start
4949
android_gravity: 'center'
5050
# Section to specifies the configuration for the splash in Android 12+
51-
android_12:
51+
android_12_and_above:
5252
# Provides the background color of splash screen
5353
color: '#FFFFFF'
5454
# Provides custom icon to replace the default app icon

lib/cmd/android_splash.dart

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,21 @@ Future<void> generateAndroidImages({
4848
await file.delete();
4949
}
5050
final sourceImage = File(imageSource);
51+
if (await sourceImage.exists()) {
52+
/// Creating a splash image from the provided asset source
53+
sourceImage.copySync(imagePath);
54+
} else {
55+
throw SplashMasterException(message: 'Image path not found');
56+
}
5157

52-
/// Creating a splash image from the provided asset source
53-
sourceImage.copySync(imagePath);
5458
log("Splash image added to ${mipmap.folder}");
5559
}
5660
}
5761

58-
Future<void> generateAndroid12Images({
59-
YamlMap? android12,
62+
Future<void> generateImageForAndroid12AndAbove({
63+
YamlMap? android12AndAbove,
6064
}) async {
61-
if (android12 == null) {
65+
if (android12AndAbove == null) {
6266
log('Skipping Android 12 configuration as it is not provided.');
6367
return;
6468
}
@@ -74,16 +78,20 @@ Future<void> generateAndroid12Images({
7478
}
7579

7680
/// Create image in mipmap directories for the Android 12+
77-
if (android12[YamlKeys.imageKey] != null) {
81+
if (android12AndAbove[YamlKeys.imageKey] != null) {
7882
final imagePath = '$mipmapFolder/${AndroidStrings.splashImage12Png}';
7983
final file = File(imagePath);
8084
if (await file.exists()) {
8185
await file.delete();
8286
}
83-
final sourceImage = File(android12[YamlKeys.imageKey]);
87+
final sourceImage = File(android12AndAbove[YamlKeys.imageKey]);
88+
if (await sourceImage.exists()) {
89+
/// Creating a splash image from the provided asset source
90+
sourceImage.copySync(imagePath);
91+
} else {
92+
throw SplashMasterException(message: 'Image path not found');
93+
}
8494

85-
/// Creating a splash image from the provided asset source
86-
sourceImage.copySync(imagePath);
8795
log("Splash image added to ${mipmap.folder}");
8896
}
8997
}
@@ -159,14 +167,14 @@ Future<void> createColors({
159167

160168
/// Updates the `styles.xml` file for the splash screen setup.
161169
Future<void> updateStylesXml({
162-
YamlMap? android12,
170+
YamlMap? android12AndAbove,
163171
String? color,
164172
}) async {
165173
const androidValuesFolder = CmdStrings.androidValuesDirectory;
166174

167-
if (android12 != null &&
168-
(android12[YamlKeys.colorKey] != null ||
169-
android12[YamlKeys.imageKey] != null)) {
175+
if (android12AndAbove != null &&
176+
(android12AndAbove[YamlKeys.colorKey] != null ||
177+
android12AndAbove[YamlKeys.imageKey] != null)) {
170178
const v31 = CmdStrings.androidValuesV31Directory;
171179
if (!await Directory(v31).exists()) {
172180
Directory(v31).create();
@@ -179,8 +187,8 @@ Future<void> updateStylesXml({
179187

180188
createAndroid12Styles(
181189
styleFile: styleFile,
182-
color: android12[YamlKeys.colorKey],
183-
imageSource: android12[YamlKeys.imageKey],
190+
color: android12AndAbove[YamlKeys.colorKey],
191+
imageSource: android12AndAbove[YamlKeys.imageKey],
184192
);
185193
}
186194
final xml = File('$androidValuesFolder/${AndroidStrings.stylesXml}');

lib/cmd/command_line.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ void setupSplashScreen(YamlMap splashData) {
131131
color: splashData[YamlKeys.colorKey],
132132
gravity: splashData[YamlKeys.androidGravityKey],
133133
iosContentMode: iosContentMode?.mode,
134-
android12: splashData[YamlKeys.android12key],
134+
android12AndAbove: splashData[YamlKeys.android12AndAbovekey],
135135
);
136136
}
137137
}
@@ -141,13 +141,13 @@ Future<void> applyAndroidSplashImage({
141141
String? imageSource,
142142
String? color,
143143
String? gravity,
144-
YamlMap? android12,
144+
YamlMap? android12AndAbove,
145145
}) async {
146146
await generateAndroidImages(
147147
imageSource: imageSource,
148148
);
149-
await generateAndroid12Images(
150-
android12: android12,
149+
await generateImageForAndroid12AndAbove(
150+
android12AndAbove: android12AndAbove,
151151
);
152152
await createColors(
153153
color: color,
@@ -158,7 +158,7 @@ Future<void> applyAndroidSplashImage({
158158
gravity: gravity,
159159
);
160160
await updateStylesXml(
161-
android12: android12,
161+
android12AndAbove: android12AndAbove,
162162
color: color,
163163
);
164164
}
@@ -169,7 +169,7 @@ Future<void> applySplash({
169169
String? color,
170170
String? gravity,
171171
String? iosContentMode,
172-
YamlMap? android12,
172+
YamlMap? android12AndAbove,
173173
}) async {
174174
await generateIosImages(
175175
imageSource: imageSource,
@@ -180,6 +180,6 @@ Future<void> applySplash({
180180
imageSource: imageSource,
181181
color: color,
182182
gravity: gravity,
183-
android12: android12,
183+
android12AndAbove: android12AndAbove,
184184
);
185185
}

lib/values/yaml_keys.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ class YamlKeys {
3737
static const iosContentModeKey = 'ios_content_mode';
3838

3939
/// Specifies splash screen setup details for Android 12.
40-
static const android12key = 'android_12';
40+
static const android12AndAbovekey = 'android_12_and_above';
4141

4242
/// List of supported keys
4343
static List<String> supportedYamlKeys = [
4444
imageKey,
4545
colorKey,
4646
androidGravityKey,
4747
iosContentModeKey,
48-
android12key,
48+
android12AndAbovekey,
4949
];
5050
}

0 commit comments

Comments
 (0)