getString method

String? getString(
  1. String key, {
  2. String? defaultValue,
})

Reads a key value of String type from Map.

If value/map is NULL or not String type return empty string

Example:

Map<String, dynamic> map = {'username': 'thor', 'age': 35};

String username = map.getString('username');
print(username); // Output: thor

String email = map.getString('email', 'not_provided@example.com');
print(email); // Output: not_provided@example.com

Implementation

String? getString(String key, {String? defaultValue}) =>
    this[key] is String ? this[key]! as String : defaultValue;