| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:math' as math; | 5 import 'dart:math' as math; |
| 6 | 6 |
| 7 import 'package:vector_math/vector_math.dart'; | 7 import 'package:vector_math/vector_math.dart'; |
| 8 | 8 |
| 9 import '../animation/scroll_behavior.dart'; | 9 import '../animation/scroll_behavior.dart'; |
| 10 import 'basic.dart'; | 10 import 'basic.dart'; |
| 11 import 'scrollable.dart'; | 11 import 'scrollable.dart'; |
| 12 | 12 |
| 13 abstract class FixedHeightScrollable extends Scrollable { | 13 abstract class FixedHeightScrollable extends Scrollable { |
| 14 | 14 |
| 15 FixedHeightScrollable({ String key, this.itemHeight, Color backgroundColor }) | 15 final EdgeDims padding; |
| 16 |
| 17 FixedHeightScrollable({ String key, this.itemHeight, Color backgroundColor, th
is.padding }) |
| 16 : super(key: key, backgroundColor: backgroundColor) { | 18 : super(key: key, backgroundColor: backgroundColor) { |
| 17 assert(itemHeight != null); | 19 assert(itemHeight != null); |
| 18 } | 20 } |
| 19 | 21 |
| 20 double itemHeight; | 22 double itemHeight; |
| 21 | 23 |
| 22 void syncFields(FixedHeightScrollable source) { | 24 void syncFields(FixedHeightScrollable source) { |
| 23 itemHeight = source.itemHeight; | 25 itemHeight = source.itemHeight; |
| 24 super.syncFields(source); | 26 super.syncFields(source); |
| 25 } | 27 } |
| 26 | 28 |
| 27 ScrollBehavior createScrollBehavior() => new OverscrollBehavior(); | 29 ScrollBehavior createScrollBehavior() => new OverscrollBehavior(); |
| 28 OverscrollBehavior get scrollBehavior => super.scrollBehavior; | 30 OverscrollBehavior get scrollBehavior => super.scrollBehavior; |
| 29 | 31 |
| 30 int _itemCount = 0; | 32 int _itemCount = 0; |
| 31 int get itemCount => _itemCount; | 33 int get itemCount => _itemCount; |
| 32 void set itemCount (int value) { | 34 void set itemCount (int value) { |
| 33 if (_itemCount != value) { | 35 if (_itemCount != value) { |
| 34 _itemCount = value; | 36 _itemCount = value; |
| 35 scrollBehavior.contentsHeight = itemHeight * _itemCount; | 37 double contentsHeight = itemHeight * _itemCount; |
| 38 if (padding != null) |
| 39 contentsHeight += padding.top + padding.bottom; |
| 40 scrollBehavior.contentsHeight = contentsHeight; |
| 36 } | 41 } |
| 37 } | 42 } |
| 38 | 43 |
| 39 double _height; | 44 double _height; |
| 40 void _handleSizeChanged(Size newSize) { | 45 void _handleSizeChanged(Size newSize) { |
| 41 setState(() { | 46 setState(() { |
| 42 _height = newSize.height; | 47 _height = newSize.height; |
| 43 scrollBehavior.containerHeight = _height; | 48 scrollBehavior.containerHeight = _height; |
| 44 }); | 49 }); |
| 45 } | 50 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 69 } | 74 } |
| 70 | 75 |
| 71 List<Widget> items = buildItems(itemShowIndex, itemShowCount); | 76 List<Widget> items = buildItems(itemShowIndex, itemShowCount); |
| 72 assert(items.every((item) => item.key != null)); | 77 assert(items.every((item) => item.key != null)); |
| 73 | 78 |
| 74 return new SizeObserver( | 79 return new SizeObserver( |
| 75 callback: _handleSizeChanged, | 80 callback: _handleSizeChanged, |
| 76 child: new ClipRect( | 81 child: new ClipRect( |
| 77 child: new Transform( | 82 child: new Transform( |
| 78 transform: transform, | 83 transform: transform, |
| 79 child: new Block(items) | 84 child: new Container( |
| 85 padding: padding, |
| 86 child: new Block(items) |
| 87 ) |
| 80 ) | 88 ) |
| 81 ) | 89 ) |
| 82 ); | 90 ); |
| 83 } | 91 } |
| 84 | 92 |
| 85 List<Widget> buildItems(int start, int count); | 93 List<Widget> buildItems(int start, int count); |
| 86 | 94 |
| 87 } | 95 } |
| OLD | NEW |