composeAttributes static method

Map<String, dynamic>? composeAttributes(
  1. Map<String, dynamic>? a,
  2. Map<String, dynamic>? b, {
  3. bool keepNull = false,
})

Composes two attribute sets.

Implementation

static Map<String, dynamic>? composeAttributes(Map<String, dynamic>? a, Map<String, dynamic>? b,
    {bool keepNull = false}) {
  a ??= const {};
  b ??= const {};

  final result = Map<String, dynamic>.from(a)..addAll(b);
  final keys = result.keys.toList(growable: false);

  if (!keepNull) {
    for (final key in keys) {
      if (result[key] == null) result.remove(key);
    }
  }

  return result.isEmpty ? null : result;
}