createDarkSplashImageDrawable function
Implementation
Future<void> createDarkSplashImageDrawable({
String? darkImage,
String? color,
String? gravity,
}) async {
log(darkImage ?? '');
if (darkImage == null) return;
final darkImageFile = File(darkImage);
if (await darkImageFile.exists()) {
const androidDrawableFolder = CmdStrings.androidDrawableDarkDirectory;
const splashImagePath =
'$androidDrawableFolder/${AndroidStrings.splashScreenDarkXml}';
final file = File(splashImagePath);
final xml = await file.create(recursive: true);
final builder = XmlBuilder();
builder.processing(AndroidStrings.xml, AndroidStrings.xmlVersion);
/// Creating a layer-list element and its attributes
builder.element(AndroidStrings.layerListElement, nest: () {
builder.attribute(
AndroidStrings.xmlnsAndroidAttr,
AndroidStrings.xmlnsAndroidAttrValue,
);
/// Creates item element and attributes for color
if (color != null) {
builder.element(
AndroidStrings.itemElement,
nest: () {
builder.attribute(
AndroidStrings.androidDrawableAttr,
AndroidStrings.androidDrawableAttrVal,
);
},
);
}
/// Creates item element and attributes for image
builder.element(AndroidStrings.itemElement, nest: () {
builder.element(AndroidStrings.bitmapAttrVal, nest: () {
builder.attribute(
AndroidStrings.androidGravityAttr,
gravity ?? AndroidStrings.defaultAndroidGravityAttrVal,
);
builder.attribute(
AndroidStrings.androidSrcAttr,
AndroidStrings.androidDarkSrcAttrVal,
);
builder.attribute(
AndroidStrings.androidTileModeAttr,
AndroidStrings.androidTileModeAttrVal,
);
});
});
});
final document = builder.buildDocument();
await xml.writeAsString(document.toXmlString(pretty: true));
} else {
throw SplashMasterException(message: "$darkImage doesn't exists.");
}
}