StickerPack.fromXML constructor

StickerPack.fromXML(
  1. String id,
  2. XMLNode node,
  3. {bool hashAvailable = true}
)

Implementation

factory StickerPack.fromXML(
  String id,
  XMLNode node, {
  bool hashAvailable = true,
}) {
  assert(node.tag == 'pack', 'node has wrong tag');
  assert(node.attributes['xmlns'] == stickersXmlns, 'node has wrong XMLNS');

  var hashAlgorithm = HashFunction.sha256;
  var hashValue = '';
  if (hashAvailable) {
    final hash = node.firstTag('hash', xmlns: hashXmlns)!;
    hashAlgorithm = HashFunction.fromName(hash.attributes['algo']! as String);
    hashValue = hash.innerText();
  }

  return StickerPack(
    id,
    node.firstTag('name')!.innerText(),
    node.firstTag('summary')!.innerText(),
    hashAlgorithm,
    hashValue,
    node.children
        .where((e) => e.tag == 'item')
        .map<Sticker>(Sticker.fromXML)
        .toList(),
    node.firstTag('restricted') != null,
  );
}