# saveTemplate method

Future<void> saveTemplate(

1. String name

)

Save a distro as a template by `name`

## Implementation

    Future<void> saveTemplate(String name) async {
      String templateName = name;
      // Check if template already exists
      var templates = prefs.getStringList('templates');
      var i = 2;
      while (templates != null && templates.contains(templateName)) {
        if (i > 2) {
          templateName =
              '${templateName.substring(0, templateName.length - 2)}-$i';
        } else {
          templateName = '$templateName-2';
        }
        i++;
      }

      plausible.event(name: "wsl_saveastemplate");
      Notify.message('$templateName ${'savingastemplate-text'.i18n()}.',
          loading: true);
      await WSLApi().export(name, getTemplatePath().file('$templateName.ext4'));
      templates ??= [];
      templates.add(templateName);
      prefs.setStringList('templates', templates);
      Notify.message('$templateName ${'savedastemplate-text'.i18n()}.',
          duration: const Duration(seconds: 3));
    }