Skip to content

Commit

Permalink
Fix iOS background image build incorrectly when background dark image…
Browse files Browse the repository at this point in the history
… is used. Fixes #452. Correct background image/color handling on web.  Fixes #450. Don't include dark styling in web if not specified in config.  Fixes 453. Add _Parameters class to hold parameters.
  • Loading branch information
jonbhanson committed Nov 20, 2022
1 parent 0239914 commit b662516
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 121 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [2.2.15] - (2022-Nov-20)

- Fix iOS background image build incorrectly when background dark image is used. Fixes [#452](https://github.com/jonbhanson/flutter_native_splash/issues/452), fixes [#439](https://github.com/jonbhanson/flutter_native_splash/issues/439).
- Correct background image/color handling on web. Fixes [#450](https://github.com/jonbhanson/flutter_native_splash/issues/450).
- Don't include dark styling in web if not specified in config. Fixes [453](https://github.com/jonbhanson/flutter_native_splash/issues/453).
- Add _Parameters class to hold parameters.

## [2.2.14] - (2022-Nov-07)

- Don't update `values-31` if there is no `android_12` section in the config. Closes [#447](https://github.com/jonbhanson/flutter_native_splash/issues/447).
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
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.14
flutter_native_splash: ^2.2.15
```
Don't forget to `flutter pub get`.
Expand Down Expand Up @@ -107,6 +107,12 @@ flutter_native_splash:
# 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:
#color_android: "#42a5f5"
#color_dark_android: "#042a49"
#color_ios: "#42a5f5"
#color_dark_ios: "#042a49"
#color_web: "#42a5f5"
#color_dark_web: "#042a49"
#image_android: assets/splash-android.png
#image_dark_android: assets/splash-invert-android.png
#image_ios: assets/splash-ios.png
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ packages:
path: ".."
relative: true
source: path
version: "2.2.14"
version: "2.2.15"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down
6 changes: 6 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ flutter_native_splash:

# 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:
#color_android: "#42a5f5"
#color_dark_android: "#042a49"
#color_ios: "#42a5f5"
#color_dark_ios: "#042a49"
#color_web: "#42a5f5"
#color_dark_web: "#042a49"
#image_android: assets/splash-android.png
#image_dark_android: assets/splash-invert-android.png
#image_ios: assets/splash-ios.png
Expand Down
214 changes: 137 additions & 77 deletions lib/cli_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,70 +44,79 @@ void createSplash({
/// 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? image =
_checkImageExists(config: config, parameter: _Parameter.image);
final String? imageAndroid =
_checkImageExists(config: config, parameter: 'image_android');
_checkImageExists(config: config, parameter: _Parameter.imageAndroid);
final String? imageIos =
_checkImageExists(config: config, parameter: 'image_ios');
_checkImageExists(config: config, parameter: _Parameter.imageIos);
final String? imageWeb =
_checkImageExists(config: config, parameter: 'image_web');
_checkImageExists(config: config, parameter: _Parameter.imageWeb);
final String? darkImage =
_checkImageExists(config: config, parameter: 'image_dark');
_checkImageExists(config: config, parameter: _Parameter.darkImage);
final String? darkImageAndroid =
_checkImageExists(config: config, parameter: 'image_dark_android');
_checkImageExists(config: config, parameter: _Parameter.darkImageAndroid);
final String? darkImageIos =
_checkImageExists(config: config, parameter: 'image_dark_ios');
_checkImageExists(config: config, parameter: _Parameter.darkImageIos);
final String? darkImageWeb =
_checkImageExists(config: config, parameter: 'image_dark_web');
_checkImageExists(config: config, parameter: _Parameter.darkImageWeb);
final String? brandingImage =
_checkImageExists(config: config, parameter: 'branding');
final String? brandingImageAndroid =
_checkImageExists(config: config, parameter: 'branding_android');
_checkImageExists(config: config, parameter: _Parameter.brandingImage);
final String? brandingImageAndroid = _checkImageExists(
config: config, parameter: _Parameter.brandingImageAndroid);
final String? brandingImageIos =
_checkImageExists(config: config, parameter: 'branding_ios');
_checkImageExists(config: config, parameter: _Parameter.brandingImageIos);
final String? brandingImageWeb =
_checkImageExists(config: config, parameter: 'branding_web');
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? brandingDarkImageWeb =
_checkImageExists(config: config, parameter: 'branding_dark_web');
final String? color = parseColor(config['color']);
final String? darkColor = parseColor(config['color_dark']);
_checkImageExists(config: config, parameter: _Parameter.brandingImageWeb);
final String? brandingDarkImage = _checkImageExists(
config: config, parameter: _Parameter.brandingDarkImage);
final String? brandingDarkImageAndroid = _checkImageExists(
config: config, parameter: _Parameter.brandingDarkImageAndroid);
final String? brandingDarkImageIos = _checkImageExists(
config: config, parameter: _Parameter.brandingDarkImageIos);
final String? brandingDarkImageWeb = _checkImageExists(
config: config, parameter: _Parameter.brandingDarkImageWeb);
final String? color = parseColor(config[_Parameter.color]);
final String? colorAndroid = parseColor(config[_Parameter.colorAndroid]);
final String? colorIos = parseColor(config[_Parameter.colorIos]);
final String? colorWeb = parseColor(config[_Parameter.colorWeb]);
final String? darkColor = parseColor(config[_Parameter.darkColor]);
final String? darkColorAndroid =
parseColor(config[_Parameter.darkColorAndroid]);
final String? darkColorIos = parseColor(config[_Parameter.darkColorIos]);
final String? darkColorWeb = parseColor(config[_Parameter.darkColorWeb]);
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');
_checkImageExists(config: config, parameter: _Parameter.backgroundImage);
final String? backgroundImageAndroid = _checkImageExists(
config: config, parameter: _Parameter.backgroundImageAndroid);
final String? backgroundImageIos = _checkImageExists(
config: config, parameter: _Parameter.backgroundImageIos);
final String? backgroundImageWeb = _checkImageExists(
config: config, parameter: _Parameter.backgroundImageWeb);
final String? darkBackgroundImage = _checkImageExists(
config: config, parameter: _Parameter.darkBackgroundImage);
final String? darkBackgroundImageAndroid = _checkImageExists(
config: config,
parameter: 'background_image_dark_android',
parameter: _Parameter.darkBackgroundImageAndroid,
);
final String? darkBackgroundImageIos =
_checkImageExists(config: config, parameter: 'background_image_dark_ios');
final String? darkBackgroundImageWeb =
_checkImageExists(config: config, parameter: 'background_image_dark_web');
final String? darkBackgroundImageIos = _checkImageExists(
config: config, parameter: _Parameter.darkBackgroundImageIos);
final String? darkBackgroundImageWeb = _checkImageExists(
config: config, parameter: _Parameter.darkBackgroundImageWeb);

final plistFiles = config['info_plist_files'] as List<String>?;
final plistFiles = config[_Parameter.plistFiles] as List<String>?;
String gravity = (config['fill'] as bool? ?? false) ? 'fill' : 'center';
if (config['android_gravity'] != null) {
gravity = config['android_gravity'] as String;
if (config[_Parameter.gravity] != null) {
gravity = config[_Parameter.gravity] as String;
}
final String? androidScreenOrientation =
config['android_screen_orientation'] as String?;
final brandingGravity = config['branding_mode'] as String? ?? 'bottom';
final bool fullscreen = config['fullscreen'] as bool? ?? false;
config[_Parameter.androidScreenOrientation] as String?;
final brandingGravity =
config[_Parameter.brandingGravity] as String? ?? 'bottom';
final bool fullscreen = config[_Parameter.fullscreen] as bool? ?? false;
final String iosContentMode =
config['ios_content_mode'] as String? ?? 'center';
final webImageMode = config['web_image_mode'] as String? ?? 'center';
config[_Parameter.iosContentMode] as String? ?? 'center';
final webImageMode = config[_Parameter.webImageMode] as String? ?? 'center';
String? android12Image;
String? android12DarkImage;
String? android12IconBackgroundColor;
Expand All @@ -117,25 +126,28 @@ void createSplashByConfig(Map<String, dynamic> config) {
String? android12BrandingImage;
String? android12DarkBrandingImage;

if (config['android_12'] != null) {
final android12Config = config['android_12'] as Map<String, dynamic>;
if (config[_Parameter.android12Section] != null) {
final android12Config =
config[_Parameter.android12Section] as Map<String, dynamic>;
android12Image =
_checkImageExists(config: android12Config, parameter: 'image');
android12DarkImage =
_checkImageExists(config: android12Config, parameter: 'image_dark');
_checkImageExists(config: android12Config, parameter: _Parameter.image);
android12DarkImage = _checkImageExists(
config: android12Config, parameter: _Parameter.darkImage);
android12IconBackgroundColor =
parseColor(android12Config['icon_background_color']);
parseColor(android12Config[_Parameter.iconBackgroundColor]);
darkAndroid12IconBackgroundColor =
parseColor(android12Config['icon_background_color_dark']);
android12Color = parseColor(android12Config['color']) ?? color;
android12DarkColor = parseColor(android12Config['color_dark']) ?? darkColor;
android12BrandingImage =
_checkImageExists(config: android12Config, parameter: 'branding');
android12DarkBrandingImage =
_checkImageExists(config: android12Config, parameter: 'branding_dark');
parseColor(android12Config[_Parameter.iconBackgroundColorDark]);
android12Color = parseColor(android12Config[_Parameter.color]) ?? color;
android12DarkColor =
parseColor(android12Config[_Parameter.darkColor]) ?? darkColor;
android12BrandingImage = _checkImageExists(
config: android12Config, parameter: _Parameter.brandingImage);
android12DarkBrandingImage = _checkImageExists(
config: android12Config, parameter: _Parameter.brandingDarkImage);
}

if (!config.containsKey('android') || config['android'] as bool) {
if (!config.containsKey(_Parameter.android) ||
config[_Parameter.android] as bool) {
if (Directory('android').existsSync()) {
_createAndroidSplash(
imagePath: imageAndroid ?? image,
Expand All @@ -144,8 +156,8 @@ void createSplashByConfig(Map<String, dynamic> config) {
brandingDarkImagePath: brandingDarkImageAndroid ?? brandingDarkImage,
backgroundImage: backgroundImageAndroid ?? backgroundImage,
darkBackgroundImage: darkBackgroundImageAndroid ?? darkBackgroundImage,
color: color,
darkColor: darkColor,
color: colorAndroid ?? color,
darkColor: darkColorAndroid ?? darkColor,
gravity: gravity,
brandingGravity: brandingGravity,
fullscreen: fullscreen,
Expand All @@ -166,7 +178,7 @@ void createSplashByConfig(Map<String, dynamic> config) {
}
}

if (!config.containsKey('ios') || config['ios'] as bool) {
if (!config.containsKey(_Parameter.ios) || config[_Parameter.ios] as bool) {
if (Directory('ios').existsSync()) {
_createiOSSplash(
imagePath: imageIos ?? image,
Expand All @@ -175,8 +187,8 @@ void createSplashByConfig(Map<String, dynamic> config) {
darkBackgroundImage: darkBackgroundImageIos ?? darkBackgroundImage,
brandingImagePath: brandingImageIos ?? brandingImage,
brandingDarkImagePath: brandingDarkImageIos ?? brandingDarkImage,
color: color,
darkColor: darkColor,
color: colorIos ?? color,
darkColor: darkColorIos ?? darkColor,
plistFiles: plistFiles,
iosContentMode: iosContentMode,
iosBrandingContentMode: brandingGravity,
Expand All @@ -187,7 +199,7 @@ void createSplashByConfig(Map<String, dynamic> config) {
}
}

if (!config.containsKey('web') || config['web'] as bool) {
if (!config.containsKey(_Parameter.web) || config[_Parameter.web] as bool) {
if (Directory('web').existsSync()) {
_createWebSplash(
imagePath: imageWeb ?? image,
Expand All @@ -196,8 +208,8 @@ void createSplashByConfig(Map<String, dynamic> config) {
darkBackgroundImage: darkBackgroundImageWeb ?? darkBackgroundImage,
brandingImagePath: brandingImageWeb ?? brandingImage,
brandingDarkImagePath: brandingDarkImageWeb ?? brandingDarkImage,
color: color,
darkColor: darkColor,
color: colorWeb ?? color,
darkColor: darkColorWeb ?? darkColor,
imageMode: webImageMode,
brandingMode: brandingGravity,
);
Expand Down Expand Up @@ -235,26 +247,26 @@ void removeSplash({
final config = getConfig(configFile: path, flavor: flavor);

final removeConfig = <String, dynamic>{
'color': '#ffffff',
'color_dark': '#000000'
_Parameter.color: '#ffffff',
_Parameter.darkColor: '#000000'
};

if (config.containsKey('android')) {
removeConfig['android'] = config['android'];
if (config.containsKey(_Parameter.android)) {
removeConfig[_Parameter.android] = config[_Parameter.android];
}

if (config.containsKey('ios')) {
removeConfig['ios'] = config['ios'];
if (config.containsKey(_Parameter.ios)) {
removeConfig[_Parameter.ios] = config[_Parameter.ios];
}

if (config.containsKey('web')) {
removeConfig['web'] = config['web'];
if (config.containsKey(_Parameter.web)) {
removeConfig[_Parameter.web] = config[_Parameter.web];
}

/// Checks if the image that was specified in the config file does exist.
/// If not the developer will receive an error message and the process will exit.
if (config.containsKey('info_plist_files')) {
removeConfig['info_plist_files'] = config['info_plist_files'];
if (config.containsKey(_Parameter.plistFiles)) {
removeConfig[_Parameter.plistFiles] = config[_Parameter.plistFiles];
}
createSplashByConfig(removeConfig);
}
Expand Down Expand Up @@ -354,3 +366,51 @@ String? parseColor(dynamic color) {

throw Exception('Invalid color value');
}

class _Parameter {
static const android = 'android';
static const android12Section = 'android_12';
static const androidScreenOrientation = 'android_screen_orientation';
static const backgroundImage = 'background_image';
static const backgroundImageAndroid = 'background_android';
static const backgroundImageIos = 'background_ios';
static const backgroundImageWeb = 'background_web';
static const brandingDarkImage = 'branding_dark';
static const brandingDarkImageAndroid = 'branding_dark_android';
static const brandingDarkImageIos = 'branding_dark_ios';
static const brandingDarkImageWeb = 'branding_dark_web';
static const brandingGravity = 'branding_mode';
static const brandingImage = 'branding';
static const brandingImageAndroid = 'branding_android';
static const brandingImageIos = 'branding_ios';
static const brandingImageWeb = 'branding_web';
static const color = 'color';
static const colorAndroid = "color_android";
static const colorIos = "color_ios";
static const colorWeb = "color_web";
static const darkBackgroundImage = 'background_image_dark';
static const darkBackgroundImageAndroid = 'background_image_dark_android';
static const darkBackgroundImageIos = 'background_image_dark_ios';
static const darkBackgroundImageWeb = 'background_image_dark_web';
static const darkColor = 'color_dark';
static const darkColorAndroid = "color_dark_android";
static const darkColorIos = "color_dark_ios";
static const darkColorWeb = "color_dark_web";
static const darkImage = 'image_dark';
static const darkImageAndroid = 'image_dark_android';
static const darkImageIos = 'image_dark_ios';
static const darkImageWeb = 'image_dark_web';
static const fullscreen = 'fullscreen';
static const gravity = 'android_gravity';
static const iconBackgroundColor = 'icon_background_color';
static const iconBackgroundColorDark = 'icon_background_color_dark';
static const image = 'image';
static const imageAndroid = 'image_android';
static const imageIos = 'image_ios';
static const imageWeb = 'image_web';
static const ios = 'ios';
static const iosContentMode = 'ios_content_mode';
static const plistFiles = 'info_plist_files';
static const web = 'web';
static const webImageMode = 'web_image_mode';
}
4 changes: 3 additions & 1 deletion lib/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ void _createiOSSplash({
backgroundImageFile.createSync(recursive: true);

backgroundImageFile.writeAsStringSync(
darkColor != null ? _iOSLaunchBackgroundDarkJson : _iOSLaunchBackgroundJson,
(darkColor != null || darkBackgroundImage != null)
? _iOSLaunchBackgroundDarkJson
: _iOSLaunchBackgroundJson,
);

_applyInfoPList(plistFiles: plistFiles, fullscreen: fullscreen);
Expand Down
Loading

0 comments on commit b662516

Please sign in to comment.