【发布时间】:2020-12-15 10:07:21
【问题描述】:
我只是想显示相机的预览并调整用户以进行自拍。
我有以下 sn-p 代码,我想让这个人的图像透明(不是白色)并用颜色填充周围区域。
但是我面临的问题,如果我将SVG设置为透明色,它将显示父(容器)的颜色,
我需要使人的图像完全透明才能看到相机的预览,并用颜色填充周围区域。
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Stack(
children: [
Container(
height: MediaQuery.of(context).size.height,
child: Center(
child: _cameraPreviewWidget(),
),
),
Container(
height: MediaQuery.of(context).size.height,
color: Colors.grey[700].withOpacity(0.8),
child: Align(
alignment: Alignment.bottomCenter,
child: SvgPicture.asset(
'assets/svg/selfie_person.svg',
alignment: Alignment.bottomCenter,
fit: BoxFit.cover,
color: Colors.white,
),
),
),
Container(
height: MediaQuery.of(context).size.height,
child: Padding(
padding: EdgeInsets.only(
top: MediaQuery.of(context).size.height * 0.05,
bottom: MediaQuery.of(context).size.height * 0.15,
),
child: Column(
children: [
ListTile(
leading: InkWell(
onTap: () {
Navigator.pop(context, null);
},
child: FaIcon(
FontAwesomeIcons.arrowLeft,
color: Colors.white,
),
),
title: Center(
child: Text(
"Take a selfie",
style: Theme.of(context).textTheme.subtitle2,
),
),
),
Padding(
padding: EdgeInsets.symmetric(
horizontal: MediaQuery.of(context).size.width * 0.05,
),
child: Text(
"Take a quick selfie so we know it's you, this is never public",
style: Theme.of(context).textTheme.subtitle2,
overflow: TextOverflow.ellipsis,
maxLines: 3,
textAlign: TextAlign.center,
),
),
Expanded(
child: Align(
alignment: Alignment.bottomCenter,
child: _captureButton(),
),
),
],
),
),
),
],
),
),
);
【问题讨论】:
-
也许您可以尝试制作一个新图像,将正方形前面的人的轮廓剪掉,轮廓是空的。您的图像将是灰色部分,而不是您现在拥有的白色部分。
-
这是个好主意,如果我没有找到 Flutter 的任何解决方案,我会这样做
标签: image flutter flutter-layout transparency