deleteProfile method
Deletes a profile.
profileId
- ID of the profile to delete
Throws an exception if profiles have not been loaded or if the profile ID doesn't exist.
Implementation
Future<void> deleteProfile(String profileId) async {
if (_profiles == null) {
throw Exception('Launcher profiles not loaded');
}
if (!_profiles!.profiles.containsKey(profileId)) {
throw Exception('Profile with ID $profileId not found');
}
if (_activeProfile != null &&
_activeProfile!.name == _profiles!.profiles[profileId]!.name) {
_activeProfile = null;
}
final updatedProfiles = Map<String, Profile>.from(_profiles!.profiles);
updatedProfiles.remove(profileId);
_profiles = LauncherProfiles(
profiles: updatedProfiles,
settings: _profiles!.settings,
version: _profiles!.version,
);
await saveProfiles();
if (_activeProfile == null && updatedProfiles.isNotEmpty) {
_activeProfile = updatedProfiles.values.first;
}
}