颤动:透明的孩子,具有填充父级的背景颜色

问题描述

我只是试图显示相机的预览并对齐用户以进行自拍照。

我有以下代码段,我想使人的图像透明(而不是白色),并用颜色填充周围的区域。

但是我面临的问题是,如果我将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,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,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",overflow: TextOverflow.ellipsis,maxLines: 3,textAlign: TextAlign.center,Expanded(
                      child: Align(
                        alignment: Alignment.bottomCenter,child: _captureButton(),],);

selfie photo screen

解决方法

我不太了解您的问题,但是我认为您应该尝试Opacity类..用Opacity包装您的SVG

您可以检查它:

https://api.flutter.dev/flutter/widgets/Opacity-class.html

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...