deserialize method
Deserializes the FML template elements, attributes and children
Implementation
@override
void deserialize(XmlElement xml) {
// deserialize
super.deserialize(xml);
// set size constraints
width = Xml.get(node: xml, tag: 'width');
height = Xml.get(node: xml, tag: 'height');
minWidth = Xml.get(node: xml, tag: 'minwidth');
maxWidth = Xml.get(node: xml, tag: 'maxwidth');
minHeight = Xml.get(node: xml, tag: 'minheight');
maxHeight = Xml.get(node: xml, tag: 'maxheight');
depth = Xml.get(node: xml, tag: 'depth');
// properties
visible = Xml.get(node: xml, tag: 'visible');
enabled = Xml.get(node: xml, tag: 'enabled');
halign = Xml.get(node: xml, tag: 'halign');
valign = Xml.get(node: xml, tag: 'valign');
flex = Xml.get(node: xml, tag: 'flex');
flexfit = Xml.get(node: xml, tag: 'flexfit');
onscreen = Xml.get(node: xml, tag: 'onscreen');
offscreen = Xml.get(node: xml, tag: 'offscreen');
// _colors array - sets color1, color2, color3 and colo4
_colors = Xml.get(node: xml, tag: 'color');
// visual transforms
opacity = Xml.get(node: xml, tag: 'opacity');
rotation = Xml.get(node: xml, tag: 'rotate');
flip = Xml.get(node: xml, tag: 'flip');
// drag
draggable = Xml.get(node: xml, tag: 'draggable');
if (draggable) {
ondrag = Xml.get(node: xml, tag: 'ondrag');
ondropped = Xml.get(node: xml, tag: 'ondropped');
}
// drop
droppable = Xml.get(node: xml, tag: 'droppable');
if (droppable) {
ondrop = Xml.get(node: xml, tag: 'ondrop');
canDrop = Xml.get(node: xml, tag: 'candrop');
drop = Data();
}
// view sizing and position
// these are treated differently for efficiency reasons
// we only create the observable if its bound to in the template
// otherwise we just store the value in a simple double variable
String? key;
if (WidgetModel.isBound(this, key = Binding.toKey(id, 'viewwidth'))) {
_viewWidthObservable = DoubleObservable(key, null, scope: scope);
}
if (WidgetModel.isBound(this, key = Binding.toKey(id, 'viewheight'))) {
_viewHeightObservable = DoubleObservable(key, null, scope: scope);
}
if (WidgetModel.isBound(this, key = Binding.toKey(id, 'viewx'))) {
_viewXObservable = DoubleObservable(key, null, scope: scope);
}
if (WidgetModel.isBound(this, key = Binding.toKey(id, 'viewy'))) {
_viewYObservable = DoubleObservable(key, null, scope: scope);
}
// view requires a VisibilityDetector if either onstage or offstage is set or
// someone is bound to my visibility
_addVisibilityDetector = visible &&
(!isNullOrEmpty(onscreen) ||
!isNullOrEmpty(offscreen) ||
WidgetModel.isBound(this, Binding.toKey(id, 'visiblearea')) ||
WidgetModel.isBound(this, Binding.toKey(id, 'visibleheight')) ||
WidgetModel.isBound(this, Binding.toKey(id, 'visiblewidth')));
// set margins. Can be comma separated top,left,bottom,right
// space around the widget
var margins = Xml.attribute(node: xml, tag: 'margin') ??
Xml.attribute(node: xml, tag: 'margins');
this.margins = margins;
// set padding. Can be comma separated top,left,bottom,right
// space around the widget's children
var padding = Xml.attribute(node: xml, tag: 'pad') ??
Xml.attribute(node: xml, tag: 'padding') ??
Xml.attribute(node: xml, tag: 'padd');
this.padding = padding;
// tooltip
var tooltip = Xml.attribute(node: xml, tag: 'tip') ??
Xml.attribute(node: xml, tag: 'tootip');
List<TooltipModel> tips =
findChildrenOfExactType(TooltipModel).cast<TooltipModel>();
if (tips.isNotEmpty) {
tipModel = tips.first;
removeChildrenOfExactType(TooltipModel);
} else if (tooltip != null) {
// build tooltip
XmlElement eTip = XmlElement(XmlName("TOOLTIP"));
// build text
tooltip = tooltip.replaceAll("{this.id}", id);
XmlElement eText = XmlElement(XmlName("TEXT"));
eText.attributes.add(XmlAttribute(XmlName("value"), tooltip));
eTip.children.add(eText);
var model = WidgetModel.fromXml(this, eTip);
tipModel = (model is TooltipModel) ? model : null;
}
// add animations
children?.forEach((child) {
if (child is AnimationModel) {
animations ??= [];
animations!.add(child);
}
});
// remove animations from child list
if (animations != null) {
children?.removeWhere((element) => animations!.contains(element));
}
}