这是更改SliverAppBar形状的正确简单方法(如Flutter文档中所述)。无需使用任何技巧,甚至可以将其形状变成任何想要的形状。
SliverAppBar(
shape: ContinuousRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(30), bottomRight: Radius.circular(30))),
title: Text('Sliver AppBar'),
);
SliverAppBar
的 borderRadius
在展开时不起作用于 flexibleSpace
。如何解决? - Satyajyoti Biswas如果有人需要在 SliverPersistentHeader
中添加底部边框角落:
在代理中:
Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
borderRadius: const BorderRadius.vertical(bottom: Radius.circular(15.0)),
),
child: Image()
)
BorderRadius
小部件实现了这种设计。Container(
height: 75.0,
child: Center(child: new Text("Hello",
textAlign: TextAlign.center,
style: TextStyle(
height: 2.5,
color: Colors.white,
fontSize: 18.0,
),
)),
decoration: new BoxDecoration(
color: Colors.blue,
boxShadow: [new BoxShadow(blurRadius: 3.0)],
borderRadius: BorderRadius.vertical(bottom: Radius.circular(19.0)),
),
),
这不会为您提供视差滚动功能。 SliverOverlapAbsorber(
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(
context),
sliver: SliverAppBar(
pinned: true,
stretch: true,
automaticallyImplyLeading: false,
expandedHeight: 180,
flexibleSpace: FlexibleSpaceBar(
stretchModes: const <StretchMode>[
StretchMode.zoomBackground,
StretchMode.blurBackground,
],
background: Stack(
children: [
CustomImage(
path: "assets/images/profile.png",
width: MediaQuery.of(context).size.width,
fit: BoxFit.fill,
),
Container(
color: iconGreyColor.withOpacity(0.2),
),
Positioned(
bottom: 50,
child: Row(
children: [
CustomImage(
path: "assets/images/notification.png",
),
Icon(Icons.message),
Icon(Icons.search)
],
))
],
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(30),
),
),
))
appBar: AppBar(
shape: ContinuousRectangleBorder(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(100),
bottomRight: Radius.circular(100))),
),
Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight: 180,
title: Text('RoundedRectangleBorder'),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
bottom: Radius.circular(40),
),
),
),
],
),
);