useScrollController function

ScrollController useScrollController({
  1. int initialOffset = 0,
  2. List<Object?>? keys,
})

A ScrollController of the first build, whose scrollable starts at initialOffset, made anew when the keys of a build differ from the last one's.

HookBuilder(
  builder: (context) {
    final controller = useScrollController();
    return KeyBindings({
      'g': () => controller.jumpTo(0),
    }, child: SingleChildScrollView(
      controller: controller,
      child: Text(files.join('\n')),
    ));
  },
)

Implementation

ScrollController useScrollController({
  int initialOffset = 0,
  List<Object?>? keys,
}) => use(
  _ControllerHook(
    () => ScrollController(initialOffset: initialOffset),
    keys,
    'useScrollController',
  ),
);