createAndroid12Styles function
Updates the styles.xml
file for the splash screen setup for Android 12+.
Implementation
Future<void> createAndroid12Styles({
required File styleFile,
String? color,
String? imageSource,
String? brandingImageSource,
}) async {
final xml = await styleFile.create();
final builder = XmlBuilder();
builder.processing(AndroidStrings.xml, AndroidStrings.xmlVersion);
/// Creating a resources element
builder.element(
AndroidStrings.resourcesElement,
nest: () {
/// Creating a style element as child of resources element
builder.element(
AndroidStrings.styleElement,
attributes: {
AndroidStrings.nameAttr: AndroidStrings.styleNameAttrVal,
AndroidStrings.styleParentAttr: AndroidStrings.styleParentAttrVal,
},
nest: () {
/// Creating a item element for color
if (color != null) {
builder.element(
AndroidStrings.itemElement,
attributes: {
AndroidStrings.nameAttr: AndroidStrings.windowSplashScreenBG,
},
nest: color,
);
}
/// Creating a item element for image
if (imageSource != null) {
builder.element(
AndroidStrings.itemElement,
attributes: {
AndroidStrings.nameAttr:
AndroidStrings.windowSplashScreenAnimatedIcon,
},
nest: AndroidStrings.drawableSplashImage12,
);
}
if (brandingImageSource != null) {
builder.element(
AndroidStrings.itemElement,
attributes: {
AndroidStrings.nameAttr:
AndroidStrings.windowSplashScreenBrandingImage,
},
nest: AndroidStrings.drawableAndroid12BrandingImage,
);
}
},
);
},
);
final document = builder.buildDocument();
await xml.writeAsString(document.toXmlString(pretty: true));
}