Skip to content

Commit

Permalink
Added parameters for platform-specific images. Closes #375. Remove bl…
Browse files Browse the repository at this point in the history
…ack status bar which appeared on Android devices with a notch. Fixes #311.
  • Loading branch information
jonbhanson committed Jul 3, 2022
1 parent f9207f3 commit 4029f1f
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 69 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
@@ -1,13 +1,14 @@
##[2.2.4] - (2022-July-03)
* Added parameters for platform-specific images. Closes [#375](https://github.com/jonbhanson/flutter_native_splash/issues/375).
* Remove black status bar which appeared on Android devices with a notch. Fixes [#311](https://github.com/jonbhanson/flutter_native_splash/issues/311).
##[2.2.3+1] - (2022-June-12)
* Updated readme.

## [2.2.3] - (2022-June-5)
* Create new storyboard file rather than try to modify existing file. Closes [#369](https://github.com/jonbhanson/flutter_native_splash/issues/369).
* Reverted 2.1.6 change of using light settings for dark mode if omitted. Fixes [#368](https://github.com/jonbhanson/flutter_native_splash/issues/368).
## [2.2.2] - (2022-May-29)
* Corrected Android 12 color overriding color parameter. Closes [#365](https://github.com/jonbhanson/flutter_native_splash/issues/365).
* Add support for setting screen orientation in Android. Closes [#344](https://github.com/jonbhanson/flutter_native_splash/issues/344).

## [2.2.1] - (2022-May-22)
* Updated dependencies. Closes [#358](https://github.com/jonbhanson/flutter_native_splash/issues/358).
* Added Android 12 background color support. Closes [#357](https://github.com/jonbhanson/flutter_native_splash/issues/357).
Expand Down
23 changes: 21 additions & 2 deletions README.md
Expand Up @@ -19,7 +19,7 @@ First, add `flutter_native_splash` as a dependency in your pubspec.yaml file.

```yaml
dependencies:
flutter_native_splash: ^2.2.3+1
flutter_native_splash: ^2.2.4
```

Don't forget to `flutter pub get`.
Expand Down Expand Up @@ -100,7 +100,26 @@ flutter_native_splash:
#android: false
#ios: false
#web: false


# Platform specific images can be specified with the following parameters, which will override
# the respective image parameter. You may specify all, selected, or none of these parameters:
#image_andriod: assets/splash-andriod.png
#image_dark_android: assets/splash-invert-android.png
#image_ios: assets/splash-ios.png
#image_dark_ios: assets/splash-invert-ios.png
#image_web: assets/splash-web.png
#image_dark_web: assets/splash-invert-web.png
#background_image_android: "assets/background-android.png"
#background_image_dark_android: "assets/dark-background-android.png"
#background_image_ios: "assets/background-ios.png"
#background_image_dark_ios: "assets/dark-background-ios.png"
#background_image_web: "assets/background-web.png"
#background_image_dark_web: "assets/dark-background-web.png"
#branding_andriod: assets/brand-android.png
#branding_dark_android: assets/dart_dark-android.png
#branding_ios: assets/brand-ios.png
#branding_dark_ios: assets/dart_dark-ios.png

# The position of the splash image can be set with android_gravity, ios_content_mode, and
# web_image_mode parameters. All default to center.
#
Expand Down
6 changes: 6 additions & 0 deletions lib/android.dart
Expand Up @@ -381,6 +381,12 @@ Future<void> _updateStylesFile({
value: fullScreen.toString(),
);

replaceElement(
launchTheme: launchTheme,
name: 'android:windowLayoutInDisplayCutoutMode',
value: 'shortEdges',
);

// In Android 12, the color must be set directly in the styles.xml
if (android12BackgroundColor != null) {
replaceElement(
Expand Down
112 changes: 48 additions & 64 deletions lib/cli_commands.dart
Expand Up @@ -38,26 +38,57 @@ void createSplash({String? path, String? flavor}) {
_flavorHelper = _FlavorHelper(flavor);

final config = getConfig(configFile: path);
_checkConfig(config);
createSplashByConfig(config);
}

/// Create splash screens for Android and iOS based on a config argument
void createSplashByConfig(Map<String, dynamic> config) {
// Preparing all the data for later usage
final String? image = _checkImageExists(config: config, parameter: 'image');
final String? imageAndroid =
_checkImageExists(config: config, parameter: 'image_android');
final String? imageIos =
_checkImageExists(config: config, parameter: 'image_ios');
final String? imageWeb =
_checkImageExists(config: config, parameter: 'image_web');
final String? darkImage =
_checkImageExists(config: config, parameter: 'image_dark');
final String? darkImageAndroid =
_checkImageExists(config: config, parameter: 'image_dark_android');
final String? darkImageIos =
_checkImageExists(config: config, parameter: 'image_dark_ios');
final String? darkImageWeb =
_checkImageExists(config: config, parameter: 'image_dark_web');
final String? brandingImage =
_checkImageExists(config: config, parameter: 'branding');
final String? brandingImageAndroid =
_checkImageExists(config: config, parameter: 'branding_android');
final String? brandingImageIos =
_checkImageExists(config: config, parameter: 'branding_ios');
final String? brandingDarkImage =
_checkImageExists(config: config, parameter: 'branding_dark');
final String? brandingDarkImageAndroid =
_checkImageExists(config: config, parameter: 'branding_dark_android');
final String? brandingDarkImageIos =
_checkImageExists(config: config, parameter: 'branding_dark_ios');
final String? color = parseColor(config['color']);
final String? darkColor = parseColor(config['color_dark']);
final String? backgroundImage =
_checkImageExists(config: config, parameter: 'background_image');
final String? backgroundImageAndroid =
_checkImageExists(config: config, parameter: 'background_android');
final String? backgroundImageIos =
_checkImageExists(config: config, parameter: 'background_ios');
final String? backgroundImageWeb =
_checkImageExists(config: config, parameter: 'background_web');
final String? darkBackgroundImage =
_checkImageExists(config: config, parameter: 'background_image_dark');
final String? darkBackgroundImageAndroid = _checkImageExists(
config: config, parameter: 'background_image_dark_android');
final String? darkBackgroundImageIos =
_checkImageExists(config: config, parameter: 'background_image_dark_ios');
final String? darkBackgroundImageWeb =
_checkImageExists(config: config, parameter: 'background_image_dark_web');

final plistFiles = config['info_plist_files'] as List<String>?;
String gravity = (config['fill'] as bool? ?? false) ? 'fill' : 'center';
Expand Down Expand Up @@ -95,16 +126,16 @@ void createSplashByConfig(Map<String, dynamic> config) {
if (!config.containsKey('android') || config['android'] as bool) {
if (Directory('android').existsSync()) {
_createAndroidSplash(
imagePath: image,
darkImagePath: darkImage,
brandingImagePath: brandingImage,
brandingDarkImagePath: brandingDarkImage,
imagePath: imageAndroid ?? image,
darkImagePath: darkImageAndroid ?? darkImage,
brandingImagePath: brandingImageAndroid ?? brandingImage,
brandingDarkImagePath: brandingDarkImageAndroid ?? brandingDarkImage,
android12ImagePath: android12Image,
android12DarkImagePath: android12DarkImage,
android12IconBackgroundColor: android12IconBackgroundColor,
darkAndroid12IconBackgroundColor: darkAndroid12IconBackgroundColor,
backgroundImage: backgroundImage,
darkBackgroundImage: darkBackgroundImage,
backgroundImage: backgroundImageAndroid ?? backgroundImage,
darkBackgroundImage: darkBackgroundImageAndroid ?? darkBackgroundImage,
color: android12Color ?? color,
darkColor: android12DarkColor ?? darkColor,
gravity: gravity,
Expand All @@ -122,12 +153,12 @@ void createSplashByConfig(Map<String, dynamic> config) {
if (!config.containsKey('ios') || config['ios'] as bool) {
if (Directory('ios').existsSync()) {
_createiOSSplash(
imagePath: image,
darkImagePath: darkImage,
backgroundImage: backgroundImage,
darkBackgroundImage: darkBackgroundImage,
brandingImagePath: brandingImage,
brandingDarkImagePath: brandingDarkImage,
imagePath: imageIos ?? image,
darkImagePath: darkImageIos ?? darkImage,
backgroundImage: backgroundImageIos ?? backgroundImage,
darkBackgroundImage: darkBackgroundImageIos ?? darkBackgroundImage,
brandingImagePath: brandingImageIos ?? brandingImage,
brandingDarkImagePath: brandingDarkImageIos ?? brandingDarkImage,
color: color,
darkColor: darkColor,
plistFiles: plistFiles,
Expand All @@ -143,10 +174,10 @@ void createSplashByConfig(Map<String, dynamic> config) {
if (!config.containsKey('web') || config['web'] as bool) {
if (Directory('web').existsSync()) {
_createWebSplash(
imagePath: image,
darkImagePath: darkImage,
backgroundImage: backgroundImage,
darkBackgroundImage: darkBackgroundImage,
imagePath: imageWeb ?? image,
darkImagePath: darkImageWeb ?? darkImage,
backgroundImage: backgroundImageWeb ?? backgroundImage,
darkBackgroundImage: darkBackgroundImageWeb ?? darkBackgroundImage,
color: color,
darkColor: darkColor,
imageMode: webImageMode,
Expand Down Expand Up @@ -283,53 +314,6 @@ Map<String, dynamic> _yamlToMap(YamlMap yamlMap) {
return map;
}

/// Validates if the mix and match of different setup values are not conflicting with each other.
/// If they do, the developer will get a message where the issue is.
void _checkConfig(Map<String, dynamic> config) {
if (config.containsKey('color') && config.containsKey('background_image')) {
print(
'Your `flutter_native_splash` section cannot not contain both a '
'`color` and `background_image`.',
);
exit(1);
}

if (!config.containsKey('color') && !config.containsKey('background_image')) {
print(
'Your `flutter_native_splash` section does not contain a `color` or '
'`background_image`.',
);
exit(1);
}

if (config.containsKey('color_dark') &&
config.containsKey('background_image_dark')) {
print(
'Your `flutter_native_splash` section cannot not contain both a '
'`color_dark` and `background_image_dark`.',
);
exit(1);
}

if (config.containsKey('image_dark') &&
!config.containsKey('color_dark') &&
!config.containsKey('background_image_dark')) {
print(
'Your `flutter_native_splash` section contains `image_dark` but '
'does not contain a `color_dark` or a `background_image_dark`.',
);
exit(1);
}

if (config.containsKey('branding_dark') && !config.containsKey('branding')) {
print(
'Your `flutter_native_splash` section contains `branding_dark` but '
'does not contain a `branding`.',
);
exit(1);
}
}

@visibleForTesting
String? parseColor(dynamic color) {
dynamic colorValue = color;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,7 +1,7 @@
name: flutter_native_splash
description: Customize Flutter's default white native splash screen with
background color and splash image. Supports dark mode, full screen, and more.
version: 2.2.3+1
version: 2.2.4
homepage: https://github.com/jonbhanson/flutter_native_splash

environment:
Expand Down

0 comments on commit 4029f1f

Please sign in to comment.