Skip to content
pubscout

linked_scroll_controller

0.2.0, released 6 years ago by google.dev

Synchronizes scroll positions of multiple scrollable widgets.

WASM-readyRepository archivedQuiet but busy
$ flutter pub add linked_scroll_controller
Source repository

What it does

Provides a controller group that keeps several ScrollControllers in sync. When one scrolls, all others jump to the same offset. It supports dynamic addition of controllers and offers animateTo/jumpTo for the group.

AI-written summary of version 0.2.0, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need two or more scrollable widgets to move together, e.g., side‑by‑side lists or horizontally scrolling items inside a vertical list.
  • You want a simple, null‑safe solution without external dependencies or code generation.
  • You are building a Flutter app that targets Android, iOS, web, macOS, Windows, or Linux.
  • You prefer an imperative API that works directly with ScrollControllers.

Skip it when

  • You need complex scrolling behavior like parallax or nested scroll physics that require custom scroll physics.
  • You are already using a state‑management solution that handles scroll positions differently and you want to avoid duplicate controllers.

Strengths

  • Simple API, no extra dependencies.
  • Fully null‑safe and stable release.
  • Supports dynamic controller addition with unique keys.
  • Provides group animateTo/jumpTo for coordinated scrolling.

Weaknesses

  • Only synchronizes scroll offset, no advanced physics or animations.
  • Requires unique keys when adding controllers dynamically to avoid offset drift.
  • Limited to scrollable widgets; not a general state‑management tool.

Setup

Kind
Flutter widgets
Effort
Low
Code generation
No
Direct dependencies
0
class LinkedScrollables extends StatefulWidget {
  @override
  _LinkedScrollablesState createState() => _LinkedScrollablesState();
}

class _LinkedScrollablesState extends State<LinkedScrollables> {
  final LinkedScrollControllerGroup _controllers = LinkedScrollControllerGroup();
  late final ScrollController _letters;
  late final ScrollController _numbers;

  @override
  void initState() {
    super.initState();
    _letters = _controllers.addAndGet();
    _numbers = _controllers.addAndGet();
  }

  @override
  void dispose() {
    _letters.dispose();
    _numbers.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Expanded(
          child: ListView(controller: _letters, children: const [
            _Tile('Hello A'),
            _Tile('Hello B'),
            _Tile('Hello C'),
            _Tile('Hello D'),
            _Tile('Hello E'),
          ]),
        ),
        Expanded(
          child: ListView(controller: _numbers, children: const [
            _Tile('Hello 1'),
            _Tile('Hello 2'),
            _Tile('Hello 3'),
            _Tile('Hello 4'),
            _Tile('Hello 5'),
          ]),
        ),
      ],
    );
  }
}

class _Tile extends StatelessWidget {
  final String caption;
  const _Tile(this.caption);
  @override
  Widget build(BuildContext context) => Container(
    margin: const EdgeInsets.all(8.0),
    padding: const EdgeInsets.all(8.0),
    height: 250.0,
    child: Center(child: Text(caption)),
  );
}

Alternatives

Packages that do the same job and could replace linked_scroll_controller.

Works with

Packages commonly used together with linked_scroll_controller: ones it builds on, ones built on it, and its own family.