From 2e9986614d48b81983fd4f3e3094d72c3a0b3bae Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 6 Feb 2017 16:13:48 -0800 Subject: [PATCH] Use sliver-based scrolling in more places (#7893) In particular, we now use ListView in the about dialog. --- dev/benchmarks/complex_layout/lib/main.dart | 29 +++++-------------- packages/flutter/lib/src/material/about.dart | 15 +++++----- .../test/widgets/scroll_interaction_test.dart | 14 ++++----- .../scrollable_list_with_inherited_test.dart | 4 +-- 4 files changed, 24 insertions(+), 38 deletions(-) diff --git a/dev/benchmarks/complex_layout/lib/main.dart b/dev/benchmarks/complex_layout/lib/main.dart index a7dac64039..282e579ef1 100644 --- a/dev/benchmarks/complex_layout/lib/main.dart +++ b/dev/benchmarks/complex_layout/lib/main.dart @@ -52,24 +52,6 @@ class ComplexLayout extends StatefulWidget { static ComplexLayoutState of(BuildContext context) => context.ancestorStateOfType(const TypeMatcher()); } -class FancyItemDelegate extends LazyBlockDelegate { - @override - Widget buildItem(BuildContext context, int index) { - if (index % 2 == 0) - return new FancyImageItem(index, key: new ValueKey(index)); - else - return new FancyGalleryItem(index, key: new ValueKey(index)); - } - - @override - bool shouldRebuild(FancyItemDelegate oldDelegate) => false; - - @override - double estimateTotalExtent(int firstIndex, int lastIndex, double minOffset, double firstStartOffset, double lastEndOffset) { - return double.INFINITY; - } -} - class ComplexLayoutState extends State { @override Widget build(BuildContext context) { @@ -91,10 +73,15 @@ class ComplexLayoutState extends State { body: new Column( children: [ new Expanded( - child: new LazyBlock( + child: new ListView.builder( key: new Key('main-scroll'), // this key is used by the driver test - delegate: new FancyItemDelegate(), - ) + itemBuilder: (BuildContext context, int index) { + if (index % 2 == 0) + return new FancyImageItem(index, key: new ValueKey(index)); + else + return new FancyGalleryItem(index, key: new ValueKey(index)); + }, + ), ), new BottomBar(), ], diff --git a/packages/flutter/lib/src/material/about.dart b/packages/flutter/lib/src/material/about.dart index f7f2366820..8a0458fccd 100644 --- a/packages/flutter/lib/src/material/about.dart +++ b/packages/flutter/lib/src/material/about.dart @@ -447,15 +447,14 @@ class _LicensePageState extends State { ), body: new DefaultTextStyle( style: Theme.of(context).textTheme.caption, - child: new Scrollbar( - child: new LazyBlock( + child: new Scrollbar2( + child: new ListView( padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0), - delegate: new LazyBlockChildren( - children: contents - ) - ) - ) - ) + shrinkWrap: true, + children: contents, + ), + ), + ), ); } } diff --git a/packages/flutter/test/widgets/scroll_interaction_test.dart b/packages/flutter/test/widgets/scroll_interaction_test.dart index c26f677837..06177b862d 100644 --- a/packages/flutter/test/widgets/scroll_interaction_test.dart +++ b/packages/flutter/test/widgets/scroll_interaction_test.dart @@ -7,29 +7,29 @@ import 'package:flutter/widgets.dart'; void main() { testWidgets('Scroll flings twice in a row does not crash', (WidgetTester tester) async { - await tester.pumpWidget(new Block( + await tester.pumpWidget(new ListView( children: [ new Container(height: 100000.0) ] )); - ScrollableState scrollable = - tester.state(find.byType(Scrollable)); + Scrollable2State scrollable = + tester.state(find.byType(Scrollable2)); - expect(scrollable.scrollOffset, equals(0.0)); + expect(scrollable.position.pixels, equals(0.0)); await tester.flingFrom(const Point(200.0, 300.0), const Offset(0.0, -200.0), 500.0); await tester.pump(); await tester.pump(const Duration(seconds: 5)); - expect(scrollable.scrollOffset, greaterThan(0.0)); + expect(scrollable.position.pixels, greaterThan(0.0)); - double oldOffset = scrollable.scrollOffset; + double oldOffset = scrollable.position.pixels; await tester.flingFrom(const Point(200.0, 300.0), const Offset(0.0, -200.0), 500.0); await tester.pump(); await tester.pump(const Duration(seconds: 5)); - expect(scrollable.scrollOffset, greaterThan(oldOffset)); + expect(scrollable.position.pixels, greaterThan(oldOffset)); }); } diff --git a/packages/flutter/test/widgets/scrollable_list_with_inherited_test.dart b/packages/flutter/test/widgets/scrollable_list_with_inherited_test.dart index 662a1837d6..023e1f2679 100644 --- a/packages/flutter/test/widgets/scrollable_list_with_inherited_test.dart +++ b/packages/flutter/test/widgets/scrollable_list_with_inherited_test.dart @@ -21,8 +21,8 @@ Widget buildCard(BuildContext context, int index) { } Widget buildFrame() { - return new LazyBlock( - delegate: new LazyBlockBuilder(builder: buildCard) + return new ListView.builder( + itemBuilder: buildCard, ); }