Rav*_*mar 7 scroll-position nestedscrollview flutter flutter-layout sliverappbar
我想SliverAppBar在ScrollablePositionedList.builder滚动时隐藏。这是我在此处包含的相关代码段。
NestedScrollView(
headerSliverBuilder: (context, innerBoxIsScrolled) => [
SliverAppBar(
backgroundColor: Colors.blue,
expandedHeight: 112,
snap: true,
pinned: false,
floating: true,
forceElevated: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.event),
)
],
flexibleSpace: SafeArea(
child: Column(
children: <Widget>[
Container(
height: kToolbarHeight,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Title',
style: Theme.of(context)
.textTheme
.title
.copyWith(
fontSize: 16, color: Colors.white),
),
SizedBox(
height: 2,
),
Text(
'Date',
style: Theme.of(context)
.textTheme
.caption
.copyWith(
fontSize: 10, color: Colors.white),
),
SizedBox(
height: 2,
),
Text(
'Another Text',
style: Theme.of(context)
.textTheme
.subtitle
.copyWith(
fontSize: 14, color: Colors.white),
),
],
),
),
Expanded(
child: Container(
height: kToolbarHeight,
width: MediaQuery.of(context).size.width,
color: Colors.white,
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Text(
'Prev',
),
Text(
'Next',
)
],
),
),
)
],
),
),
)
],
body: ScrollablePositionedList.builder(
physics: ScrollPhysics(),
itemPositionsListener: itemPositionListener,
itemScrollController: _itemScrollController,
initialScrollIndex: 0,
itemCount: 500,
itemBuilder: (BuildContext ctxt, int index) {
return Container(
margin: EdgeInsets.all(16)
,
child: Text('$index'));
})),
Run Code Online (Sandbox Code Playgroud)
到目前为止,我尝试了两种方法,但都没有正常工作,
我添加
physics: ScrollPhysics(),到ScrollablePositionedList.builder
输出:
我添加
physics: NeverScrollableScrollPhysics(),到ScrollablePositionedList.builder
SliverAppBar这次隐藏,但现在我无法滚动到最后ScrollablePositionedList.builder我的列表中有 500 个项目,但它仅滚动到第 14 个项目,请参阅输出。此外,它在滚动时滞后太多
输出:
提前致谢。
| 归档时间: |
|
| 查看次数: |
1948 次 |
| 最近记录: |