stringValuesOnly property

Map get stringValuesOnly

Returns a new map with string values only.

The getter iterates over each key-value pair in the original map. If the value is of type DateTime, it converts it to a string representation.

Returns a new map with the same keys but string values instead of DateTime values.

Example:

Map<dynamic, dynamic> originalMap = {
  'name': 'Alice',
  'age': 25,
  'birthday': DateTime(1990, 1, 1),
};

Map<dynamic, dynamic> stringMap = originalMap.stringValuesOnly;
print(stringMap); // Output: {name: Alice, age: 25, birthday: 1990-01-01 00:00:00.000}

Implementation

Map<dynamic, dynamic> get stringValuesOnly {
  Map<dynamic, dynamic> map = this;
  map.forEach((key, value) {
    if (value is DateTime) map[key] = value.toString();
  });

  return map;
}