update method

Project update(
  1. Project project, {
  2. Map<String, String>? flavors,
  3. String? flutterSdkVersion,
  4. bool? updateVscodeSettings,
})

Update the project with new configurations

The project parameter is the project to be updated. The optional parameters are:

  • flavors: A map of flavor configurations.
  • pinnedVersion: The new pinned version of the Flutter SDK.

This method updates the project's configuration with the provided parameters. It creates or updates the project's config file. The updated project is returned.

Implementation

Project update(
  Project project, {
  Map<String, String>? flavors,
  String? flutterSdkVersion,
  bool? updateVscodeSettings,
}) {
  final currentConfig = project.config ?? ProjectConfig.empty();

  final mergedFlavors = {...?currentConfig.flavors, ...?flavors};

  final newConfig = ProjectConfig(
    flutter: flutterSdkVersion,
    flavors: mergedFlavors.isNotEmpty ? mergedFlavors : null,
    updateVscodeSettings: updateVscodeSettings,
  );

  final config = currentConfig.copyWith.$merge(newConfig);

  // Update flavors
  final configFile = project.configPath.file;
  final legacyConfigFile = project.legacyConfigPath.file;

  // If config file does not exists create it
  if (!configFile.existsSync()) {
    configFile.createSync(recursive: true);
  }

  final jsonContents = prettyJson(config.toMap());

  configFile.write(jsonContents);
  legacyConfigFile.write(prettyJson(config.toLegacyMap()));

  return Project.loadFromPath(project.path);
}