Flutter 如何在flatter中剪切不透明度小部件?

Flutter 如何在flatter中剪切不透明度小部件?,flutter,flutter-opacity,flutter-design,Flutter,Flutter Opacity,Flutter Design,我想删除容器中心的不透明度,使其下方的图片可见 我想要什么: 我的尝试: import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; class AppFour extends StatefulWidget { @override _AppFourState createState() => _AppFourState(); }

我想删除容器中心的不透明度,使其下方的图片可见

我想要什么:

我的尝试:

import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class AppFour extends StatefulWidget {
  @override
  _AppFourState createState() => _AppFourState();
}

class _AppFourState extends State<AppFour> {
  String img = 'https://images.unsplash.com/photo-1513279922550-250c2129b13a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Container(
            height: MediaQuery.of(context).size.height,
            decoration: BoxDecoration(
              image: DecorationImage(
                image: NetworkImage('$img'),
                fit: BoxFit.cover,
              ),
            ),
          ),
          Opacity(
            opacity: 0.5,
            child: Container(
              color: Colors.white,
            ),
          ),
          Center(
            child: Container(
              height: MediaQuery.of(context).size.height / 1.5,
              width: MediaQuery.of(context).size.width / 1.5,
              decoration: BoxDecoration(
                color: Colors.transparent,
                image: DecorationImage(
                    image: NetworkImage('$img'),
                    fit: BoxFit.fitHeight),
                borderRadius: BorderRadius.circular(5.0),
                border: Border.all(
                  color: Colors.white,
                  width: 2.0,
                ),
                boxShadow: [
                  BoxShadow(
                      color: Colors.black,
                      offset: Offset(0.0, 0.0),
                      blurRadius: 10.0)
                ],
              ),
            ),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        backgroundColor: Colors.grey[800],
        child: Transform.rotate(
          angle: 45,
          child: Icon(FontAwesomeIcons.syncAlt),
        ),
        onPressed: () {},
      ),
    );
  }
}

我尝试过的代码:

import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class AppFour extends StatefulWidget {
  @override
  _AppFourState createState() => _AppFourState();
}

class _AppFourState extends State<AppFour> {
  String img = 'https://images.unsplash.com/photo-1513279922550-250c2129b13a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          Container(
            height: MediaQuery.of(context).size.height,
            decoration: BoxDecoration(
              image: DecorationImage(
                image: NetworkImage('$img'),
                fit: BoxFit.cover,
              ),
            ),
          ),
          Opacity(
            opacity: 0.5,
            child: Container(
              color: Colors.white,
            ),
          ),
          Center(
            child: Container(
              height: MediaQuery.of(context).size.height / 1.5,
              width: MediaQuery.of(context).size.width / 1.5,
              decoration: BoxDecoration(
                color: Colors.transparent,
                image: DecorationImage(
                    image: NetworkImage('$img'),
                    fit: BoxFit.fitHeight),
                borderRadius: BorderRadius.circular(5.0),
                border: Border.all(
                  color: Colors.white,
                  width: 2.0,
                ),
                boxShadow: [
                  BoxShadow(
                      color: Colors.black,
                      offset: Offset(0.0, 0.0),
                      blurRadius: 10.0)
                ],
              ),
            ),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        backgroundColor: Colors.grey[800],
        child: Transform.rotate(
          angle: 45,
          child: Icon(FontAwesomeIcons.syncAlt),
        ),
        onPressed: () {},
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“package:font_awesome_flatter/font_awesome_flatter.dart”;
类AppFour扩展了StatefulWidget{
@凌驾
_AppFourState createState();
}
类AppFourState扩展了状态{
字符串img=https://images.unsplash.com/photo-1513279922550-250c2129b13a?ixlib=rb-1.2.1&ixid=EYJHCBFAWQIOJEYMDD9&auto=format&fit=crop&w=1050&q=80';
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:堆栈(
儿童:[
容器(
高度:MediaQuery.of(context).size.height,
装饰:盒子装饰(
图像:装饰图像(
image:NetworkImage(“$img”),
适合:BoxFit.cover,
),
),
),
不透明(
不透明度:0.5,
子:容器(
颜色:颜色,白色,
),
),
居中(
子:容器(
高度:MediaQuery.of(context).size.height/1.5,
宽度:MediaQuery.of(context).size.width/1.5,
装饰:盒子装饰(
颜色:颜色。透明,
图像:装饰图像(
image:NetworkImage(“$img”),
适合:BoxFit.适合高度),
边界半径:边界半径。圆形(5.0),
边界:边界(
颜色:颜色,白色,
宽度:2.0,
),
boxShadow:[
箱形阴影(
颜色:颜色,黑色,
偏移量:偏移量(0.0,0.0),
(半径:10.0)
],
),
),
),
],
),
浮动操作按钮:浮动操作按钮(
背景颜色:颜色。灰色[800],
子对象:Transform.rotate(
角度:45,
子项:图标(FontAwesomeIcons.syncAlt),
),
按下:(){},
),
);
}
}

我已修改了您的代码,使其具有您作为示例给出的图像的效果:

屏幕截图

代码

