removeNulls method

dynamic removeNulls(
  1. dynamic params
)

Implementation

dynamic removeNulls(dynamic params) {
  if (params is Map) {
    var map = {};
    params.forEach((key, value) {
      var value0 = removeNulls(value);
      if (value0 != null) {
        map[key] = value0;
      }
    });
    if (map.isNotEmpty) {
      return map;
    }
  } else if (params is List) {
    var list = [];
    for (var val in params) {
      var value = removeNulls(val);
      if (value != null) {
        list.add(value);
      }
    }
    if (list.isNotEmpty) return list;
  } else if (params != null) {
    return params;
  }
  return null;
}