removeKeys method

  1. @useResult
bool removeKeys(
  1. List<String>? removeKeysList, {
  2. bool recurseChildValues = true,
})

Returns true after removing all keys in removeKeysList from this map.

When recurseChildValues is true (default), keys are also removed from nested Map<String, dynamic> values. Recursion follows the map's nesting depth, so disable recurseChildValues for untrusted, arbitrarily-deep input.

Implementation

@useResult
bool removeKeys(List<String>? removeKeysList, {bool recurseChildValues = true}) {
  if (removeKeysList == null || removeKeysList.isEmpty) {
    return false;
  }

  removeWhere((String key, _) => removeKeysList.contains(key));
  if (recurseChildValues) {
    // ignore: require_future_error_handling -- updateAll is synchronous; no future to handle
    updateAll(
      (String _, dynamic value) {
        // ignore: unused_result, saropa_lints/avoid_ignoring_return_values -- recursive in-place mutation; bool result intentionally discarded
        if (value is Map<String, dynamic>) value.removeKeys(removeKeysList);

        return value;
      },
    );
  }

  return true;
}