saveAsPreset method

Future<void> saveAsPreset(
  1. String? name
)

Saves the current state as a preset and updates the user's settings.

Implementation

Future<void> saveAsPreset(String? name) async {
  if (name == null) return;
  if (models.settings.dashboard.presets.any((otherPreset) => otherPreset.name == name)) {
    models.home.setMessage(
      severity: Severity.error,
      text: "Name is already taken, please rename preset",
    );
    return;
  }
  final preset = toPreset(name);
  models.settings.dashboard.presets.add(preset);
  await models.settings.update();
}