findScrollOffset static method

double? findScrollOffset([
  1. Finder? superTextFieldFinder
])

Finds and returns the scroll offset, in the direction of scrolling, within a SuperTextField.

By default, this method expects a single SuperTextField in the widget tree and finds it byType. To specify one SuperTextField among many, pass a superTextFieldFinder.

Implementation

static double? findScrollOffset([Finder? superTextFieldFinder]) {
  final finder = superTextFieldFinder ?? find.byType(SuperTextField);

  final fieldFinder = findInnerPlatformTextField(finder);
  final match = fieldFinder.evaluate().single.widget;

  if (match is SuperDesktopTextField) {
    final textScrollViewElement = find
        .descendant(
          of: finder,
          matching: find.byType(SuperTextFieldScrollview),
        )
        .evaluate()
        .single as StatefulElement;
    final textScrollView = textScrollViewElement.widget as SuperTextFieldScrollview;

    return textScrollView.scrollController.offset;
  }

  // Both mobile textfields use TextScrollView.
  final textScrollViewElement = find
      .descendant(
        of: finder,
        matching: find.byType(TextScrollView),
      )
      .evaluate()
      .single as StatefulElement;
  final textScrollView = textScrollViewElement.widget as TextScrollView;

  return textScrollView.textScrollController.scrollOffset;
}