diff --git a/CHANGELOG.md b/CHANGELOG.md index b4bd3e3..7c467f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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). diff --git a/README.md b/README.md index 36df7d2..c6e7451 100644 --- a/README.md +++ b/README.md @@ -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`. @@ -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 diff --git a/example/pubspec.lock b/example/pubspec.lock index 9d63be0..1728af7 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index c79346d..d1a8386 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -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 diff --git a/lib/cli_commands.dart b/lib/cli_commands.dart index 9ee4be2..2a3718c 100644 --- a/lib/cli_commands.dart +++ b/lib/cli_commands.dart @@ -44,70 +44,79 @@ void createSplash({ /// Create splash screens for Android and iOS based on a config argument void createSplashByConfig(Map 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?; + final plistFiles = config[_Parameter.plistFiles] as List?; 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; @@ -117,25 +126,28 @@ void createSplashByConfig(Map config) { String? android12BrandingImage; String? android12DarkBrandingImage; - if (config['android_12'] != null) { - final android12Config = config['android_12'] as Map; + if (config[_Parameter.android12Section] != null) { + final android12Config = + config[_Parameter.android12Section] as Map; 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, @@ -144,8 +156,8 @@ void createSplashByConfig(Map 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, @@ -166,7 +178,7 @@ void createSplashByConfig(Map 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, @@ -175,8 +187,8 @@ void createSplashByConfig(Map 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, @@ -187,7 +199,7 @@ void createSplashByConfig(Map 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, @@ -196,8 +208,8 @@ void createSplashByConfig(Map config) { darkBackgroundImage: darkBackgroundImageWeb ?? darkBackgroundImage, brandingImagePath: brandingImageWeb ?? brandingImage, brandingDarkImagePath: brandingDarkImageWeb ?? brandingDarkImage, - color: color, - darkColor: darkColor, + color: colorWeb ?? color, + darkColor: darkColorWeb ?? darkColor, imageMode: webImageMode, brandingMode: brandingGravity, ); @@ -235,26 +247,26 @@ void removeSplash({ final config = getConfig(configFile: path, flavor: flavor); final removeConfig = { - '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); } @@ -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'; +} diff --git a/lib/ios.dart b/lib/ios.dart index 157d157..759087c 100644 --- a/lib/ios.dart +++ b/lib/ios.dart @@ -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); diff --git a/lib/templates.dart b/lib/templates.dart index 38a0ad9..a5939ed 100644 --- a/lib/templates.dart +++ b/lib/templates.dart @@ -344,8 +344,7 @@ const String _iOSLaunchBackgroundDarkJson = ''' "images" : [ { "filename" : "background.png", - "idiom" : "universal", - "scale" : "1x" + "idiom" : "universal" }, { "appearances" : [ @@ -355,36 +354,7 @@ const String _iOSLaunchBackgroundDarkJson = ''' } ], "filename" : "darkbackground.png", - "idiom" : "universal", - "scale" : "1x" - }, - { - "idiom" : "universal", - "scale" : "2x" - }, - { - "appearances" : [ - { - "appearance" : "luminosity", - "value" : "dark" - } - ], - "idiom" : "universal", - "scale" : "2x" - }, - { - "idiom" : "universal", - "scale" : "3x" - }, - { - "appearances" : [ - { - "appearance" : "luminosity", - "value" : "dark" - } - ], - "idiom" : "universal", - "scale" : "3x" + "idiom" : "universal" } ], "info" : { @@ -439,7 +409,7 @@ const String _webCss = ''' body { margin:0; height:100%; - background: [LIGHTBACKGROUNDCOLOR]; + background-color: [LIGHTBACKGROUNDCOLOR]; [LIGHTBACKGROUNDIMAGE] background-size: 100% 100%; } @@ -489,12 +459,15 @@ body { bottom: 0; right: 0; } +'''; + +const String _webCssDark = ''' @media (prefers-color-scheme: dark) { body { margin:0; height:100%; - background: [DARKBACKGROUNDCOLOR]; + background-color: [DARKBACKGROUNDCOLOR]; [DARKBACKGROUNDIMAGE] background-size: 100% 100%; } diff --git a/lib/web.dart b/lib/web.dart index 3daffc2..1b633b2 100644 --- a/lib/web.dart +++ b/lib/web.dart @@ -86,6 +86,7 @@ void _createWebSplash({ darkColor: darkColor, darkBackgroundImage: darkBackgroundImage, backgroundImage: backgroundImage, + hasDarkImage: darkBackgroundImage != null, ); _createSplashJs(); _updateHtml( @@ -167,16 +168,19 @@ void _createSplashCss({ required String? darkColor, required String? backgroundImage, required String? darkBackgroundImage, + required bool hasDarkImage, }) { print('[Web] Creating CSS'); color ??= '000000'; - darkColor ??= color; - var cssContent = _webCss - .replaceFirst('[LIGHTBACKGROUNDCOLOR]', '#$color') - .replaceFirst('[DARKBACKGROUNDCOLOR]', '#$darkColor'); + var cssContent = _webCss.replaceFirst('[LIGHTBACKGROUNDCOLOR]', '#$color'); + if (darkColor != null || darkBackgroundImage != null || hasDarkImage) { + darkColor ??= color; + cssContent += + _webCssDark.replaceFirst('[DARKBACKGROUNDCOLOR]', '#$darkColor'); + } if (backgroundImage == null) { - cssContent = cssContent.replaceFirst('[LIGHTBACKGROUNDIMAGE]', ''); + cssContent = cssContent.replaceFirst(' [LIGHTBACKGROUNDIMAGE]\n', ''); } else { cssContent = cssContent.replaceFirst( '[LIGHTBACKGROUNDIMAGE]', @@ -185,7 +189,7 @@ void _createSplashCss({ } if (backgroundImage == null) { - cssContent = cssContent.replaceFirst('[DARKBACKGROUNDIMAGE]', ''); + cssContent = cssContent.replaceFirst(' [DARKBACKGROUNDIMAGE]\n', ''); } else { cssContent = cssContent.replaceFirst( '[DARKBACKGROUNDIMAGE]', diff --git a/pubspec.yaml b/pubspec.yaml index 07c8de2..d6c50d0 100644 --- a/pubspec.yaml +++ b/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.14 +version: 2.2.15 repository: https://github.com/jonbhanson/flutter_native_splash issue_tracker: https://github.com/jonbhanson/flutter_native_splash/issues