BaseDocument.fromType constructor
BaseDocument.fromType(
- String docType, {
- String? data,
- TransportableData? signature,
- Create a new empty document
- Create entity document with data and signature loaded from local storage
@param docType - document type
@param data - document data in JsON format
@param signature - signature of document data in Base64 format
Implementation
BaseDocument.fromType(String docType, {String? data, TransportableData? signature}) {
// document type
assert(docType.isNotEmpty && docType != '*', 'document type error: $docType');
this['type'] = docType;
// document data(Json) & signature(Base64)
if (data == null || signature == null) {
assert(data == null && signature == null, 'document data/signature error: $data, $signature');
// 1. Create a new empty document
_json = null;
_sig = null;
// initialize properties with created time
_properties = {
'type': docType, // deprecated
'created_time': DateTime.now().millisecondsSinceEpoch / 1000.0,
};
_status = 0;
} else {
assert(data.isNotEmpty && signature.isNotEmpty, 'document data/signature error: $data, $signature');
// 2. Create entity document with data and signature loaded from local storage
this['data'] = data;
this['signature'] = signature.serialize();
_json = data;
_sig = signature;
_properties = null; // lazy
// all documents must be verified before saving into local storage
_status = 1;
}
}