Fix the confusing-zero case with NestedScrollView. (#14133)

* Fix the confusing-zero case with NestedScrollView.

* Update mock_canvas.dart

* Update tabs_demo.dart

* more tweaks
This commit is contained in:
Ian Hickson
2018-01-18 20:21:15 -08:00
committed by GitHub
parent c5cbc0df3a
commit 3ac9449ad4
15 changed files with 1293 additions and 127 deletions

View File

@@ -13,6 +13,8 @@ class _Page {
_Page({ this.label });
final String label;
String get id => label[0];
@override
String toString() => '$runtimeType("$label")';
}
class _CardData {
@@ -69,6 +71,13 @@ final Map<_Page, List<_CardData>> _allPages = <_Page, List<_CardData>>{
imageAsset: 'shrine/products/chucks.png',
imageAssetPackage: _kGalleryAssetsPackage,
),
],
new _Page(label: 'RIGHT'): <_CardData>[
const _CardData(
title: 'Beachball',
imageAsset: 'shrine/products/beachball.png',
imageAssetPackage: _kGalleryAssetsPackage,
),
const _CardData(
title: 'Dipped Brush',
imageAsset: 'shrine/products/brush.png',
@@ -80,13 +89,6 @@ final Map<_Page, List<_CardData>> _allPages = <_Page, List<_CardData>>{
imageAssetPackage: _kGalleryAssetsPackage,
),
],
new _Page(label: 'RIGHT'): <_CardData>[
const _CardData(
title: 'Beachball',
imageAsset: 'shrine/products/beachball.png',
imageAssetPackage: _kGalleryAssetsPackage,
),
],
};
class _CardDataItem extends StatelessWidget {
@@ -121,7 +123,10 @@ class _CardDataItem extends StatelessWidget {
),
),
new Center(
child: new Text(data.title, style: Theme.of(context).textTheme.title),
child: new Text(
data.title,
style: Theme.of(context).textTheme.title,
),
),
],
),
@@ -141,13 +146,18 @@ class TabsDemo extends StatelessWidget {
body: new NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
new SliverAppBar(
title: const Text('Tabs and scrolling'),
pinned: true,
expandedHeight: 150.0,
forceElevated: innerBoxIsScrolled,
bottom: new TabBar(
tabs: _allPages.keys.map((_Page page) => new Tab(text: page.label)).toList(),
new SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
child: new SliverAppBar(
title: const Text('Tabs and scrolling'),
pinned: true,
expandedHeight: 150.0,
forceElevated: innerBoxIsScrolled,
bottom: new TabBar(
tabs: _allPages.keys.map(
(_Page page) => new Tab(text: page.label),
).toList(),
),
),
),
];
@@ -157,15 +167,41 @@ class TabsDemo extends StatelessWidget {
return new SafeArea(
top: false,
bottom: false,
child: new ListView(
padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16.0),
itemExtent: _CardDataItem.height,
children: _allPages[page].map((_CardData data) {
return new Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: new _CardDataItem(page: page, data: data),
child: new Builder(
builder: (BuildContext context) {
return new CustomScrollView(
key: new PageStorageKey<_Page>(page),
slivers: <Widget>[
new SliverOverlapInjector(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
),
new SliverPadding(
padding: const EdgeInsets.symmetric(
vertical: 8.0,
horizontal: 16.0,
),
sliver: new SliverFixedExtentList(
itemExtent: _CardDataItem.height,
delegate: new SliverChildBuilderDelegate(
(BuildContext context, int index) {
final _CardData data = _allPages[page][index];
return new Padding(
padding: const EdgeInsets.symmetric(
vertical: 8.0,
),
child: new _CardDataItem(
page: page,
data: data,
),
);
},
childCount: _allPages[page].length,
),
),
),
],
);
}).toList(),
},
),
);
}).toList(),