Skip to content

Commit

Permalink
Don't create Android 12 night res files if dark mode is not configured.
Browse files Browse the repository at this point in the history
Fixes #227.  Remove command takes dark mode into account.
  • Loading branch information
jonbhanson committed Oct 27, 2021
1 parent d73462a commit 6f074a7
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 32 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [1.3.1] - (2021-Oct-27)
* Don't create Android 12 night res files if dark mode is not configured. Fixes [#227](https://github.com/jonbhanson/flutter_native_splash/issues/227). `Remove` command takes dark mode into account.

## [1.3.0] - (2021-Oct-26)
* Added Android 12 support. Closes [#204](https://github.com/jonbhanson/flutter_native_splash/issues/204), closes [#226](https://github.com/jonbhanson/flutter_native_splash/issues/226).

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.0
flutter_native_splash: ^1.3.1
```

Don't forget to `flutter pub get`.
Expand Down
33 changes: 19 additions & 14 deletions lib/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ final List<_AndroidDrawableTemplate> androidSplashImagesDark =
void _createAndroidSplash({
required String? imagePath,
required String? darkImagePath,
required String color,
required String darkColor,
required String? color,
required String? darkColor,
required String gravity,
required bool fullscreen,
required String? backgroundImage,
Expand Down Expand Up @@ -79,7 +79,7 @@ void _createAndroidSplash({
showImage: imagePath != null,
);

if (darkColor.isNotEmpty) {
if (darkColor != null || darkBackgroundImage != null) {
_applyLaunchBackgroundXml(
gravity: gravity,
launchBackgroundFilePath: _androidLaunchDarkBackgroundFile,
Expand All @@ -93,7 +93,7 @@ void _createAndroidSplash({
launchBackgroundFilePath: _androidV21LaunchBackgroundFile,
showImage: imagePath != null,
);
if (darkColor.isNotEmpty) {
if (darkColor != null || darkBackgroundImage != null) {
_applyLaunchBackgroundXml(
gravity: gravity,
launchBackgroundFilePath: _androidV21LaunchDarkBackgroundFile,
Expand All @@ -110,11 +110,13 @@ void _createAndroidSplash({
file: _androidV31StylesFile,
template: _androidV31StylesXml,
android12BackgroundColor: color);
_applyStylesXml(
fullScreen: fullscreen,
file: _androidV31StylesNightFile,
template: _androidV31StylesNightXml,
android12BackgroundColor: darkColor);
if (darkColor != null) {
_applyStylesXml(
fullScreen: fullscreen,
file: _androidV31StylesNightFile,
template: _androidV31StylesNightXml,
android12BackgroundColor: darkColor);
}
} else {
var file = File(_androidV31StylesFile);
if (file.existsSync()) file.deleteSync();
Expand All @@ -127,11 +129,14 @@ void _createAndroidSplash({
file: _androidStylesFile,
template: _androidStylesXml,
android12BackgroundColor: null);
_applyStylesXml(
fullScreen: fullscreen,
file: _androidNightStylesFile,
template: _androidStylesNightXml,
android12BackgroundColor: null);

if (darkColor != null || darkBackgroundImage != null) {
_applyStylesXml(
fullScreen: fullscreen,
file: _androidNightStylesFile,
template: _androidStylesNightXml,
android12BackgroundColor: null);
}
}

/// Create splash screen as drawables for multiple screens (dpi)
Expand Down
11 changes: 7 additions & 4 deletions lib/flutter_native_splash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ void createSplashByConfig(Map<String, dynamic> config) {

/// Remove any splash screen by setting the default white splash
void removeSplash({String? path}) {
print('Restoring Flutter\'s default white native splash screen...');
print('Restoring Flutter\'s default native splash screen...');
var config = getConfig(configFile: path);

var removeConfig = <String, dynamic>{'color': '#ffffff'};
var removeConfig = <String, dynamic>{
'color': '#ffffff',
'color_dark': '#000000'
};
if (config.containsKey('android')) {
removeConfig['android'] = config['android'];
}
Expand Down Expand Up @@ -203,14 +206,14 @@ void checkConfig(Map<String, dynamic> config) {
}

@visibleForTesting
String parseColor(var color) {
String? parseColor(var color) {
if (color is int) color = color.toString().padLeft(6, '0');

if (color is String) {
color = color.replaceAll('#', '').replaceAll(' ', '');
if (color.length == 6) return color;
}
if (color == null) return '';
if (color == null) return null;

throw Exception('Invalid color value');
}
14 changes: 7 additions & 7 deletions lib/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ final List<_IosLaunchImageTemplate> iOSSplashImagesDark =
void _createiOSSplash({
required String? imagePath,
required String? darkImagePath,
required String color,
required String darkColor,
required String? color,
required String? darkColor,
List<String>? plistFiles,
required String iosContentMode,
required bool fullscreen,
Expand Down Expand Up @@ -78,7 +78,7 @@ void _createiOSSplash({
File(_iOSAssetsLaunchImageBackgroundFolder + 'Contents.json');
backgroundImageFile.createSync(recursive: true);

backgroundImageFile.writeAsStringSync(darkColor.isNotEmpty
backgroundImageFile.writeAsStringSync(darkColor != null
? _iOSLaunchBackgroundDarkJson
: _iOSLaunchBackgroundJson);

Expand Down Expand Up @@ -231,14 +231,14 @@ void _createLaunchScreenStoryboard(
}

void _createBackground({
required String colorString,
required String darkColorString,
required String? colorString,
required String? darkColorString,
required String? backgroundImageSource,
required String? darkBackgroundImageSource,
required String backgroundImageDestination,
required String darkBackgroundImageDestination,
}) {
if (colorString.isNotEmpty) {
if (colorString != null) {
var background = Image(1, 1);
var redChannel = int.parse(colorString.substring(0, 2), radix: 16);
var greenChannel = int.parse(colorString.substring(2, 4), radix: 16);
Expand All @@ -257,7 +257,7 @@ void _createBackground({
throw Exception('No color string or background image!');
}

if (darkColorString.isNotEmpty) {
if (darkColorString != null) {
var background = Image(1, 1);
var redChannel = int.parse(darkColorString.substring(0, 2), radix: 16);
var greenChannel = int.parse(darkColorString.substring(2, 4), radix: 16);
Expand Down
11 changes: 6 additions & 5 deletions lib/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class _WebLaunchImageTemplate {
void _createWebSplash({
required String? imagePath,
required String? darkImagePath,
required String color,
required String darkColor,
required String? color,
required String? darkColor,
required String imageMode,
required String? backgroundImage,
required String? darkBackgroundImage,
Expand Down Expand Up @@ -110,12 +110,13 @@ void _saveImageWeb(
}

void createSplashCss(
{required String color,
required String darkColor,
{required String? color,
required String? darkColor,
required String? backgroundImage,
required String? darkBackgroundImage}) {
print('[Web] Creating CSS');
if (darkColor.isEmpty) darkColor = color;
color ??= '000000';
darkColor ??= color;
var cssContent = _webCss
.replaceFirst('[LIGHTBACKGROUNDCOLOR]', '#' + color)
.replaceFirst('[DARKBACKGROUNDCOLOR]', '#' + darkColor);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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: 1.3.0
version: 1.3.1
homepage: https://github.com/jonbhanson/flutter_native_splash

environment:
Expand Down

0 comments on commit 6f074a7

Please sign in to comment.