【发布时间】:2018-06-30 07:41:27
【问题描述】:
我希望在顶部有一个不可滚动部分的视图,例如在底部有一个标签栏,我可以滚动到顶部以显示项目列表并能够在列表内滚动项目。
为此,我使用了一个 CustomScrollView,暂时用一个 sliver 网格代替图像,一个 sliver 应用程序栏用于标签栏,一个 sliverFixedExtentList 用于列表。
Widget build(BuildContext context) {
return new Scaffold(
body: new CustomScrollView(
slivers: <Widget>[
new SliverGrid(
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(
childAspectRatio: 0.58,
crossAxisCount: 1,
),
delegate: new SliverChildBuilderDelegate(
(BuildContext context, int index) {
return new Container(
color: Colors.red,
child: new Container(
color: Colors.green,
child: new Text('IMG HERE'),
)
);
},
childCount: 1,
),
),
new SliverAppBar(
title: new Text("title"),
floating: false,
pinned: true,
primary: true,
actions: <Widget>[
new IconButton(
icon: const Icon(Icons.arrow_upward),
onPressed: () {
},
),
],
bottom: new TabBar(
controller: _tabController,
isScrollable: true,
tabs: _bars,
),
),
new SliverFixedExtentList(
itemExtent: 100.0,
delegate: new SliverChildBuilderDelegate(
(BuildContext context, int index) {
return new Container(
alignment: Alignment.center,
color: Colors.lightGreen[100 * (index % 9)],
child: new Text('list item $index'),
);
},
),
),
],
)
);
}
但我有 3 个问题:
- 我不知道如何在此处为 slivergrid 设置不可滚动的 sliver。
- 我不知道如何让 appBar 在启动时准确地放置在屏幕底部。
- 我的列表有问题,当appbar到达顶部时,列表跳转了一些项目,它似乎代表了sliverGrid元素的大小。
谢谢
【问题讨论】:
标签: flutter