[英]How to make background of ClipPath transparent?
我使用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,
),
),
),
);
这是快船课
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分别位于。 我想使其等同于position: absolute
html中的position: absolute
,以便在滚动时内容位于TabBar下方。
@ 10101010的建议成功了!
我使用了Stack,效果很好。
这是最终的脚手架代码:
return Scaffold(
body: Stack(
children: <Widget>[
Container(
height: deviceHeight,
width: deviceWidth,
),
_currentPage(),
Positioned(
width: viewportWIdth,
height: 40,
bottom: 0,
child: ClipPath(
clipper: NavBarClipper(),
child: Material(
elevation: 5,
color: Color(0xff282c34),
child: TabBar(
onTap: (newIndex) {
if (newIndex == 4) {
setState(() {
_scaffoldKey.currentState.openEndDrawer();
});
} else {
setState(() {
_currentIndex = newIndex;
});
}
},
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,
),
),
Tab(
icon: Icon(
Icons.menu,
size: 30,
),
),
],
controller: controller,
),
),
),
],
),
key: _scaffoldKey,
endDrawer: Drawer(
child: Container(),
),
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.