getDevices method

List<AppleDeviceModel> getDevices(
  1. String body
)

Implementation

List<AppleDeviceModel> getDevices(String body) {
  final document = parse(body);
  final typesElement = document.getElementById(deviceTypesId);
  final trs = typesElement?.querySelectorAll('tr');

  if (trs == null) {
    return [];
  }

  final models = <AppleDeviceModel>[];
  for (final tr in trs) {
    for (final child in parse(tr.innerHtml).children) {
      final texts = child.text.split(':');
      if (texts.length != 2) {
        continue;
      }

      final model = AppleDeviceModel(
        id: texts.first.trim(),
        name: texts.last.trim(),
      );
      models.add(model);
    }
  }
  return models;
}