BtDeviceParameter.fromXML constructor

BtDeviceParameter.fromXML(
  1. String xmlSTR
)

Implementation

factory BtDeviceParameter.fromXML(String xmlSTR) {
  final document = XmlDocument.parse(xmlSTR);

  XmlElement? vendorModelInfoElement =
      document.firstChild!.getElement("vendorModelInfo");
  XmlElement? ipAndPortElement = document.firstChild!.getElement("ipAndPort");
  XmlElement? statusElement = document.firstChild!.getElement("btStatus");

  VendorModelInfo vendorModelInfo =
      VendorModelInfo.fromXML(vendorModelInfoElement!.toXmlString());
  IpAndPort ipAndPort = IpAndPort.fromXML(ipAndPortElement!.toXmlString());
  BtStatus status = BtStatus.fromXML(statusElement!.toXmlString());

  String supportsColor = document.firstChild!.attributes
      .firstWhere((element) => element.name.toString() == "supportsColor")
      .value;

  XmlElement? supportedStocksElement =
      document.firstChild!.getElement("supportedStocks");
  List<XmlElement> supporters = supportedStocksElement == null
      ? []
      : supportedStocksElement.findElements("supportedStock").toList();
  List<SupportedStock> supportedStocks =
      supporters.map((e) => SupportedStock.fromXML(e.toXmlString())).toList();

  return BtDeviceParameter(
      vendorModelInfo: vendorModelInfo,
      ipAndPort: ipAndPort,
      status: status,
      supportsColor: supportsColor,
      supportedStocks: supportedStocks);
}