Enable initializing Scrollable scrollOffset
Added Scrollable named parameter initializeScrollOffset. If unspecified, then the initial value of scrollOffset is 0.0 as before.
This commit is contained in:
parent
e1933af37e
commit
18b78cfafa
@ -35,18 +35,22 @@ abstract class Scrollable extends StatefulComponent {
|
|||||||
|
|
||||||
Scrollable({
|
Scrollable({
|
||||||
Key key,
|
Key key,
|
||||||
|
this.initialScrollOffset,
|
||||||
this.scrollDirection: ScrollDirection.vertical
|
this.scrollDirection: ScrollDirection.vertical
|
||||||
}) : super(key: key) {
|
}) : super(key: key) {
|
||||||
assert(scrollDirection == ScrollDirection.vertical ||
|
assert(scrollDirection == ScrollDirection.vertical ||
|
||||||
scrollDirection == ScrollDirection.horizontal);
|
scrollDirection == ScrollDirection.horizontal);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double initialScrollOffset;
|
||||||
ScrollDirection scrollDirection;
|
ScrollDirection scrollDirection;
|
||||||
|
|
||||||
AnimatedSimulation _toEndAnimation; // See _startToEndAnimation()
|
AnimatedSimulation _toEndAnimation; // See _startToEndAnimation()
|
||||||
ValueAnimation<double> _toOffsetAnimation; // Started by scrollTo()
|
ValueAnimation<double> _toOffsetAnimation; // Started by scrollTo()
|
||||||
|
|
||||||
void initState() {
|
void initState() {
|
||||||
|
if (initialScrollOffset is double)
|
||||||
|
_scrollOffset = initialScrollOffset;
|
||||||
_toEndAnimation = new AnimatedSimulation(_setScrollOffset);
|
_toEndAnimation = new AnimatedSimulation(_setScrollOffset);
|
||||||
_toOffsetAnimation = new ValueAnimation<double>()
|
_toOffsetAnimation = new ValueAnimation<double>()
|
||||||
..addListener(() {
|
..addListener(() {
|
||||||
@ -261,8 +265,13 @@ class ScrollableViewport extends Scrollable {
|
|||||||
ScrollableViewport({
|
ScrollableViewport({
|
||||||
Key key,
|
Key key,
|
||||||
this.child,
|
this.child,
|
||||||
|
double initialScrollOffset,
|
||||||
ScrollDirection scrollDirection: ScrollDirection.vertical
|
ScrollDirection scrollDirection: ScrollDirection.vertical
|
||||||
}) : super(key: key, scrollDirection: scrollDirection);
|
}) : super(
|
||||||
|
key: key,
|
||||||
|
scrollDirection: scrollDirection,
|
||||||
|
initialScrollOffset: initialScrollOffset
|
||||||
|
);
|
||||||
|
|
||||||
Widget child;
|
Widget child;
|
||||||
|
|
||||||
@ -312,10 +321,12 @@ class ScrollableViewport extends Scrollable {
|
|||||||
class Block extends Component {
|
class Block extends Component {
|
||||||
Block(this.children, {
|
Block(this.children, {
|
||||||
Key key,
|
Key key,
|
||||||
|
this.initialScrollOffset,
|
||||||
this.scrollDirection: ScrollDirection.vertical
|
this.scrollDirection: ScrollDirection.vertical
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final List<Widget> children;
|
final List<Widget> children;
|
||||||
|
final double initialScrollOffset;
|
||||||
final ScrollDirection scrollDirection;
|
final ScrollDirection scrollDirection;
|
||||||
|
|
||||||
BlockDirection get _direction {
|
BlockDirection get _direction {
|
||||||
@ -326,6 +337,7 @@ class Block extends Component {
|
|||||||
|
|
||||||
Widget build() {
|
Widget build() {
|
||||||
return new ScrollableViewport(
|
return new ScrollableViewport(
|
||||||
|
initialScrollOffset: initialScrollOffset,
|
||||||
scrollDirection: scrollDirection,
|
scrollDirection: scrollDirection,
|
||||||
child: new BlockBody(children, direction: _direction)
|
child: new BlockBody(children, direction: _direction)
|
||||||
);
|
);
|
||||||
@ -340,10 +352,11 @@ class Block extends Component {
|
|||||||
abstract class ScrollableWidgetList extends Scrollable {
|
abstract class ScrollableWidgetList extends Scrollable {
|
||||||
ScrollableWidgetList({
|
ScrollableWidgetList({
|
||||||
Key key,
|
Key key,
|
||||||
|
double initialScrollOffset,
|
||||||
ScrollDirection scrollDirection: ScrollDirection.vertical,
|
ScrollDirection scrollDirection: ScrollDirection.vertical,
|
||||||
this.itemExtent,
|
this.itemExtent,
|
||||||
this.padding
|
this.padding
|
||||||
}) : super(key: key, scrollDirection: scrollDirection) {
|
}) : super(key: key, initialScrollOffset: initialScrollOffset, scrollDirection: scrollDirection) {
|
||||||
assert(itemExtent != null);
|
assert(itemExtent != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,13 +501,19 @@ typedef Widget ItemBuilder<T>(T item);
|
|||||||
class ScrollableList<T> extends ScrollableWidgetList {
|
class ScrollableList<T> extends ScrollableWidgetList {
|
||||||
ScrollableList({
|
ScrollableList({
|
||||||
Key key,
|
Key key,
|
||||||
|
double initialScrollOffset,
|
||||||
ScrollDirection scrollDirection: ScrollDirection.vertical,
|
ScrollDirection scrollDirection: ScrollDirection.vertical,
|
||||||
this.items,
|
this.items,
|
||||||
this.itemBuilder,
|
this.itemBuilder,
|
||||||
this.itemsWrap: false,
|
this.itemsWrap: false,
|
||||||
double itemExtent,
|
double itemExtent,
|
||||||
EdgeDims padding
|
EdgeDims padding
|
||||||
}) : super(key: key, scrollDirection: scrollDirection, itemExtent: itemExtent, padding: padding);
|
}) : super(
|
||||||
|
key: key,
|
||||||
|
initialScrollOffset: initialScrollOffset,
|
||||||
|
scrollDirection: scrollDirection,
|
||||||
|
itemExtent: itemExtent,
|
||||||
|
padding: padding);
|
||||||
|
|
||||||
List<T> items;
|
List<T> items;
|
||||||
ItemBuilder<T> itemBuilder;
|
ItemBuilder<T> itemBuilder;
|
||||||
@ -526,6 +545,7 @@ class ScrollableList<T> extends ScrollableWidgetList {
|
|||||||
class PageableList<T> extends ScrollableList<T> {
|
class PageableList<T> extends ScrollableList<T> {
|
||||||
PageableList({
|
PageableList({
|
||||||
Key key,
|
Key key,
|
||||||
|
double initialScrollOffset,
|
||||||
ScrollDirection scrollDirection: ScrollDirection.horizontal,
|
ScrollDirection scrollDirection: ScrollDirection.horizontal,
|
||||||
List<T> items,
|
List<T> items,
|
||||||
ItemBuilder<T> itemBuilder,
|
ItemBuilder<T> itemBuilder,
|
||||||
@ -536,6 +556,7 @@ class PageableList<T> extends ScrollableList<T> {
|
|||||||
this.curve: ease
|
this.curve: ease
|
||||||
}) : super(
|
}) : super(
|
||||||
key: key,
|
key: key,
|
||||||
|
initialScrollOffset: initialScrollOffset,
|
||||||
scrollDirection: scrollDirection,
|
scrollDirection: scrollDirection,
|
||||||
items: items,
|
items: items,
|
||||||
itemBuilder: itemBuilder,
|
itemBuilder: itemBuilder,
|
||||||
@ -587,10 +608,11 @@ class PageableList<T> extends ScrollableList<T> {
|
|||||||
class ScrollableMixedWidgetList extends Scrollable {
|
class ScrollableMixedWidgetList extends Scrollable {
|
||||||
ScrollableMixedWidgetList({
|
ScrollableMixedWidgetList({
|
||||||
Key key,
|
Key key,
|
||||||
|
double initialScrollOffset,
|
||||||
this.builder,
|
this.builder,
|
||||||
this.token,
|
this.token,
|
||||||
this.layoutState
|
this.layoutState
|
||||||
}) : super(key: key);
|
}) : super(key: key, initialScrollOffset: initialScrollOffset);
|
||||||
|
|
||||||
IndexedBuilder builder;
|
IndexedBuilder builder;
|
||||||
Object token;
|
Object token;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user