Closed fangshengfy closed 4 years ago
maybe scroll has poblem
What kind of issue you get with this example?
NestedScrollView-》SliverAppBar There is a problem with folding
Flutter can't properly place sliverappbar over the multidirectional infinite scroll since it can't define edges for app bar placement calculation.
If you need to incorporate sticky header items with SliverAppBar, you need to use example from SingleChildScrollPage
and example from Flutter docs. Since quite likely you need to add Overlap and Absorber slivers in scrollable area
SingleChildScrollView
in SingleChildScrollPage
can be replaced with any other ScrollView that Flutter provides
and StickyListItem
can be rendered with SliverChildBuilderDelegate
for example if you need infinite list
but, if you need single directional scroll view with nested scroll - you no need actually NestedScrollView
@fangshengfy here is an example of page scaffold (just define droadcast _headerStream
controller)
Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight: 230.0,
pinned: true,
flexibleSpace: FlexibleSpaceBar(
title: Text('Title'),
background: Image.network(
'http://img.haote.com/upload/20180918/2018091815372344164.jpg',
fit: BoxFit.fitHeight,
),
),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
final date = DateTime.now().add(
Duration(
days: index,
)
);
return StickyListItem<int>(
itemIndex: index,
streamSink: _headerStream.sink,
positionAxis: HeaderPositionAxis.crossAxis,
header: StreamBuilder<StickyState<int>>(
initialData: StickyState<int>(index),
stream: _headerStream.stream.where((event) => event.index == index),
builder: (_, snapshot) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.orange.withOpacity(1 - snapshot.data.position),
),
height: 70,
width: 70,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
date.day.toString(),
style: TextStyle(
fontSize: 21,
color: Colors.black87,
fontWeight: FontWeight.w600,
),
),
Text(
DateFormat.MMM().format(date),
style: TextStyle(
height: .7,
fontSize: 17,
color: Colors.black87,
fontWeight: FontWeight.w400,
),
)
],
),
),
);
},
),
content: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
color: Colors.blueAccent,
),
height: 300,
width: double.infinity,
child: Center(
child: Text(
DateFormat.yMMMMd().format(date),
style: TextStyle(
fontSize: 18,
color: Colors.white
),
),
),
),
),
);
},
),
),
],
)
);
Btw, if you don't want to rebuild header on scroll, you can remove stream and StreamBuilder from prev example. Position will be recalculated in any case