decode static method

Future<FormDef> decode(
  1. Uint8List bytes, {
  2. ResourceResolver? resolver,
  3. XFormParser? parser,
})

Restores a form encoded by encode, reading external secondary instances through resolver (or a configured parser). As in JavaRosa's ExternalDataInstance.readExternal, external instances are read again, and a missing file throws ResourceNotFoundException (a client would then parse the form again, using a placeholder).

Implementation

static Future<FormDef> decode(
  Uint8List bytes, {
  ResourceResolver? resolver,
  XFormParser? parser,
}) async {
  final data = jsonDecode(utf8.decode(bytes)) as Map<String, Object?>;
  if (data['version'] != version) {
    throw FormatException(
      'Unsupported FormDefCodec version ${data['version']}',
    );
  }
  final form = await (parser ?? XFormParser(resolver: resolver)).parse(
    data['formXml']! as String,
    formXmlSrc: data['formXmlPath'] as String?,
    lastSavedSrc: data['lastSavedSrc'] as String?,
    instanceXml: data['instance']! as String,
    restoringCachedForm: true,
  );
  final language = data['language'] as String?;
  if (language != null) form.localizer?.locale = language;
  return form;
}