我使用ClipPath将底部TabBar的路径剪切,如上图所示。
以下是脚手架:
Scaffold(
bottomNavigationBar: ClipPath(
clipBehavior: Clip.hardEdge,
clipper: NavBarClipper(), // class code shown below
child: Material(
elevation: 5,
color: Color(0xff282c34),
child: TabBar(
onTap: (value) {
if (value == 3) {
setState(() {
_scaffoldKey.currentState.openEndDrawer();
});
}
},
indicatorColor: Colors.white,
indicatorWeight: 1.0,
labelColor: Colors.white,
unselectedLabelColor: Colors.grey,
tabs: <Tab>[
Tab(
icon: Icon(
Icons.home,
size: 30,
),
),
Tab(
icon: Icon(
Icons.add_a_photo,
size: 30,
),
),
Tab(
icon: Icon(
Icons.notifications,
size: 30,
),
),
Tab(
icon: Icon(
Icons.person,
size: 30,
),
),
],
controller: controller,
),
),
),
);
这里是剪贴板类(Clipper Class)。最初的回答:
class NavBarClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Path path = Path();
path.lineTo(0, size.height);
path.lineTo(size.width, size.height);
path.lineTo(size.width - 20, 0);
path.lineTo(20, 0);
path.lineTo(0, size.height);
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return true;
}
}
但是,正如您在图像中所看到的那样,被剪切区域的颜色是白色的,看起来不太好。我想要使其透明,这样在剪切空间中也可以看到背后的图像。
编辑:我认为问题不在于剪切区域是白色的。实际上,TabBar并没有沿z轴位于页面内容之上。页面内容和TabBar分别位于不同位置。我希望它相当于html中的
position: absolute
,这样当我滚动时,内容就会在TabBar下面。
Stack
。 - 10101010