diff --git a/CHANGELOG.md b/CHANGELOG.md index 6190c2a..7d983d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [1.2.2] - (2021-Sep-06) + +* Added a FAQ to address the deprecation of `SplashScreenDrawable`. Closes [#199](https://github.com/jonbhanson/flutter_native_splash/issues/199). +* Added `` tag to `index.html` by finding the `` tag instead of `src="main.dart.js`, which was removed in Flutter 2.5. Fixes [#202](https://github.com/jonbhanson/flutter_native_splash/issues/202). +* Added `false` tag to dark mode `styles.xml` to improve Xiaomi support. Closes [#184](https://github.com/jonbhanson/flutter_native_splash/issues/184). + ## [1.2.1] - (2021-Jul-19) * Check the file type and exit with error if it is not a PNG. * Updated documentation with more FAQs. diff --git a/README.md b/README.md index c122658..5acee89 100644 --- a/README.md +++ b/README.md @@ -17,15 +17,11 @@ First, add `flutter_native_splash` as a dev dependency in your pubspec.yaml file ```yaml dev_dependencies: - flutter_native_splash: ^1.2.1 + flutter_native_splash: ^1.2.2 ``` Don't forget to `flutter pub get`. -> #### NOTE: -> -> If you are using Flutter 1.x (no null safety), you must use the 0.x version of this package. - ## 1. Setting the splash screen Customized the following settings and add to your project's `pubspec.yaml` file or place in a new file in your root project folder named `flutter_native_splash.yaml`. @@ -140,6 +136,18 @@ At this time, the splash screen may jump when using `fullscreen` with Android 12 The native splash screen is displayed while the native app loads the Flutter framework. Once Flutter loads, there are probably still resources that need to be loaded before your app is ready. For this reason, you should consider implementing a secondary Flutter splash screen or placeholders that display while these resources load. The [example](https://github.com/jonbhanson/flutter_native_splash/blob/master/example/lib/main.dart) show an implimentation of a secondary splash screen. # FAQs +## I got the error "A splash screen was provided to Flutter, but this is deprecated." + +This message is not related to this package, but is related to a [change](https://flutter.dev/docs/development/ui/advanced/splash-screen#migrating-from-manifest--activity-defined-custom-splash-screens) in how Flutter handles splash screens in Flutter 2.5. It is caused by having the following code in your `AndroidManifest.xml`, which was included by default in previous versions of Flutter: + +```xml + +``` +The solution is to remove the above code. + ## Can I change the duration of the splash screen? The native splash screen is displayed while the native app loads the Flutter framework. Because the resources in your app cannot load while the native splash screen is displayed, the native splash screen must be as fast as possible. Note that delaying the user experience is a poor design decision. diff --git a/example/README.md b/example/README.md index e5f9c98..7451477 100644 --- a/example/README.md +++ b/example/README.md @@ -1,6 +1,6 @@ # Example for flutter_native_splash -A new Flutter application for testing a splash screen. +A new Flutter project for testing a splash screen. ## Getting Started diff --git a/example/analysis_options.yaml b/example/analysis_options.yaml new file mode 100644 index 0000000..61b6c4d --- /dev/null +++ b/example/analysis_options.yaml @@ -0,0 +1,29 @@ +# This file configures the analyzer, which statically analyzes Dart code to +# check for errors, warnings, and lints. +# +# The issues identified by the analyzer are surfaced in the UI of Dart-enabled +# IDEs (https://dart.dev/tools#ides-and-editors). The analyzer can also be +# invoked from the command line by running `flutter analyze`. + +# The following line activates a set of recommended lints for Flutter apps, +# packages, and plugins designed to encourage good coding practices. +include: package:flutter_lints/flutter.yaml + +linter: + # The lint rules applied to this project can be customized in the + # section below to disable rules from the `package:flutter_lints/flutter.yaml` + # included above or to enable additional rules. A list of all available lints + # and their documentation is published at + # https://dart-lang.github.io/linter/lints/index.html. + # + # Instead of disabling a lint rule for the entire project in the + # section below, it can also be suppressed for a single line of code + # or a specific dart file by using the `// ignore: name_of_lint` and + # `// ignore_for_file: name_of_lint` syntax on the line or in the file + # producing the lint. + rules: + # avoid_print: false # Uncomment to disable the `avoid_print` rule + # prefer_single_quotes: true # Uncomment to enable the `prefer_single_quotes` rule + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/example/android/.gitignore b/example/android/.gitignore index 0a741cb..6f56801 100644 --- a/example/android/.gitignore +++ b/example/android/.gitignore @@ -9,3 +9,5 @@ GeneratedPluginRegistrant.java # Remember to never publicly share your keystore. # See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app key.properties +**/*.keystore +**/*.jks diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 7fa85db..a845493 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -27,6 +27,11 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion 30 + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.example" diff --git a/example/android/app/src/main/AndroidManifest.xml b/example/android/app/src/main/AndroidManifest.xml index 34dd77e..6f325b4 100644 --- a/example/android/app/src/main/AndroidManifest.xml +++ b/example/android/app/src/main/AndroidManifest.xml @@ -18,15 +18,6 @@ android:name="io.flutter.embedding.android.NormalTheme" android:resource="@style/NormalTheme" /> - - diff --git a/example/android/app/src/main/java/com/example/example/MainActivity.java b/example/android/app/src/main/java/com/example/example/MainActivity.java index 194399b..59f336d 100644 --- a/example/android/app/src/main/java/com/example/example/MainActivity.java +++ b/example/android/app/src/main/java/com/example/example/MainActivity.java @@ -1,105 +1,6 @@ package com.example.example; -import android.animation.Animator; -import android.content.Context; -import android.content.pm.PackageManager; -import android.graphics.drawable.Drawable; -import android.os.Build; -import android.os.Bundle; -import android.view.View; -import android.widget.ImageView; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import io.flutter.embedding.android.FlutterActivity; -import io.flutter.embedding.android.SplashScreen; public class MainActivity extends FlutterActivity { - - // By default, Flutter makes a 1/2 second fade between the native splash screen - // and the first Flutter frame. However, loading an image for a secondary splash - // screen takes a moment, causing a flash that can be observed in spite of the fade. - // To prevent this, a CustomSplashScreen is used that keeps the splash screen - // visible over the Flutter app 1/2 second to conceal the flash from the image loading. - // To restore the Flutter default behavior, remove the contents of MainActivity and - // the CustomSplashScreen class. - - @Nullable - @Override - public SplashScreen provideSplashScreen() { - Drawable manifestSplashDrawable = getSplashScreenFromManifest(); - if (manifestSplashDrawable != null) { - return new CustomSplashScreen(manifestSplashDrawable); - } else { - return null; - } - } - - /* package */ static final String SPLASH_SCREEN_META_DATA_KEY = - "io.flutter.embedding.android.SplashScreenDrawable"; - - @Nullable - private Drawable getSplashScreenFromManifest() { - try { - Bundle metaData = getMetaData(); - int splashScreenId = metaData != null ? metaData.getInt(SPLASH_SCREEN_META_DATA_KEY) : 0; - return splashScreenId != 0 - ? Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP - ? getResources().getDrawable(splashScreenId, getTheme()) - : getResources().getDrawable(splashScreenId) - : null; - } catch (PackageManager.NameNotFoundException e) { - // This is never expected to happen. - return null; - } - } -} - -class CustomSplashScreen implements SplashScreen { - private final Drawable drawable; - private io.flutter.embedding.android.DrawableSplashScreen.DrawableSplashScreenView splashView; - - public CustomSplashScreen(@NonNull Drawable drawable) { - this.drawable = drawable; - } - - @Nullable - @Override - public View createSplashView(@NonNull Context context, @Nullable Bundle savedInstanceState) { - splashView = new io.flutter.embedding.android.DrawableSplashScreen.DrawableSplashScreenView(context); - splashView.setSplashDrawable(drawable, ImageView.ScaleType.FIT_XY); - return splashView; - } - - @Override - public void transitionToFlutter(@NonNull Runnable onTransitionComplete) { - if (splashView == null) { - onTransitionComplete.run(); - return; - } - - splashView - .animate() - .alpha(1.0f) - .setDuration(500) - .setListener( - new Animator.AnimatorListener() { - @Override - public void onAnimationStart(Animator animation) {} - - @Override - public void onAnimationEnd(Animator animation) { - onTransitionComplete.run(); - } - - @Override - public void onAnimationCancel(Animator animation) { - onTransitionComplete.run(); - } - - @Override - public void onAnimationRepeat(Animator animation) {} - }); - } } diff --git a/example/android/build.gradle b/example/android/build.gradle index fab3c2e..622ddc5 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -1,26 +1,24 @@ buildscript { repositories { google() - jcenter() + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:4.1.3' + classpath 'com.android.tools.build:gradle:4.1.0' } } allprojects { repositories { google() - jcenter() + mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" -} -subprojects { project.evaluationDependsOn(':app') } diff --git a/example/assets/1.5x/splash_dark.png b/example/assets/1.5x/splash_dark.png new file mode 100644 index 0000000..ba6d9ed Binary files /dev/null and b/example/assets/1.5x/splash_dark.png differ diff --git a/example/assets/2.0x/splash_dark.png b/example/assets/2.0x/splash_dark.png new file mode 100644 index 0000000..350f6d4 Binary files /dev/null and b/example/assets/2.0x/splash_dark.png differ diff --git a/example/assets/3.0x/splash_dark.png b/example/assets/3.0x/splash_dark.png new file mode 100644 index 0000000..bebe14e Binary files /dev/null and b/example/assets/3.0x/splash_dark.png differ diff --git a/example/assets/4.0x/splash_dark.png b/example/assets/4.0x/splash_dark.png new file mode 100644 index 0000000..95eb328 Binary files /dev/null and b/example/assets/4.0x/splash_dark.png differ diff --git a/example/assets/splash_dark.png b/example/assets/splash_dark.png new file mode 100644 index 0000000..ce932e9 Binary files /dev/null and b/example/assets/splash_dark.png differ diff --git a/example/ios/.gitignore b/example/ios/.gitignore index e96ef60..151026b 100644 --- a/example/ios/.gitignore +++ b/example/ios/.gitignore @@ -18,6 +18,7 @@ Flutter/App.framework Flutter/Flutter.framework Flutter/Flutter.podspec Flutter/Generated.xcconfig +Flutter/ephemeral/ Flutter/app.flx Flutter/app.zip Flutter/flutter_assets/ diff --git a/example/ios/Flutter/AppFrameworkInfo.plist b/example/ios/Flutter/AppFrameworkInfo.plist index 9367d48..8d4492f 100644 --- a/example/ios/Flutter/AppFrameworkInfo.plist +++ b/example/ios/Flutter/AppFrameworkInfo.plist @@ -21,6 +21,6 @@ CFBundleVersion 1.0 MinimumOSVersion - 8.0 + 9.0 diff --git a/example/ios/Runner.xcodeproj/project.pbxproj b/example/ios/Runner.xcodeproj/project.pbxproj index fd88861..656cd04 100644 --- a/example/ios/Runner.xcodeproj/project.pbxproj +++ b/example/ios/Runner.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 50; objects = { /* Begin PBXBuildFile section */ @@ -74,7 +74,6 @@ 9740EEB11CF90186004384FC /* Flutter */, 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, - CF3B75C9A7D2FA2A4C99F110 /* Frameworks */, ); sourceTree = ""; }; @@ -139,7 +138,7 @@ 97C146E61CF9000F007C117D /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 1020; + LastUpgradeCheck = 1300; ORGANIZATIONNAME = ""; TargetAttributes = { 97C146ED1CF9000F007C117D = { @@ -301,7 +300,10 @@ CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = com.example.example; PRODUCT_NAME = "$(TARGET_NAME)"; VERSIONING_SYSTEM = "apple-generic"; @@ -421,7 +423,10 @@ CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = com.example.example; PRODUCT_NAME = "$(TARGET_NAME)"; VERSIONING_SYSTEM = "apple-generic"; @@ -436,7 +441,10 @@ CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)"; ENABLE_BITCODE = NO; INFOPLIST_FILE = Runner/Info.plist; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); PRODUCT_BUNDLE_IDENTIFIER = com.example.example; PRODUCT_NAME = "$(TARGET_NAME)"; VERSIONING_SYSTEM = "apple-generic"; diff --git a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme index a28140c..c87d15a 100644 --- a/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme +++ b/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme @@ -1,6 +1,6 @@ - - - - + + - - _MyHomePageState(); + State createState() => _MyHomePageState(); } class _MyHomePageState extends State { @@ -109,7 +110,7 @@ class _MyHomePageState extends State { // horizontal). mainAxisAlignment: MainAxisAlignment.center, children: [ - Text( + const Text( 'You have pushed the button this many times:', ), Text( @@ -122,7 +123,7 @@ class _MyHomePageState extends State { floatingActionButton: FloatingActionButton( onPressed: _incrementCounter, tooltip: 'Increment', - child: Icon(Icons.add), + child: const Icon(Icons.add), ), // This trailing comma makes auto-formatting nicer for build methods. ); } @@ -131,9 +132,16 @@ class _MyHomePageState extends State { class Splash extends StatelessWidget { @override Widget build(BuildContext context) { + bool lightMode = + MediaQuery.of(context).platformBrightness == Brightness.light; return Scaffold( - backgroundColor: Color(0xe1f5fe).withOpacity(1.0), - body: Center(child: Image.asset('assets/splash.png')), + backgroundColor: lightMode + ? Color(0xe1f5fe).withOpacity(1.0) + : Color(0x042a49).withOpacity(1.0), + body: Center( + child: lightMode + ? Image.asset('assets/splash.png') + : Image.asset('assets/splash_dark.png')), ); } } @@ -146,6 +154,6 @@ class Init { // This is where you can initialize the resources needed by your app while // the splash screen is displayed. Remove the following example because // delaying the user experience is a bad design practice! - await Future.delayed(Duration(seconds: 3)); + await Future.delayed(const Duration(seconds: 3)); } } diff --git a/example/pubspec.lock b/example/pubspec.lock index d0b47cd..e8520bf 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -21,7 +21,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.6.1" + version: "2.8.2" boolean_selector: dependency: transitive description: @@ -42,7 +42,7 @@ packages: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.1" clock: dependency: transitive description: @@ -63,7 +63,7 @@ packages: name: crypto url: "https://pub.dartlang.org" source: hosted - version: "3.0.0" + version: "3.0.1" cupertino_icons: dependency: "direct main" description: @@ -83,13 +83,20 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" flutter_native_splash: dependency: "direct dev" description: path: ".." relative: true source: path - version: "1.2.1" + version: "1.2.2" flutter_test: dependency: "direct dev" description: flutter @@ -102,20 +109,27 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "3.0.2" + lints: + dependency: transitive + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" matcher: dependency: transitive description: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10" + version: "0.12.11" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0" + version: "1.7.0" path: dependency: transitive description: @@ -129,7 +143,7 @@ packages: name: petitparser url: "https://pub.dartlang.org" source: hosted - version: "4.1.0" + version: "4.2.0" sky_engine: dependency: transitive description: flutter @@ -176,7 +190,7 @@ packages: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.3.0" + version: "0.4.3" typed_data: dependency: transitive description: @@ -204,7 +218,7 @@ packages: name: xml url: "https://pub.dartlang.org" source: hosted - version: "5.1.2" + version: "5.2.0" yaml: dependency: transitive description: @@ -213,4 +227,4 @@ packages: source: hosted version: "3.1.0" sdks: - dart: ">=2.12.0 <3.0.0" + dart: ">=2.13.0 <3.0.0" diff --git a/example/pubspec.yaml b/example/pubspec.yaml index eeaf4fb..deadba8 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,8 +1,8 @@ name: example -description: A new Flutter application. +description: A new Flutter project. # The following line prevents the package from being accidentally published to -# pub.dev using `pub publish`. This is preferred for private packages. +# pub.dev using `flutter pub publish`. This is preferred for private packages. publish_to: 'none' # Remove this line if you wish to publish to pub.dev # The following defines the version and build number for your application. @@ -18,8 +18,14 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev version: 1.0.0+1 environment: - sdk: '>=2.12.0-0 <3.0.0' - + sdk: ">=2.12.0 <3.0.0" + +# Dependencies specify other packages that your package needs in order to work. +# To automatically upgrade your package dependencies to the latest versions +# consider running `flutter pub upgrade --major-versions`. Alternatively, +# dependencies can be manually updated by changing the version numbers below to +# the latest version available on pub.dev. To see which dependencies have newer +# versions available, run `flutter pub outdated`. dependencies: flutter: sdk: flutter @@ -35,6 +41,13 @@ dev_dependencies: flutter_native_splash: path: .. + # The "flutter_lints" package below contains a set of recommended lints to + # encourage good coding practices. The lint set provided by the package is + # activated in the `analysis_options.yaml` file located at the root of your + # package. See that file for information about deactivating specific lint + # rules and activating additional ones. + flutter_lints: ^1.0.4 + # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec diff --git a/example/test/widget_test.dart b/example/test/widget_test.dart index 747db1d..a19dabb 100644 --- a/example/test/widget_test.dart +++ b/example/test/widget_test.dart @@ -13,7 +13,7 @@ import 'package:example/main.dart'; void main() { testWidgets('Counter increments smoke test', (WidgetTester tester) async { // Build our app and trigger a frame. - await tester.pumpWidget(MyApp()); + await tester.pumpWidget(const MyApp()); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); diff --git a/example/web/icons/Icon-maskable-192.png b/example/web/icons/Icon-maskable-192.png new file mode 100644 index 0000000..eb9b4d7 Binary files /dev/null and b/example/web/icons/Icon-maskable-192.png differ diff --git a/example/web/icons/Icon-maskable-512.png b/example/web/icons/Icon-maskable-512.png new file mode 100644 index 0000000..d69c566 Binary files /dev/null and b/example/web/icons/Icon-maskable-512.png differ diff --git a/example/web/index.html b/example/web/index.html index aaeb180..b6b9dd2 100644 --- a/example/web/index.html +++ b/example/web/index.html @@ -8,14 +8,17 @@ The path provided below has to start and end with a slash "/" in order for it to work correctly. - Fore more details: + For more details: * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base + + This is a placeholder for base href that will be replaced by the value of + the `--base-href` argument provided to `flutter build`. --> - + - + @@ -34,12 +37,68 @@ application. For more information, see: https://developers.google.com/web/fundamentals/primers/service-workers --> - diff --git a/example/web/manifest.json b/example/web/manifest.json index 3911621..096edf8 100644 --- a/example/web/manifest.json +++ b/example/web/manifest.json @@ -5,7 +5,7 @@ "display": "standalone", "background_color": "#0175C2", "theme_color": "#0175C2", - "description": "A new Flutter application.", + "description": "A new Flutter project.", "orientation": "portrait-primary", "prefer_related_applications": false, "icons": [ @@ -18,6 +18,18 @@ "src": "icons/Icon-512.png", "sizes": "512x512", "type": "image/png" + }, + { + "src": "icons/Icon-maskable-192.png", + "sizes": "192x192", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "icons/Icon-maskable-512.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" } ] } diff --git a/lib/android.dart b/lib/android.dart index c06b374..7f72ec5 100644 --- a/lib/android.dart +++ b/lib/android.dart @@ -35,27 +35,27 @@ final List<_AndroidDrawableTemplate> androidSplashImagesDark = /// Create Android splash screen void _createAndroidSplash({ - required String imagePath, - required String darkImagePath, + required String? imagePath, + required String? darkImagePath, required String color, required String darkColor, required String gravity, required bool fullscreen, - required String backgroundImage, - required String darkBackgroundImage, + required String? backgroundImage, + required String? darkBackgroundImage, required bool android12, }) { - if (imagePath.isNotEmpty) { + if (imagePath != null) { _applyImageAndroid(imagePath: imagePath); } - if (darkImagePath.isNotEmpty) { + if (darkImagePath != null) { _applyImageAndroid(imagePath: darkImagePath, dark: true); } _applyLaunchBackgroundXml( gravity: gravity, launchBackgroundFilePath: _androidLaunchBackgroundFile, - showImage: imagePath.isNotEmpty, + showImage: imagePath != null, ); _createBackground( @@ -82,7 +82,7 @@ void _createAndroidSplash({ _applyLaunchBackgroundXml( gravity: gravity, launchBackgroundFilePath: _androidLaunchDarkBackgroundFile, - showImage: imagePath.isNotEmpty, + showImage: imagePath != null, ); } @@ -90,13 +90,13 @@ void _createAndroidSplash({ _applyLaunchBackgroundXml( gravity: gravity, launchBackgroundFilePath: _androidV21LaunchBackgroundFile, - showImage: imagePath.isNotEmpty, + showImage: imagePath != null, ); if (darkColor.isNotEmpty) { _applyLaunchBackgroundXml( gravity: gravity, launchBackgroundFilePath: _androidV21LaunchDarkBackgroundFile, - showImage: imagePath.isNotEmpty, + showImage: imagePath != null, ); } } diff --git a/lib/flutter_native_splash.dart b/lib/flutter_native_splash.dart index 94f38c0..ae63fa3 100644 --- a/lib/flutter_native_splash.dart +++ b/lib/flutter_native_splash.dart @@ -115,7 +115,7 @@ void removeSplash({String? path}) { createSplashByConfig(removeConfig); } -String checkImageExists( +String? checkImageExists( {required Map config, required String parameter}) { String image = config[parameter] ?? ''; if (image.isNotEmpty && !File(image).existsSync()) { @@ -129,7 +129,7 @@ String checkImageExists( ' Your image must be a PNG file.'); exit(1); } - return image; + return image == '' ? null : image; } /// Get config from `pubspec.yaml` or `flutter_native_splash.yaml` diff --git a/lib/ios.dart b/lib/ios.dart index 568d90b..5e8fea3 100644 --- a/lib/ios.dart +++ b/lib/ios.dart @@ -26,17 +26,17 @@ final List<_IosLaunchImageTemplate> iOSSplashImagesDark = /// Create iOS splash screen void _createiOSSplash({ - required String imagePath, - required String darkImagePath, + required String? imagePath, + required String? darkImagePath, required String color, required String darkColor, List? plistFiles, required String iosContentMode, required bool fullscreen, - required String backgroundImage, - required String darkBackgroundImage, + required String? backgroundImage, + required String? darkBackgroundImage, }) { - if (imagePath.isNotEmpty) { + if (imagePath != null) { _applyImageiOS(imagePath: imagePath); } else { final splashImage = Image(1, 1); @@ -47,7 +47,7 @@ void _createiOSSplash({ }); } - if (darkImagePath.isNotEmpty) { + if (darkImagePath != null) { _applyImageiOS(imagePath: darkImagePath, dark: true); } else { iOSSplashImagesDark.forEach((template) { @@ -59,7 +59,7 @@ void _createiOSSplash({ var launchImageFile = File(_iOSAssetsLaunchImageFolder + 'Contents.json'); launchImageFile.createSync(recursive: true); launchImageFile.writeAsStringSync( - darkImagePath.isNotEmpty ? _iOSContentsJsonDark : _iOSContentsJson); + darkImagePath != null ? _iOSContentsJsonDark : _iOSContentsJson); _applyLaunchScreenStoryboard( imagePath: imagePath, iosContentMode: iosContentMode); @@ -116,7 +116,7 @@ void _saveImageiOS( /// Update LaunchScreen.storyboard adding width, height and color void _applyLaunchScreenStoryboard( - {required String imagePath, required String iosContentMode}) { + {required String? imagePath, required String iosContentMode}) { final file = File(_iOSLaunchScreenStoryboardFile); if (file.existsSync()) { @@ -134,7 +134,7 @@ void _applyLaunchScreenStoryboard( /// Updates LaunchScreen.storyboard adding splash image path void _updateLaunchScreenStoryboard( - {required String imagePath, required String iosContentMode}) { + {required String? imagePath, required String iosContentMode}) { // Load the data final file = File(_iOSLaunchScreenStoryboardFile); final xmlDocument = XmlDocument.parse(file.readAsStringSync()); @@ -207,7 +207,7 @@ void _updateLaunchScreenStoryboard( view.children.add( XmlDocument.parse(_iOSLaunchBackgroundConstraints).rootElement.copy()); - if (imagePath.isNotEmpty) { + if (imagePath != null) { final image = decodeImage(File(imagePath).readAsBytesSync()); if (image == null) { print(imagePath + ' could not be loaded.'); @@ -222,7 +222,7 @@ void _updateLaunchScreenStoryboard( /// Creates LaunchScreen.storyboard with splash image path void _createLaunchScreenStoryboard( - {required String imagePath, required String iosContentMode}) { + {required String? imagePath, required String iosContentMode}) { var file = File(_iOSLaunchScreenStoryboardFile); file.createSync(recursive: true); file.writeAsStringSync(_iOSLaunchScreenStoryboardContent); @@ -233,8 +233,8 @@ void _createLaunchScreenStoryboard( void _createBackground({ required String colorString, required String darkColorString, - required String backgroundImageSource, - required String darkBackgroundImageSource, + required String? backgroundImageSource, + required String? darkBackgroundImageSource, required String backgroundImageDestination, required String darkBackgroundImageDestination, }) { @@ -248,7 +248,7 @@ void _createBackground({ var file = File(backgroundImageDestination); file.createSync(recursive: true); file.writeAsBytesSync(encodePng(background)); - } else if (backgroundImageSource.isNotEmpty) { + } else if (backgroundImageSource != null) { // Copy will not work if the directory does not exist, so createSync // will ensure that the directory exists. File(backgroundImageDestination).createSync(recursive: true); @@ -267,7 +267,7 @@ void _createBackground({ var file = File(darkBackgroundImageDestination); file.createSync(recursive: true); file.writeAsBytesSync(encodePng(background)); - } else if (darkBackgroundImageSource.isNotEmpty) { + } else if (darkBackgroundImageSource != null) { // Copy will not work if the directory does not exist, so createSync // will ensure that the directory exists. File(darkBackgroundImageDestination).createSync(recursive: true); diff --git a/lib/templates.dart b/lib/templates.dart index 696a1d0..62fa8f9 100644 --- a/lib/templates.dart +++ b/lib/templates.dart @@ -46,6 +46,7 @@ const String _androidStylesNightXml = ''' @drawable/launch_background + false