From 286b800b4003ffc496bf18fe5c969ecef637a4fc Mon Sep 17 00:00:00 2001 From: Jon Hanson Date: Thu, 23 Sep 2021 13:23:57 -0400 Subject: [PATCH] * Updated readme. Thanks @j-j-gajjar for PR #216. * Remove references to background images in web when images are missing. Fixes #196. * Updated dependencies. --- CHANGELOG.md | 5 +++++ README.md | 6 +++--- lib/templates.dart | 4 ++-- lib/web.dart | 27 +++++++++++++++++++++++++-- pubspec.yaml | 6 +++--- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60c7613..82929f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [1.2.4] - (2021-Sep-23) +* Updated readme. Thanks [@j-j-gajjar](https://github.com/j-j-gajjar) for PR [#216](https://github.com/jonbhanson/flutter_native_splash/pull/216). +* Remove references to background images in web when images are missing. Fixes [#196](https://github.com/jonbhanson/flutter_native_splash/issues/196). +* Updated dependencies. + ## [1.2.3] - (2021-Sep-08) * Reverted XML dependency to be compatible with stable Flutter branch. Closes [#206](https://github.com/jonbhanson/flutter_native_splash/issues/206). diff --git a/README.md b/README.md index 9717eb0..33df0c2 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![pub package](https://img.shields.io/pub/v/flutter_native_splash)](https://pub.dev/packages/flutter_native_splash) [![Build Status](https://img.shields.io/travis/jonbhanson/flutter_native_splash)](https://travis-ci.org/jonbhanson/flutter_native_splash) -When your app is opened, there is a brief time while the native app loads Flutter. By default, during this time, the native app displays a white splash screen. This package automatically generates iOS, Android, and Web-native code for customizing this native splash screen background colour and splash image. Supports dark mode, full screen, and platform-specific options. +When your app is opened, there is a brief time while the native app loads Flutter. By default, during this time, the native app displays a white splash screen. This package automatically generates iOS, Android, and Web-native code for customizing this native splash screen background color and splash image. Supports dark mode, full screen, and platform-specific options.

@@ -17,7 +17,7 @@ First, add `flutter_native_splash` as a dev dependency in your pubspec.yaml file ```yaml dev_dependencies: - flutter_native_splash: ^1.2.3 + flutter_native_splash: ^1.2.4 ``` Don't forget to `flutter pub get`. @@ -177,7 +177,7 @@ This attribute is only found in Android 12, so if you are getting this error, it ## iOS * Your splash image will be resized to `@3x` and `@2x` images. * Color and image properties will be inserted in `LaunchScreen.storyboard`. -* The background colour is implemented by using a single-pixel png file and stretching it to fit the screen. +* The background color is implemented by using a single-pixel png file and stretching it to fit the screen. * Code for hidden status bar toggle will be added in `Info.plist`. ## Web diff --git a/lib/templates.dart b/lib/templates.dart index 62fa8f9..3e0a769 100644 --- a/lib/templates.dart +++ b/lib/templates.dart @@ -325,7 +325,7 @@ body, html { margin:0; height:100%; background: [LIGHTBACKGROUNDCOLOR]; - background-image: url("img/light-background.png"); + [LIGHTBACKGROUNDIMAGE] background-size: 100% 100%; } @@ -360,7 +360,7 @@ body, html { margin:0; height:100%; background: [DARKBACKGROUNDCOLOR]; - background-image: url("img/dark-background.png"); + [DARKBACKGROUNDIMAGE] background-size: 100% 100%; } } diff --git a/lib/web.dart b/lib/web.dart index 6ad0859..eea3bca 100644 --- a/lib/web.dart +++ b/lib/web.dart @@ -38,7 +38,11 @@ void _createWebSplash({ createBackgroundImages( backgroundImage: backgroundImage, darkBackgroundImage: darkBackgroundImage); - createSplashCss(color: color, darkColor: darkColor); + createSplashCss( + color: color, + darkColor: darkColor, + darkBackgroundImage: darkBackgroundImage, + backgroundImage: backgroundImage); updateIndex(imageMode: imageMode, imagePath: imagePath); } @@ -105,12 +109,31 @@ void _saveImageWeb( file.writeAsBytesSync(encodePng(newFile)); } -void createSplashCss({required String color, required String darkColor}) { +void createSplashCss( + {required String color, + required String darkColor, + required String? backgroundImage, + required String? darkBackgroundImage}) { print('[Web] Creating CSS'); if (darkColor.isEmpty) darkColor = color; var cssContent = _webCss .replaceFirst('[LIGHTBACKGROUNDCOLOR]', '#' + color) .replaceFirst('[DARKBACKGROUNDCOLOR]', '#' + darkColor); + + if (backgroundImage == null) { + cssContent = cssContent.replaceFirst('[LIGHTBACKGROUNDIMAGE]', ''); + } else { + cssContent = cssContent.replaceFirst('[LIGHTBACKGROUNDIMAGE]', + 'background-image: url("img/light-background.png");'); + } + + if (backgroundImage == null) { + cssContent = cssContent.replaceFirst('[DARKBACKGROUNDIMAGE]', ''); + } else { + cssContent = cssContent.replaceFirst('[DARKBACKGROUNDIMAGE]', + 'background-image: url("img/dark-background.png");'); + } + var file = File(_webFolder + _webRelativeStyleFile); file.createSync(recursive: true); file.writeAsStringSync(cssContent); diff --git a/pubspec.yaml b/pubspec.yaml index 261ecda..686abd3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_native_splash description: Generates native code to customize Flutter's default white native splash screen with background color and splash image. Supports dark mode, full screen, and more. -version: 1.2.3 +version: 1.2.4 homepage: https://github.com/jonbhanson/flutter_native_splash environment: @@ -8,10 +8,10 @@ environment: dependencies: args: ^2.2.0 - image: ^3.0.2 + image: ^3.0.5 meta: ^1.3.0 path: ^1.8.0 - xml: ^5.1.2 + xml: ^5.3.0 yaml: ^3.1.0 universal_io: ^2.0.4