diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..d66387d --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,26 @@ +name: flutter_native_splash + +on: + pull_request: + paths-ignore: + - '**.md' + push: + branches: + - master + paths-ignore: + - '**.md' + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: subosito/flutter-action@v2 + - name: Install Dependencies + run: flutter packages get + - name: Format + run: flutter format . --set-exit-if-changed + - name: Analyze + run: flutter analyze . + - name: Test + run: flutter test --test-randomize-ordering-seed random \ No newline at end of file diff --git a/lib/cli_commands.dart b/lib/cli_commands.dart index c7d246a..fac98bf 100644 --- a/lib/cli_commands.dart +++ b/lib/cli_commands.dart @@ -21,24 +21,23 @@ part 'web.dart'; late _FlavorHelper _flavorHelper; /// Create splash screens for Android and iOS -void createSplash({String? path, String? flavor}) { +void createSplash({ + required String? path, + required String? flavor, +}) { if (flavor != null) { print( ''' ╔════════════════════════════════════════════════════════════════════════════╗ ║ Flavor detected! ║ ╠════════════════════════════════════════════════════════════════════════════╣ -║ Setting up the $flavor flavor. +║ Setting up the $flavor flavor. ║ ╚════════════════════════════════════════════════════════════════════════════╝ ''', ); } - // It is important that the flavor setup occurs as soon as possible. - // So before we generate anything, we need to setup the flavor (even if it's the default one). - _flavorHelper = _FlavorHelper(flavor); - - final config = getConfig(configFile: path); + final config = getConfig(configFile: path, flavor: flavor); createSplashByConfig(config); } @@ -205,14 +204,14 @@ void createSplashByConfig(Map config) { } } - const String _greet = ''' + const String greet = ''' ✅ Native splash complete. Now go finish building something awesome! 💪 You rock! 🤘🤩 Like the package? Please give it a 👍 here: https://pub.dev/packages/flutter_native_splash '''; - const String _whatsNew = ''' + const String whatsNew = ''' ╔════════════════════════════════════════════════════════════════════════════╗ ║ WHAT IS NEW: ║ ╠════════════════════════════════════════════════════════════════════════════╣ @@ -222,14 +221,16 @@ Like the package? Please give it a 👍 here: https://pub.dev/packages/flutter_n ║ Check the docs for more info. ║ ╚════════════════════════════════════════════════════════════════════════════╝ '''; - print(_whatsNew + _greet); + print(whatsNew + greet); } /// Remove any splash screen by setting the default white splash -void removeSplash({String? path, String? flavor}) { - _flavorHelper = _FlavorHelper(flavor); +void removeSplash({ + required String? path, + required String? flavor, +}) { print("Restoring Flutter's default native splash screen..."); - final config = getConfig(configFile: path); + final config = getConfig(configFile: path, flavor: flavor); final removeConfig = { 'color': '#ffffff', @@ -281,7 +282,13 @@ String? _checkImageExists({ } /// Get config from `pubspec.yaml` or `flutter_native_splash.yaml` -Map getConfig({String? configFile}) { +Map getConfig({ + required String? configFile, + required String? flavor, +}) { + // It is important that the flavor setup occurs as soon as possible. + // So before we generate anything, we need to setup the flavor (even if it's the default one). + _flavorHelper = _FlavorHelper(flavor); // if `flutter_native_splash.yaml` exists use it as config file, otherwise use `pubspec.yaml` String filePath; if (configFile != null) { diff --git a/lib/ios.dart b/lib/ios.dart index 65ae291..157d157 100644 --- a/lib/ios.dart +++ b/lib/ios.dart @@ -18,7 +18,7 @@ final List<_IosLaunchImageTemplate> _iOSSplashImages = ), // original image must be @4x ]; -final List<_IosLaunchImageTemplate> iOSSplashImagesDark = +final List<_IosLaunchImageTemplate> _iOSSplashImagesDark = <_IosLaunchImageTemplate>[ _IosLaunchImageTemplate(fileName: 'LaunchImageDark.png', pixelDensity: 1), _IosLaunchImageTemplate(fileName: 'LaunchImageDark@2x.png', pixelDensity: 2), @@ -36,7 +36,7 @@ final List<_IosLaunchImageTemplate> _iOSBrandingImages = pixelDensity: 3, ), // original image must be @4x ]; -final List<_IosLaunchImageTemplate> iOSBrandingImagesDark = +final List<_IosLaunchImageTemplate> _iOSBrandingImagesDark = <_IosLaunchImageTemplate>[ _IosLaunchImageTemplate(fileName: 'BrandingImageDark.png', pixelDensity: 1), _IosLaunchImageTemplate( @@ -81,10 +81,10 @@ void _createiOSSplash({ _applyImageiOS( imagePath: darkImagePath, dark: true, - list: iOSSplashImagesDark, + list: _iOSSplashImagesDark, ); } else { - for (final template in iOSSplashImagesDark) { + for (final template in _iOSSplashImagesDark) { final file = File(_flavorHelper.iOSAssetsLaunchImageFolder + template.fileName); if (file.existsSync()) file.deleteSync(); @@ -107,11 +107,11 @@ void _createiOSSplash({ _applyImageiOS( imagePath: brandingDarkImagePath, dark: true, - list: iOSBrandingImagesDark, + list: _iOSBrandingImagesDark, targetPath: _flavorHelper.iOSAssetsBrandingImageFolder, ); } else { - for (final template in iOSBrandingImagesDark) { + for (final template in _iOSBrandingImagesDark) { final file = File(_flavorHelper.iOSAssetsBrandingImageFolder + template.fileName); if (file.existsSync()) file.deleteSync(); diff --git a/lib/web.dart b/lib/web.dart index be4da69..3daffc2 100644 --- a/lib/web.dart +++ b/lib/web.dart @@ -26,7 +26,7 @@ void _createWebSplash({ } darkImagePath ??= imagePath; - createWebImages( + _createWebImages( imagePath: imagePath, webSplashImages: [ _WebLaunchImageTemplate(fileName: 'light-1x.png', pixelDensity: 1), @@ -35,7 +35,7 @@ void _createWebSplash({ _WebLaunchImageTemplate(fileName: 'light-4x.png', pixelDensity: 4), ], ); - createWebImages( + _createWebImages( imagePath: darkImagePath, webSplashImages: [ _WebLaunchImageTemplate(fileName: 'dark-1x.png', pixelDensity: 1), @@ -46,7 +46,7 @@ void _createWebSplash({ ); brandingDarkImagePath ??= brandingImagePath; - createWebImages( + _createWebImages( imagePath: brandingImagePath, webSplashImages: [ _WebLaunchImageTemplate(fileName: 'branding-1x.png', pixelDensity: 1), @@ -55,7 +55,7 @@ void _createWebSplash({ _WebLaunchImageTemplate(fileName: 'branding-4x.png', pixelDensity: 4), ], ); - createWebImages( + _createWebImages( imagePath: brandingDarkImagePath, webSplashImages: [ _WebLaunchImageTemplate( @@ -124,7 +124,7 @@ void createBackgroundImages({ } } -void createWebImages({ +void _createWebImages({ required String? imagePath, required List<_WebLaunchImageTemplate> webSplashImages, }) { diff --git a/test/flutter_native_splash_test.dart b/test/flutter_native_splash_test.dart index ac6a87c..2cc5afd 100644 --- a/test/flutter_native_splash_test.dart +++ b/test/flutter_native_splash_test.dart @@ -17,19 +17,12 @@ void main() { final testDir = p.join('.dart_tool', 'flutter_native_splash', 'test', 'config_file'); - late String currentDirectory; void setCurrentDirectory(String path) { final pathValue = p.join(testDir, path); - Directory(path).createSync(recursive: true); + Directory(pathValue).createSync(recursive: true); Directory.current = pathValue; } - setUp(() { - currentDirectory = Directory.current.path; - }); - tearDown(() { - Directory.current = currentDirectory; - }); test('default', () { setCurrentDirectory('default'); File('flutter_native_splash.yaml').writeAsStringSync( @@ -40,6 +33,7 @@ flutter_native_splash: ); final Map config = getConfig( configFile: 'flutter_native_splash.yaml', + flavor: null, ); File('flutter_native_splash.yaml').deleteSync(); expect(config, isNotNull); @@ -53,13 +47,16 @@ flutter_native_splash: color: "#00ff00" ''', ); - final Map config = getConfig(); + final Map config = getConfig( + configFile: null, + flavor: null, + ); File('pubspec.yaml').deleteSync(); expect(config, isNotNull); expect(config['color'], '#00ff00'); // fails if config file is missing - expect(() => getConfig(), throwsException); + expect(() => getConfig(configFile: null, flavor: null), throwsException); }); }); }