updateColorsXmlFile function

Future<void> updateColorsXmlFile(
  1. String backgroundConfig,
  2. String? flavor, {
  3. required FLILogger logger,
  4. String prefixPath = '.',
})

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, {
  required FLILogger logger,
  String prefixPath = '.',
}) async {
  final File colorsXml = File(
    path.join(prefixPath, constants.androidColorsFile(flavor)),
  );
  // existsSync is intentional here: a single bool probe before deciding
  // whether to update or create the file. Async I/O is reserved for the
  // image read/encode/write hot paths.
  if (colorsXml.existsSync()) {
    logger.info('Updating colors.xml with color for adaptive icon background');
    await updateColorsFile(colorsXml, backgroundConfig);
  } else {
    logger.info('No colors.xml file found in your Android project');
    logger.info(
      'Creating colors.xml file and adding it to your Android project',
    );
    await createNewColorsFile(backgroundConfig, flavor, prefixPath: prefixPath);
  }
}