Reputation: 586
Based on this design:
I am trying to use SliverList
with SliverAppBar
but I can't seem to overlap the items so when the top left and top right radius are applied the color of the previous item is present.
It's similar to this other post: How to overlap SliverList on a SliverAppBar
But I'm trying to apply the Stack
to all SliverList
children. The best I accomplished so far is a workaround where I wrap the item in another Container
and apply the previous background color:
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('Test'),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
child: Container(
child: Column(
children: <Widget>[
Container(
child: Text(
'Index is $index'.toUpperCase(),
),
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(bottom: 10.0),
),
Container(height: 200.0)
],
),
constraints: BoxConstraints.tightForFinite(width: 200),
decoration: BoxDecoration(
color:
index % 2 == 0 ? Color(0XFF45766E) : Color(0XFFECB141),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40.0),
topRight: Radius.circular(40.0),
),
),
padding: EdgeInsets.only(
left: 20.0,
top: 10.0,
),
),
decoration: BoxDecoration(
color: index % 2 == 0 ? Color(0XFFECB141) : Color(0XFF45766E),
),
);
},
),
),
],
);
Thank you!
Upvotes: 3
Views: 3990
Reputation: 7601
CustomScrollView->
SliverList->
SliverChildBuilderDelegate->
Container->
Stack->children[
Container,
positioned(bottom:0,
child: Container(decoration: BoxDecoration(
color: (next index color),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40.0),
topRight: Radius.circular(40.0),
),
),)
)
]
Upvotes: 0
Reputation: 2956
CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text('Test'),
),
SliverList(
delegate: SliverChildBuilderDelegate(
(BuildContext context, int index) {
return Container(
child: Container(
child: Column(
children: <Widget>[
Container(
child: Text(
'Index is $index'.toUpperCase(),
),
alignment: Alignment.centerLeft,
padding: EdgeInsets.only(bottom: 10.0),
),
Container(height: 200.0)
],
),
constraints: BoxConstraints.tightForFinite(width: 200),
decoration: BoxDecoration(
color: index % 2 == 0
? Color(0XFF45766E)
: Color(0XFFECB141),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(40.0),
topRight: Radius.circular(40.0),
),
),
padding: EdgeInsets.only(
left: 20.0,
top: 10.0,
),
),
decoration: BoxDecoration(
//the only change required here
color: index % 2 == 0
? index == 0 ? Colors.white : Color(0XFFECB141)
: Color(0XFF45766E),
),
);
},
),
),
],
);
You just need to change explicitly for the first position.
Upvotes: 2