filterProperties function

Map<String, dynamic> filterProperties(
  1. Map<String, dynamic> properties,
  2. List<String>? keys
)

filterProperties Takes Map<String, dynamic> properties, and List<String> keys used to filter Properties. Returns Map<String, dynamic> filtered Properties For example:

filterProperties({foo: 'bar', cluster: 0}, ['cluster'])
//= {cluster: 0}

Implementation

Map<String, dynamic> filterProperties(
    Map<String, dynamic> properties, List<String>? keys) {
  if (keys == null || keys.isEmpty) return {};

  Map<String, dynamic> newProperties = {};
  for (var i = 0; i < keys.length; i++) {
    var key = keys[i];
    if (properties.containsKey(key)) {
      newProperties[key] = properties[key];
    }
  }
  return newProperties;
}