mergeRecaps static method

Map<String, dynamic> mergeRecaps(
  1. Map<String, dynamic> recap1,
  2. Map<String, dynamic> recap2
)

Implementation

static Map<String, dynamic> mergeRecaps(
  Map<String, dynamic> recap1,
  Map<String, dynamic> recap2,
) {
  isValidRecap(recap1);
  isValidRecap(recap2);
  final att1 = recap1['att'] as Map<String, dynamic>;
  final att2 = recap2['att'] as Map<String, dynamic>;
  final keys = [...att1.keys, ...att2.keys]..sort(
      (a, b) => a.compareTo(b),
    );
  final mergedRecap = {'att': {}};

  for (var key in keys) {
    final actions1 = att1[key] as Map<String, dynamic>? ?? {};
    final actions1Keys = actions1.keys;
    final actions2 = att2[key] as Map<String, dynamic>? ?? {};
    final actions2Keys = actions2.keys;
    final actions = [...actions1Keys, ...actions2Keys]..sort(
        (a, b) => a.compareTo(b),
      );

    for (var action in actions) {
      mergedRecap['att']![key] = {
        ...mergedRecap['att']?[key],
        [action]: recap1['att'][key]?[action] || recap2['att'][key]?[action],
      };
    }
  }

  return mergedRecap;
}