getProperties method
Implementation
@override
Map<String, dynamic> getProperties({Element? ancestor}) {
Map<String, dynamic> properties = super.getProperties(ancestor: ancestor);
String? className;
// EditableText
if (element.widget is EditableText) {
className = RanorexSupportedClassName.editableText;
final EditableText editableTextWidget = element.widget as EditableText;
final TextEditingController controller = editableTextWidget.controller;
properties[WidgetProperty.text.name] = controller.text;
properties[WidgetProperty.textColor.name] = editableTextWidget
.style.color !=
null
? '#${(editableTextWidget.style.color!.value & 0xFFFFFF).toRadixString(16).padLeft(6, '0').toUpperCase()}'
: '';
final TextSelection selection = controller.selection;
properties[WidgetProperty.selectionStart.name] = selection.start;
properties[WidgetProperty.selectionLength.name] =
selection.end - selection.start;
if (selection.end > selection.start) {
properties[WidgetProperty.selectionText.name] =
controller.text.substring(selection.start, selection.end);
}
properties[WidgetProperty.hasFocus.name] =
editableTextWidget.focusNode.hasFocus;
}
// TextField
else if (element.widget is TextField) {
final TextField textFieldWidget = element.widget as TextField;
final TextEditingController? controller = textFieldWidget.controller;
className = RanorexSupportedClassName.textField;
properties[WidgetProperty.text.name] = controller?.text ?? '';
properties[WidgetProperty.textColor.name] = textFieldWidget
.style?.color !=
null
? '#${(textFieldWidget.style!.color!.value & 0xFFFFFF).toRadixString(16).padLeft(6, '0').toUpperCase()}'
: '';
properties[WidgetProperty.backgroundColor.name] = textFieldWidget
.decoration?.fillColor !=
null
? '#${(textFieldWidget.decoration!.fillColor!.value & 0xFFFFFF).toRadixString(16).padLeft(6, '0').toUpperCase()}'
: '';
final TextSelection selection =
controller?.selection ?? const TextSelection.collapsed(offset: 0);
properties[WidgetProperty.selectionStart.name] = selection.start;
properties[WidgetProperty.selectionLength.name] =
selection.end - selection.start;
if (selection.end > selection.start) {
properties[WidgetProperty.selectionText.name] =
controller?.text.substring(selection.start, selection.end);
}
properties[WidgetProperty.hasFocus.name] =
textFieldWidget.focusNode?.hasFocus ?? false;
}
// TextFormField
else if (element.widget is TextFormField) {
className = RanorexSupportedClassName.textFormField;
final TextFormField textFormFieldWidget = element.widget as TextFormField;
final TextEditingController? controller = textFormFieldWidget.controller;
properties[WidgetProperty.text.name] = controller?.text ?? '';
final TextSelection selection =
controller?.selection ?? const TextSelection.collapsed(offset: 0);
properties[WidgetProperty.selectionStart.name] = selection.start;
properties[WidgetProperty.selectionLength.name] =
selection.end - selection.start;
if (selection.end > selection.start) {
properties[WidgetProperty.selectionText.name] =
controller?.text.substring(selection.start, selection.end);
}
}
//Text
else if (element.widget is Text) {
className = RanorexSupportedClassName.textWidget;
Text textWidget = element.widget as Text;
properties[WidgetProperty.text.name] = textWidget.data ?? '';
properties[WidgetProperty.textColor.name] = textWidget.style?.color !=
null
? '#${(textWidget.style!.color!.value & 0xFFFFFF).toRadixString(16).padLeft(6, '0').toUpperCase()}'
: '';
}
//Badge
else if (element.widget is Badge) {
className = RanorexSupportedClassName.badge;
Badge badgeWidget = element.widget as Badge;
if (badgeWidget.label is Text) {
final textWidget = badgeWidget.label as Text;
properties[WidgetProperty.text.name] = textWidget.data ?? '';
properties[WidgetProperty.textColor.name] = textWidget.style?.color !=
null
? '#${(textWidget.style!.color!.value & 0xFFFFFF).toRadixString(16).padLeft(6, '0').toUpperCase()}'
: '';
}
properties[WidgetProperty.backgroundColor.name] =
'#${(badgeWidget.backgroundColor!.value & 0xFFFFFF).toRadixString(16).padLeft(6, '0').toUpperCase()}';
}
properties[WidgetProperty.className.name] = className;
properties[WidgetProperty.accessibilityLabel.name] =
element.findAncestorWidgetOfExactType<Semantics>()?.properties.label ??
'';
return properties;
}