getProperties method
Implementation
@override
Map<String, dynamic> getProperties({Element? ancestor}) {
Map<String, dynamic> properties = super.getProperties(ancestor: ancestor);
// ElevatedButton
if (element.widget is ElevatedButton) {
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.elevatedButton;
ElevatedButton buttonWidget = element.widget as ElevatedButton;
properties[WidgetProperty.enabled.name] = buttonWidget.onPressed != null;
if (buttonWidget.child is Text) {
properties[WidgetProperty.text.name] =
(buttonWidget.child as Text).data ?? '';
}
}
// TextButton
else if (element.widget is TextButton) {
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.textButton;
TextButton textButton = element.widget as TextButton;
properties[WidgetProperty.enabled.name] = textButton.onPressed != null;
if (textButton.child is Text) {
properties[WidgetProperty.text.name] =
(textButton.child as Text).data ?? '';
}
}
// MaterialButton
else if (element.widget is MaterialButton) {
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.materialButton;
MaterialButton materialButton = element.widget as MaterialButton;
properties[WidgetProperty.text.name] =
(materialButton.child as Text).data ?? '';
}
// FloatingActionButton
else if (element.widget is FloatingActionButton) {
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.iconButton;
}
// IconButton
else if (element.widget is IconButton) {
String associatedText = '';
bool isEnabled = element.widget is IconButton &&
(element.widget as IconButton).onPressed != null;
// Look for nearby Text widgets in Row or Column
Element? ancestor =
element.findAncestorWidgetOfExactType<Row>()?.createElement() ??
element.findAncestorWidgetOfExactType<Column>()?.createElement();
if (ancestor != null) {
if (ancestor.widget is Row) {
Row rowWidget = ancestor.widget as Row;
associatedText = _findTextInSiblings(rowWidget.children);
} else if (ancestor.widget is Column) {
Column columnWidget = ancestor.widget as Column;
associatedText = _findTextInSiblings(columnWidget.children);
}
}
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.iconButton;
properties[WidgetProperty.enabled.name] = isEnabled;
properties[WidgetProperty.text.name] = associatedText;
}
//NavigationDestination
else if (element.widget is NavigationDestination) {
NavigationDestination navigationDestinationWidget =
element.widget as NavigationDestination;
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.navigationDestination;
properties[WidgetProperty.text.name] = navigationDestinationWidget.label;
}
//PopupMenuButton
else if (element.widget is PopupMenuButton) {
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.popupMenuButton;
}
//BottomNavigationBarItem
else if (element.widget is BottomNavigationBarItem) {
BottomNavigationBarItem bottomNavigationBarItem =
element.widget as BottomNavigationBarItem;
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.iconButton;
properties[WidgetProperty.text.name] = bottomNavigationBarItem.label;
}
//Switch
else if (element.widget is Switch) {
Switch switchWidget = element.widget as Switch;
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.switchButton;
properties[WidgetProperty.pressed.name] = switchWidget.onChanged != null;
properties[WidgetProperty.checked.name] = switchWidget.value;
}
//SegmentedButton
else if (element.widget is SegmentedButton) {
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.segmentedButton;
}
//ToggleButton
else if (element.widget is ToggleButtons) {
ToggleButtons toggleButtonsWidget = element.widget as ToggleButtons;
properties[WidgetProperty.className.name] =
RanorexSupportedClassName.toggleButton;
properties[WidgetProperty.pressed.name] =
toggleButtonsWidget.onPressed != null;
bool isAnyButtonSelected = false;
for (bool buttonState in toggleButtonsWidget.isSelected) {
if (buttonState) {
isAnyButtonSelected = true;
break;
}
}
properties[WidgetProperty.checked.name] = isAnyButtonSelected;
}
properties[WidgetProperty.accessibilityLabel.name] =
element.findAncestorWidgetOfExactType<Semantics>()?.properties.label ??
'';
return properties;
}