Ok after talking to @pskink comment I reached the solution
void initState() {
super.initState();
// other code
SchedulerBinding.instance.addPostFrameCallback((timeStamp) {
context.findRenderObject()?.visitChildren(_visitor);
});
}
void _visitor(RenderObject child) {
if (child is RenderEditable) {
setState(() {
// assign RenderEditable node to widget state
// make sure you get the correct child, for me there is only one textfield for testing
reEdt = child;
});
return;
}
child.visitChildren(_visitor);
}
// call when inserting text and want to scroll to cursor
void scrollToSelection(TextSelection selection) {
// find local rect of cursor or starting selection in case of selecting text
final localRect = reEdt?.getLocalRectForCaret(TextPosition(offset: selection.baseOffset));
if (localRect == null) return;
scrollController.jumpTo(localRect.top);
}
and don't forget to assign scrollController
to TextField