copyPreferences function

Map<String, Object> copyPreferences(
  1. Map<String, Object?> values
)

Creates a detached, typed snapshot of supported preference values.

Implementation

Map<String, Object> copyPreferences(Map<String, Object?> values) {
  final result = <String, Object>{};
  for (final entry in values.entries) {
    final value = entry.value;
    if (value is String || value is int || value is double || value is bool) {
      result[entry.key] = value!;
    } else if (value is List && value.every((Object? item) => item is String)) {
      result[entry.key] = List<String>.from(value);
    } else if (value != null) {
      throw FormatException(
        'Unsupported preference type for key "${entry.key}".',
      );
    }
  }
  return result;
}