Skip to content

Commit

Permalink
Merge pull request #8 from Bwolfs2/master
Browse files Browse the repository at this point in the history
Added full option plus center option
  • Loading branch information
henriquearthur committed Aug 30, 2019
2 parents 5e25ed6 + 594b6fa commit 2fc7bfe
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
28 changes: 19 additions & 9 deletions lib/android.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ final List<AndroidDrawableTemplate> splashImages = <AndroidDrawableTemplate>[
];

/// Create Android splash screen
createSplash(String imagePath, String color) async {
createSplash(String imagePath, String color, bool full) async {
await _applyImage(imagePath);
await _applyLaunchBackgroundXml();
await _applyLaunchBackgroundXml(full);

// _applyColor will update launch_background.xml which may be created in _applyLaunchBackgroundXml
// that's why we need to await _applyLaunchBackgroundXml()
Expand Down Expand Up @@ -69,23 +69,23 @@ void _saveImage(AndroidDrawableTemplate template, Image image) {
}

/// Create or update launch_background.xml adding splash image path
Future _applyLaunchBackgroundXml() {
Future _applyLaunchBackgroundXml(bool full) {
final File launchBackgroundFile = File(androidLaunchBackgroundFile);

if (launchBackgroundFile.existsSync()) {
print("[Android] Updating launch_background.xml with splash image path");
return _updateLaunchBackgroundFileWithImagePath();
return _updateLaunchBackgroundFileWithImagePath(full);
} else {
print(
"[Android] No launch_background.xml file found in your Android project");
print(
"[Android] Creating launch_background.xml file and adding it to your Android project");
return _createLaunchBackgroundFileWithImagePath();
return _createLaunchBackgroundFileWithImagePath(full);
}
}

/// Updates launch_background.xml adding splash image path
Future _updateLaunchBackgroundFileWithImagePath() async {
Future _updateLaunchBackgroundFileWithImagePath(bool full) async {
final File launchBackgroundFile = File(androidLaunchBackgroundFile);
final List<String> lines = await launchBackgroundFile.readAsLines();
bool foundExisting = false;
Expand All @@ -104,17 +104,27 @@ Future _updateLaunchBackgroundFileWithImagePath() async {
if (lines.isEmpty) {
throw InvalidNativeFile("File 'launch_background.xml' contains 0 lines.");
} else {
lines.insert(lines.length - 1, templates.androidLaunchBackgroundItemXml);
if (full == null || !full) {
lines.insert(
lines.length - 1, templates.androidLaunchBackgroundItemXml);
} else {
lines.insert(
lines.length - 1, templates.androidLaunchBackgroundItemXmlFill);
}
}
}

await launchBackgroundFile.writeAsString(lines.join('\n'));
}

/// Creates launch_background.xml with splash image path
Future _createLaunchBackgroundFileWithImagePath() async {
Future _createLaunchBackgroundFileWithImagePath(bool full) async {
File file = await File(androidLaunchBackgroundFile).create(recursive: true);
return await file.writeAsString(templates.androidLaunchBackgroundXml);
if (full == null || !full) {
return await file.writeAsString(templates.androidLaunchBackgroundXml);
} else {
return await file.writeAsString(templates.androidLaunchBackgroundXmlFill);
}
}

/// Create or update colors.xml adding splash screen background color
Expand Down
3 changes: 2 additions & 1 deletion lib/flutter_native_splash.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ void createSplash() async {

String image = config['image'];
String color = config['color'];
bool full = config['full'];

if (!config.containsKey("android") || config['android']) {
await android.createSplash(image, color);
await android.createSplash(image, color,full);
}

if (!config.containsKey("ios") || config['ios']) {
Expand Down
15 changes: 15 additions & 0 deletions lib/templates.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ const String androidLaunchBackgroundXml = '''
</layer-list>
''';

const String androidLaunchBackgroundItemXmlFill = '''
<item>
<bitmap android:gravity="fill" android:src="@drawable/splash" />
</item>
''';

const String androidLaunchBackgroundXmlFill = '''
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/splash_color" />
$androidLaunchBackgroundItemXmlFill
</layer-list>
''';

const String androidStylesItemXml = '''
<item name="android:windowFullscreen">true</item>
''';
Expand Down

0 comments on commit 2fc7bfe

Please sign in to comment.