buildBody method

Map<String, dynamic> buildBody({
  1. int? homeMobileCountryCode,
  2. int? homeMobileNetworkCode,
  3. String? radioType,
  4. String? carrier,
  5. bool? considerIp,
  6. List<CellTower> cellTowers = const [],
  7. List<WifiAccessPoint> wifiAccessPoints = const [],
})

Implementation

Map<String, dynamic> buildBody({
  int? homeMobileCountryCode,
  int? homeMobileNetworkCode,
  String? radioType,
  String? carrier,
  bool? considerIp,
  List<CellTower> cellTowers = const [],
  List<WifiAccessPoint> wifiAccessPoints = const [],
}) {
  var params = <String, dynamic>{};

  // All optionals
  if (homeMobileCountryCode != null) {
    params['homeMobileCountryCode'] = homeMobileCountryCode.toString();
  }

  if (homeMobileNetworkCode != null) {
    params['homeMobileNetworkCode'] = homeMobileNetworkCode.toString();
  }

  if (radioType != null) {
    params['radioType'] = radioType;
  }

  if (carrier != null) {
    params['carrier'] = carrier;
  }

  if (considerIp != null) {
    params['considerIp'] = considerIp.toString();
  }

  if (cellTowers.isNotEmpty) {
    params['cellTowers'] = cellTowers.map((c) => c.toJson()).toList();
  }

  if (wifiAccessPoints.isNotEmpty) {
    params['wifiAccessPoints'] =
        wifiAccessPoints.map((w) => w.toJson()).toList();
  }

  return params;
}