Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions lib/cli_commands.dart
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,20 @@ String? _checkImageExists({
exit(1);
}

if (p.extension(image).toLowerCase() != '.png') {
// https://github.com/brendan-duncan/image#supported-image-formats
final List<String> supportedFormats = [
"png", "apng", // PNG
"jpg", "jpeg", "jpe", "jfif", // JPEG
"tga", "tpic", // TGA
"gif", // GIF
"ico", // ICO
"bmp", "dib", // BMP
];

if (!supportedFormats
.any((format) => p.extension(image).toLowerCase() == ".$format")) {
print(
'Unsupported file format: $image Your image must be a PNG file.',
'Unsupported file format: $image Your image must be in one of the following formats: $supportedFormats',
);
exit(1);
}
Expand All @@ -295,6 +306,29 @@ String? _checkImageExists({
return image == '' ? null : image;
}

void createBackgroundImage({
required String imageDestination,
required String imageSource,
}) {
// Copy will not work if the directory does not exist, so createSync
// will ensure that the directory exists.
File(imageDestination).createSync(recursive: true);

// If source image is not already png, convert it, otherwise just copy it.
if (p.extension(imageSource).toLowerCase() != '.png') {
final image = decodeImage(File(imageSource).readAsBytesSync());
if (image == null) {
print('$imageSource could not be read');
exit(1);
}
File(imageDestination)
..createSync(recursive: true)
..writeAsBytesSync(encodePng(image));
} else {
File(imageSource).copySync(imageDestination);
}
}

/// Get config from `pubspec.yaml` or `flutter_native_splash.yaml`
Map<String, dynamic> getConfig({
required String? configFile,
Expand Down
16 changes: 8 additions & 8 deletions lib/ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -433,10 +433,10 @@ void _createBackground({
file.createSync(recursive: true);
file.writeAsBytesSync(encodePng(background));
} 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);
File(backgroundImageSource).copySync(backgroundImageDestination);
createBackgroundImage(
imageDestination: backgroundImageDestination,
imageSource: backgroundImageSource,
);
} else {
throw Exception('No color string or background image!');
}
Expand All @@ -453,10 +453,10 @@ void _createBackground({
file.createSync(recursive: true);
file.writeAsBytesSync(encodePng(background));
} 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);
File(darkBackgroundImageSource).copySync(darkBackgroundImageDestination);
createBackgroundImage(
imageDestination: darkBackgroundImageDestination,
imageSource: darkBackgroundImageSource,
);
} else {
final file = File(darkBackgroundImageDestination);
if (file.existsSync()) file.deleteSync();
Expand Down
37 changes: 20 additions & 17 deletions lib/web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,30 @@ void createBackgroundImages({
required String? backgroundImage,
required String? darkBackgroundImage,
}) {
const backgroundDestination = '${_webSplashImagesFolder}light-background.png';
print('[Web] Creating background images');
_createBackgroundImage(
backgroundImage: backgroundImage,
fileName: "light-background.png",
);
_createBackgroundImage(
backgroundImage: darkBackgroundImage,
fileName: "dark-background.png",
);
}

void _createBackgroundImage({
required String? backgroundImage,
required String fileName,
}) {
final backgroundDestination = '$_webSplashImagesFolder$fileName';
if (backgroundImage == null) {
final file = File(backgroundDestination);
if (file.existsSync()) file.deleteSync();
} else {
// Copy will not work if the directory does not exist, so createSync
// will ensure that the directory exists.
File(backgroundDestination).createSync(recursive: true);
File(backgroundImage).copySync(backgroundDestination);
}

const darkBackgroundDestination =
'${_webSplashImagesFolder}dark-background.png';
if (darkBackgroundImage == null) {
final file = File(darkBackgroundDestination);
if (file.existsSync()) file.deleteSync();
} else {
// Copy will not work if the directory does not exist, so createSync
// will ensure that the directory exists.
File(darkBackgroundDestination).createSync(recursive: true);
File(darkBackgroundImage).copySync(darkBackgroundDestination);
createBackgroundImage(
imageDestination: backgroundDestination,
imageSource: backgroundImage,
);
}
}

Expand Down