-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial commit of LinkedScrollController PiperOrigin-RevId: 220688858 * Correct typos in readme.md PiperOrigin-RevId: 220697252 * Fix travis.sh Closes #4 PiperOrigin-RevId: 220704036
- Loading branch information
1 parent
abc4781
commit 148fcbe
Showing
8 changed files
with
735 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
language: dart | ||
sudo: false | ||
dart: | ||
- stable | ||
- dev | ||
os: linux | ||
before_script: | ||
- git clone https://github.com/flutter/flutter.git --depth 1 | ||
- export PATH=`pwd`/flutter/bin:`pwd`/flutter/bin/cache/dart-sdk/bin:$PATH | ||
- flutter doctor | ||
script: ./tool/travis.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright 2018 the Dart project authors. | ||
// | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file or at | ||
// https://developers.google.com/open-source/licenses/bsd | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_widgets/flutter_widgets.dart'; | ||
|
||
/// Gallery page for demoing the [LinkedScrollControllerGroup]. | ||
class LinkedScrollablesPage extends StatefulWidget { | ||
@override | ||
_LinkedScrollablesPageState createState() => _LinkedScrollablesPageState(); | ||
} | ||
|
||
class _LinkedScrollablesPageState extends State<LinkedScrollablesPage> { | ||
LinkedScrollControllerGroup _controllers; | ||
ScrollController _letters; | ||
ScrollController _numbers; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
_controllers = LinkedScrollControllerGroup(); | ||
_letters = _controllers.addAndGet(); | ||
_numbers = _controllers.addAndGet(); | ||
} | ||
|
||
@override | ||
void dispose() { | ||
_letters.dispose(); | ||
_numbers.dispose(); | ||
super.dispose(); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: new AppBar(title: new Text('Linked Scrollables')), | ||
body: Row( | ||
children: [ | ||
Expanded( | ||
child: ListView( | ||
controller: _letters, | ||
children: <Widget>[ | ||
_Tile('Hello A'), | ||
_Tile('Hello B'), | ||
_Tile('Hello C'), | ||
_Tile('Hello D'), | ||
_Tile('Hello E'), | ||
], | ||
), | ||
), | ||
Expanded( | ||
child: ListView( | ||
controller: _numbers, | ||
children: <Widget>[ | ||
_Tile('Hello 1'), | ||
_Tile('Hello 2'), | ||
_Tile('Hello 3'), | ||
_Tile('Hello 4'), | ||
_Tile('Hello 5'), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
|
||
class _Tile extends StatelessWidget { | ||
final String caption; | ||
|
||
_Tile(this.caption); | ||
|
||
@override | ||
Widget build(_) => Container( | ||
margin: const EdgeInsets.all(8.0), | ||
padding: const EdgeInsets.all(8.0), | ||
height: 250.0, | ||
child: Center(child: Text(caption)), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# linked_scroll_controller | ||
|
||
This package provides a way to set up a set of scrollable widgets whose | ||
scrolling is synchronized. The set can be stable across the lifetime of the | ||
containing screen, or can change dynamically (for example, a vertically | ||
scrolling `ListView.builder()` whose items are Scrollables that scroll | ||
horizontally in unison). | ||
|
||
**If you add controllers dynamically, the corresponding scrollables must be | ||
given unique keys to avoid the scroll offset going out of sync.** | ||
|
||
# Example usage | ||
|
||
The code below sets up two side-by-side `ListView`s that scroll in unison. | ||
|
||
```dart | ||
class LinkedScrollables extends StatefulWidget { | ||
@override | ||
_LinkedScrollablesState createState() => _LinkedScrollablesState(); | ||
} | ||
class _LinkedScrollablesState extends State<LinkedScrollables> { | ||
LinkedScrollControllerGroup _controllers; | ||
ScrollController _letters; | ||
ScrollController _numbers; | ||
@override | ||
void initState() { | ||
super.initState(); | ||
_controllers = LinkedScrollControllerGroup(); | ||
_letters = _controllers.addAndGet(); | ||
_numbers = _controllers.addAndGet(); | ||
} | ||
@override | ||
void dispose() { | ||
_letters.dispose(); | ||
_numbers.dispose(); | ||
super.dispose(); | ||
} | ||
@override | ||
Widget build(BuildContext context) { | ||
return Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: Row( | ||
children: [ | ||
Expanded( | ||
child: ListView( | ||
controller: _letters, | ||
children: <Widget>[ | ||
_Tile('Hello A'), | ||
_Tile('Hello B'), | ||
_Tile('Hello C'), | ||
_Tile('Hello D'), | ||
_Tile('Hello E'), | ||
], | ||
), | ||
), | ||
Expanded( | ||
child: ListView( | ||
controller: _numbers, | ||
children: <Widget>[ | ||
_Tile('Hello 1'), | ||
_Tile('Hello 2'), | ||
_Tile('Hello 3'), | ||
_Tile('Hello 4'), | ||
_Tile('Hello 5'), | ||
], | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
class _Tile extends StatelessWidget { | ||
final String caption; | ||
_Tile(this.caption); | ||
@override | ||
Widget build(_) => Container( | ||
margin: const EdgeInsets.all(8.0), | ||
padding: const EdgeInsets.all(8.0), | ||
height: 250.0, | ||
child: Center(child: Text(caption)), | ||
); | ||
} | ||
``` |
Oops, something went wrong.