controller property Null safety

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.

Here is an example of using the controller parameter to enable scrollbar dragging for multiple independent ListViews:
final ScrollController _controllerOne = ScrollController();
final ScrollController _controllerTwo = ScrollController();

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'),
         ),
       ),
     ),
   ],
  );
}

Implementation

final ScrollController? controller;