deserialize method
void
deserialize(
- XmlElement xml
Implementation
void deserialize(XmlElement xml) {
// set busy
busy = true;
// inner scope
if (!isNullOrEmpty(Xml.get(node: xml, tag: 'scope'))) {
_subscope = Scope(parent: scope, id: Xml.get(node: xml, tag: 'scope'));
}
// retain a pointer to the xml
element = xml;
// properties
debug = Xml.get(node: xml, tag: 'debug');
datasource = Xml.get(node: xml, tag: 'data');
// register a listener to the datasource if specified
IDataSource? source = scope?.getDataSource(datasource);
source?.register(this);
// we first sort the elements moving vars and datasources to the top of the
// deserialization sequence in order to avoid excessive deferred bindings
var elements = xml.children.whereType<XmlElement>().toList();
if (elements.length > 1) {
var topmost = elements
.where((element) => _topmost.contains(element.name.toString()))
.toList();
if (topmost.isNotEmpty && topmost.length != elements.length) {
elements.removeWhere((element) => topmost.contains(element));
elements.insertAll(0, topmost);
}
}
// deserialize children
children?.clear();
for (var element in elements) {
// deserialize the model
var model = WidgetModel.fromXml(this, element);
if (model != null)
{
// add model to the datasource list
if (model is IDataSource) {
(datasources ??= []).add(model as IDataSource);
}
// add model to the child list
// in cases like camera, it is both a viewable widget as well
// as a data source.
if (model is! IDataSource || model is ViewableWidgetMixin) {
(children ??= []).add(model);
}
}
}
// set idle
busy = false;
}