Commit a8b4e938 authored by Hans Muller's avatar Hans Muller

Merge pull request #2796 from HansMuller/ali_demo

Fix _LazyWidgetProvider indexing, move Ali Connors
parents 24bf14c5 70550a7a
......@@ -17,6 +17,7 @@ import '../demo/date_picker_demo.dart';
import '../demo/dialog_demo.dart';
import '../demo/drop_down_demo.dart';
import '../demo/fitness_demo.dart';
import '../demo/flexible_space_demo.dart';
import '../demo/grid_list_demo.dart';
import '../demo/icons_demo.dart';
import '../demo/leave_behind_demo.dart';
......@@ -103,6 +104,7 @@ class GalleryHomeState extends State<GalleryHome> {
image: 'assets/section_components.png',
colors: Colors.amber,
demos: <GalleryDemo>[
new GalleryDemo(title: 'App Bar', builder: () => new FlexibleSpaceDemo()),
new GalleryDemo(title: 'Buttons', builder: () => new ButtonsDemo()),
new GalleryDemo(title: 'Buttons: Floating Action Button', builder: () => new TabsFabDemo()),
new GalleryDemo(title: 'Cards', builder: () => new CardsDemo()),
......
......@@ -297,7 +297,8 @@ class _LazyWidgetProvider extends _WidgetProvider {
@override
Widget getChild(int i) {
int n = _length ?? _widgets.length;
return _widgets[(i % n).abs()];
final int childCount = virtualChildCount;
final int index = childCount != null ? (i % childCount).abs() : i;
return _widgets[index - _base];
}
}
......@@ -158,4 +158,51 @@ void main() {
callbackTracker.clear();
});
});
test('ScrollableLazyList 10 items, 2-3 items visible', () {
testWidgets((WidgetTester tester) {
List<int> callbackTracker = <int>[];
// The root view is 800x600 in the test environment and our list
// items are 300 tall. Scrolling should cause two or three items
// to be built.
ItemListBuilder itemBuilder = (BuildContext context, int start, int count) {
List<Widget> result = <Widget>[];
for (int index = start; index < start + count; index += 1) {
callbackTracker.add(index);
result.add(new Text('$index', key: new ValueKey<int>(index)));
}
return result;
};
GlobalKey<ScrollableState<ScrollableLazyList>> scrollableKey = new GlobalKey<ScrollableState<ScrollableLazyList>>();
Widget testWidget = new ScrollableLazyList(
key: scrollableKey,
itemBuilder: itemBuilder,
itemExtent: 300.0,
itemCount: 10
);
tester.pumpWidget(testWidget);
expect(callbackTracker, equals([0, 1]));
callbackTracker.clear();
scrollableKey.currentState.scrollTo(150.0);
tester.pumpWidget(testWidget);
expect(callbackTracker, equals([0, 1, 2]));
callbackTracker.clear();
scrollableKey.currentState.scrollTo(600.0);
tester.pumpWidget(testWidget);
expect(callbackTracker, equals([2, 3]));
callbackTracker.clear();
scrollableKey.currentState.scrollTo(750.0);
tester.pumpWidget(testWidget);
expect(callbackTracker, equals([2, 3, 4]));
callbackTracker.clear();
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment