getProperties method

  1. @override
Map<String, dynamic> getProperties({
  1. Element? ancestor,
})
override

Implementation

@override
Map<String, dynamic> getProperties({Element? ancestor}) {
  Map<String, dynamic> properties = super.getProperties(ancestor: ancestor);
  properties[WidgetProperty.className.name] =
      RanorexSupportedClassName.singleChildScrollView;

  ScrollController? scrollController;
  Axis scrollDirection = Axis.vertical;

  if (element.widget is SingleChildScrollView) {
    SingleChildScrollView scrollView = element.widget as SingleChildScrollView;
    scrollController = scrollView.controller;
    scrollDirection = scrollView.scrollDirection;
    properties[WidgetProperty.containerType.name] =
        scrollView.runtimeType.toString();
  } else if (element.widget is CarouselView) {
    CarouselView carouselView = element.widget as CarouselView;
    scrollController = carouselView.controller;
    scrollDirection = carouselView.scrollDirection;
    properties[WidgetProperty.containerType.name] =
        carouselView.runtimeType.toString();
  }

  if (scrollController != null) {
      RenderBox renderBox = element.renderObject as RenderBox;
      Offset offset = renderBox.localToGlobal(Offset.zero);

      if (scrollDirection == Axis.horizontal) {
        properties[WidgetProperty.contentOffsetX.name] =
            scrollController.position.pixels.toInt();
        properties[WidgetProperty.contentOffsetY.name] = offset.dy.toInt();
      } else if (scrollDirection == Axis.vertical) {
        properties[WidgetProperty.contentOffsetX.name] = offset.dx.toInt();
        properties[WidgetProperty.contentOffsetY.name] =
            scrollController.position.pixels.toInt();
      }
  }

  return properties;
}