linked_scroll_controller
0.2.0, released 6 years ago by google.dev
Synchronizes scroll positions of multiple scrollable widgets.
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.
- two_dimensional_scrollables
Widgets for two‑dimensional scrolling like TableView and TreeView
94Compare - syncfusion_flutter_datepicker
A Flutter widget for selecting single dates, multiple dates, or date ranges with various calendar views.
91Compare - indexed_list_view
Infinite ListView that lets you programmatically jump instantly to any item by index.
82Compare - davi
Fully customized dataview widget with on-demand cell building and bidirectional scroll bars.
78Compare
Works with
Packages commonly used together with linked_scroll_controller: ones it builds on, ones built on it, and its own family.
- flutter_code_editorBuilt on linked_scroll_controllerA customizable code field widget supporting syntax highlighting and code folding.
- code_text_fieldBuilt on linked_scroll_controllerA customizable code text field supporting syntax highlighting and scrolling.
- flutter_expandable_tableBuilt on linked_scroll_controllerA Flutter widget for creating an expandable table with fixed headers and first columns.
- flutter_ganttBuilt on linked_scroll_controllerInteractive Gantt chart widget for Flutter