String img = 'https://images.unsplash.com/photo-1513279922550-250c2129b13a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80';
@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Stack(
      children: <Widget>[
        Container(
          height: MediaQuery.of(context).size.height,
          decoration: BoxDecoration(
            image: DecorationImage(
              image: NetworkImage('$img'),
              fit: BoxFit.cover,
            ),
          ),
        ),
        Opacity(
          opacity: 0.5,
          child: Container(
            color: Colors.white,
          ),
        ),
        Center(
          child: Container(
            decoration: BoxDecoration(
              color: Colors.transparent,
              borderRadius: BorderRadius.circular(5.0),
              border: Border.all(
                color: Colors.white,
                width: 5.0,
              ),
              boxShadow: [
                BoxShadow(
                  color: Colors.black,
                  offset: Offset(0.0, 0.0),
                  blurRadius: 10.0
                )
              ],
            ),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(5.0),
              child: Align(
                alignment: Alignment.center,
                widthFactor: 0.75,
                heightFactor: 0.75,
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.transparent,
                    image: DecorationImage(
                      image: NetworkImage('$img'),
                      fit: BoxFit.fitHeight
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      ],
    ),
    floatingActionButton: FloatingActionButton(
      backgroundColor: Colors.grey[800],
      child: Transform.rotate(
        angle: 45,
        child: Icon(FontAwesomeIcons.syncAlt),
      ),
      onPressed: () {},
    ),
  );
}
String img='1〕https://images.unsplash.com/photo-1513279922550-250c2129b13a?ixlib=rb-1.2.1&ixid=EYJHCBFAWQIOJEYMDD9&auto=format&fit=crop&w=1050&q=80';
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:堆栈(
儿童:[
容器(
高度:MediaQuery.of(context).size.height,
装饰:盒子装饰(
图像:装饰图像(
image:NetworkImage(“$img”),
适合:BoxFit.cover,
),
),
),
不透明(
不透明度:0.5,
子:容器(
颜色:颜色,白色,
),
),
居中(
子:容器(
装饰:盒子装饰(
颜色:颜色。透明,
边界半径:边界半径。圆形(5.0),
边界:边界(
颜色:颜色,白色,
宽度:5.0,
),
boxShadow:[
箱形阴影(
颜色:颜色,黑色,
偏移量:偏移量(0.0,0.0),
模糊半径:10.0
)
],
),
孩子:ClipRRect(
边界半径:边界半径。圆形(5.0),
子对象:对齐(
对齐:对齐.center,
宽度系数:0.75,
高度系数:0.75,
子:容器(
装饰:盒子装饰(
颜色:颜色。透明,
图像:装饰图像(
image:NetworkImage(“$img”),
适合:BoxFit.fit高度
),
),
),
),
),
),
),
],
),
浮动操作按钮:浮动操作按钮(
背景颜色:颜色。灰色[800],
子对象:Transform.rotate(
角度:45,
子项:图标(FontAwesomeIcons.syncAlt),
),
按下:(){},
),
);
}

我已修改了您的代码,使其具有您作为示例给出的图像的效果:

屏幕截图

代码

String img = 'https://images.unsplash.com/photo-1513279922550-250c2129b13a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1050&q=80';
@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Stack(
      children: <Widget>[
        Container(
          height: MediaQuery.of(context).size.height,
          decoration: BoxDecoration(
            image: DecorationImage(
              image: NetworkImage('$img'),
              fit: BoxFit.cover,
            ),
          ),
        ),
        Opacity(
          opacity: 0.5,
          child: Container(
            color: Colors.white,
          ),
        ),
        Center(
          child: Container(
            decoration: BoxDecoration(
              color: Colors.transparent,
              borderRadius: BorderRadius.circular(5.0),
              border: Border.all(
                color: Colors.white,
                width: 5.0,
              ),
              boxShadow: [
                BoxShadow(
                  color: Colors.black,
                  offset: Offset(0.0, 0.0),
                  blurRadius: 10.0
                )
              ],
            ),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(5.0),
              child: Align(
                alignment: Alignment.center,
                widthFactor: 0.75,
                heightFactor: 0.75,
                child: Container(
                  decoration: BoxDecoration(
                    color: Colors.transparent,
                    image: DecorationImage(
                      image: NetworkImage('$img'),
                      fit: BoxFit.fitHeight
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      ],
    ),
    floatingActionButton: FloatingActionButton(
      backgroundColor: Colors.grey[800],
      child: Transform.rotate(
        angle: 45,
        child: Icon(FontAwesomeIcons.syncAlt),
      ),
      onPressed: () {},
    ),
  );
}
String img='1〕https://images.unsplash.com/photo-1513279922550-250c2129b13a?ixlib=rb-1.2.1&ixid=EYJHCBFAWQIOJEYMDD9&auto=format&fit=crop&w=1050&q=80';
@凌驾
小部件构建(构建上下文){
返回脚手架(
主体:堆栈(
儿童:[
容器(
高度:MediaQuery.of(context).size.height,
装饰:盒子装饰(
图像:装饰图像(
image:NetworkImage(“$img”),
适合:BoxFit.cover,
),
),
),
不透明(
不透明度:0.5,
子:容器(
颜色:颜色,白色,
),
),
居中(
子:容器(
装饰:盒子装饰(
颜色:颜色。透明,
边界半径:边界半径。圆形(5.0),
边界:边界(
颜色:颜色,白色,
宽度:5.0,
),
boxShadow:[
箱形阴影(
颜色:颜色,黑色,
偏移量:偏移量(0.0,0.0),
模糊半径:10.0
)
],
),
孩子:ClipRRect(
边界半径:边界半径。圆形(5.0),
子对象:对齐(
对齐:对齐。