[英]How to give fixed height to a sliverList in flutter?
I am trying to make a collapsible toolbar that shrinks when scrolling the page.我正在尝试制作一个在滚动页面时会缩小的可折叠工具栏。
For that, I am using Slivers.为此,我正在使用 Slivers。 By using
SliverList
, when the data gets scrolled, it goes up in the phone screen top battery and time transparent bar.通过使用
SliverList
,当数据滚动时,它会在手机屏幕顶部电池和时间透明条中上升。 Hence, I want to give the list fixed height so that it gets scrolled in a limited area.因此,我想给列表固定高度,以便它在有限的区域内滚动。
I tried putting the SliverList
into a SingleChildScrollView
, a SizedBox
, or a Container
.我尝试将
SliverList
放入SingleChildScrollView
、 SizedBox
或Container
中。 But none worked.但没有一个奏效。
SliverList(
delegate: SliverChildBuilderDelegate((context, index) {
return Container(
color: Colors.white,
child: Text("Text"),
);
},
chikdCount:100,
),
You can change the height of slivers by using itemExtend
property in SliverFixedExtentList
.您可以使用
itemExtend
SliverFixedExtentList
来更改条子的高度。 Henceforth all the children will take the same height as 150.0.从今以后,所有孩子的身高都将与 150.0 相同。 Can you check the below code?
你能检查下面的代码吗?
SafeArea(
child: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('SliverAppBar'),
backgroundColor: Colors.green,
expandedHeight: 200.0,
flexibleSpace: FlexibleSpaceBar(
background: Image.asset('assets/forest.jpg', fit: BoxFit.cover),
),
),
SliverFixedExtentList(
itemExtent: 150.0,
delegate: SliverChildListDelegate(
[
Container(color: Colors.red),
Container(color: Colors.purple),
Container(color: Colors.green),
Container(color: Colors.orange),
Container(color: Colors.yellow),
Container(color: Colors.pink),
],
),
),
],
));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.