createProfile method

Future<Profile> createProfile({
  1. required String name,
  2. required String versionId,
  3. String? gameDir,
  4. String? javaDir,
  5. String? javaArgs,
  6. String icon = 'Furnace',
  7. bool skipJreVersionCheck = false,
  8. String type = 'custom',
})

Creates a new profile with the specified settings.

name - Name of the profile versionId - Minecraft version ID gameDir - Optional custom game directory javaDir - Optional custom Java directory javaArgs - Optional custom Java arguments icon - Icon identifier for the profile skipJreVersionCheck - Whether to skip Java version checking type - Type of profile Returns the created profile. Throws an exception if profiles have not been loaded.

Implementation

Future<Profile> createProfile({
  required String name,
  required String versionId,
  String? gameDir,
  String? javaDir,
  String? javaArgs,
  String icon = 'Furnace',
  bool skipJreVersionCheck = false,
  String type = 'custom',
}) async {
  if (_profiles == null) {
    throw Exception('Launcher profiles not loaded');
  }

  final now = DateTime.now().toIso8601String();

  final profile = Profile(
    created: now,
    gameDir: gameDir,
    icon: icon,
    javaDir: javaDir,
    lastUsed: now,
    lastVersionId: versionId,
    name: name,
    skipJreVersionCheck: skipJreVersionCheck,
    type: type,
    javaArgs: javaArgs,
  );

  final profileId = _generateProfileId();
  final updatedProfiles = Map<String, Profile>.from(_profiles!.profiles);
  updatedProfiles[profileId] = profile;

  _profiles = LauncherProfiles(
    profiles: updatedProfiles,
    settings: _profiles!.settings,
    version: _profiles!.version,
  );

  await saveProfiles();
  return profile;
}