Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 具有两种不同不透明度的颤振容器_Flutter_Flutter Layout - Fatal编程技术网

Flutter 具有两种不同不透明度的颤振容器

Flutter 具有两种不同不透明度的颤振容器,flutter,flutter-layout,Flutter,Flutter Layout,我想用两种不同的不透明度制作一个容器,使屏幕更关注一些图像,我使用了堆栈和容器,有可能制作这样的东西吗 这是我的代码示例 Stack( children: <Widget>[ Image(), Container( height: double.infinity, width: double.infinity, color: Colors.black.wi

我想用两种不同的不透明度制作一个容器,使屏幕更关注一些图像,我使用了堆栈和容器,有可能制作这样的东西吗

这是我的代码示例

Stack(
        children: <Widget>[
          Image(),
          Container(
            height: double.infinity,
            width: double.infinity,
            color: Colors.black.withOpacity(0.4),
          ),
堆栈(
儿童:[
Image(),
容器(
高度:双无限,
宽度:double.infinity,
颜色:颜色。黑色。不透明度(0.4),
),

谢谢大家,

我不确定这是一个好的解决方案。它会起作用的

import 'package:flutter/material.dart';

void main() => runApp(MaterialApp(home: FirstPage()));

class FirstPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Demo")),
      body: Stack(
        fit: StackFit.expand,
        children: <Widget>[
          Image.network(
            "https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg",
            fit: BoxFit.cover,
          ),
          CustomPaint(
            painter: MyPainter(),
          )
        ],
      ),
    );
  }
}

class MyPainter extends CustomPainter {
  final Color color;
  final double opacity;

  ///ratio of max(height, width)
  final double radius;

  MyPainter({
    Color color,
    double radius = 0.3,
    this.opacity = 0.4,
  })  : assert(opacity != null && opacity >= 0.0 && opacity <= 1.0),
        color = color ?? Colors.black,
        radius = radius ?? 0.3;

  @override
  void paint(Canvas canvas, Size size) {
    var rect = Offset.zero & size;
    var gradient = RadialGradient(
      center: Alignment.center,
      radius: radius,
      colors: [const Color(0x0000000), color.withOpacity(opacity)],
      stops: [1.0, 1.0],
    );
    canvas.drawRect(
      rect,
      Paint()..shader = gradient.createShader(rect),
    );
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }
}
导入“包装:颤振/材料.省道”;
void main()=>runApp(MaterialApp(主页:FirstPage());
类FirstPage扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(标题:文本(“演示”),
主体:堆栈(
fit:StackFit.expand,
儿童:[
图像网络(
"https://images.pexels.com/photos/414612/pexels-photo-414612.jpeg",
适合:BoxFit.cover,
),
定制油漆(
画家:我的画家(),
)
],
),
);
}
}
类MyPainter扩展了CustomPainter{
最终颜色;
最终双不透明度;
///最大值的比率(高度、宽度)
最终双半径;
我的画家({
颜色,
双半径=0.3,
此值为0.4,

}):assert(opacity!=null&&opacity>=0.0&&opacity这就是您要查找的内容: