updateColorsXmlFile function

Future<void> updateColorsXmlFile(
  1. String backgroundConfig,
  2. String? flavor
)

Retrieves the colors.xml file for the project.

If the colors.xml file is found, it is updated with a new color item for the adaptive icon background.

If not, the colors.xml file is created and a color item for the adaptive icon background is included in the new colors.xml file.

Implementation

Future<void> updateColorsXmlFile(String backgroundConfig, String? flavor) async {
  final File colorsXml = File(constants.androidColorsFile(flavor));
  // Using the sync method here due to `avoid_slow_async_io` lint suggestion.
  if (colorsXml.existsSync()) {
    utils.printStatus(
      'Updating colors.xml with color for adaptive icon background',
    );
    await updateColorsFile(colorsXml, backgroundConfig);
  } else {
    utils.printStatus('No colors.xml file found in your Android project');
    utils.printStatus(
      'Creating colors.xml file and adding it to your Android project',
    );
    await createNewColorsFile(backgroundConfig, flavor);
  }
}