controller property

ScrollController? controller
final

The ScrollController used to implement Scrollbar dragging.

If nothing is passed to controller, the default behavior is to automatically enable scrollbar dragging on the nearest ScrollController using PrimaryScrollController.of.

If a ScrollController is passed, then dragging on the scrollbar thumb will update the ScrollPosition attached to the controller. A stateful ancestor of this widget needs to manage the ScrollController and either pass it to a scrollable descendant or use a PrimaryScrollController to share it.

{@tool snippet} Here is an example of using the controller attribute to enable scrollbar dragging for multiple independent ListViews:

// (e.g. in a stateful widget)

final ScrollController controllerOne = ScrollController();
final ScrollController controllerTwo = ScrollController();

@override
Widget build(BuildContext context) {
  return Column(
    children: <Widget>[
      SizedBox(
       height: 200,
       child: CupertinoScrollbar(
         controller: controllerOne,
         child: ListView.builder(
           controller: controllerOne,
           itemCount: 120,
           itemBuilder: (BuildContext context, int index) => Text('item $index'),
         ),
       ),
     ),
     SizedBox(
       height: 200,
       child: CupertinoScrollbar(
         controller: controllerTwo,
         child: ListView.builder(
           controller: controllerTwo,
           itemCount: 120,
           itemBuilder: (BuildContext context, int index) => Text('list 2 item $index'),
         ),
       ),
     ),
   ],
  );
}

{@end-tool}

Implementation

final ScrollController? controller;