我正在尝试制作一个小部件,以呈现此图像中显示的圆圈之一。它是带有阴影的透明圆圈。圆圈应显示应用于父容器的任何颜色或背景图像。圆是透明的,但我看到的是这样:一个黑盒子的影子,而不是父母的背景色。有什么建议么?
这是我到目前为止的内容:
class TransParentCircle extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
child: new Center(
child: new Container(
decoration: new BoxDecoration(
border: new Border.all(width: 1.0, color: Colors.black),
shape: BoxShape.circle,
color: Colors.transparent,
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black,
offset: Offset(1.0, 6.0),
blurRadius: 40.0,
),
],
),
padding: EdgeInsets.all(16.0),
),
),
width: 320.0,
height: 240.0,
margin: EdgeInsets.only(bottom: 16.0));
}
}
Run Code Online (Sandbox Code Playgroud)
小智 12
As you can see in the BoxShadow class, they subclass the toPaint() method like this :
Paint toPaint() {
final Paint result = Paint()
..color = color
..maskFilter = MaskFilter.blur(BlurStyle.normal, blurSigma);
assert(() {
if (debugDisableShadows)
result.maskFilter = null;
return true;
}());
return result;
}
Run Code Online (Sandbox Code Playgroud)
... with BlurStyle.normal instead of BlurStyle.outer as we wanted.
Let's just create a custom BoxShadow that takes the BlurStyle as parameter.
import 'package:flutter/material.dart';
class CustomBoxShadow extends BoxShadow {
final BlurStyle blurStyle;
const CustomBoxShadow({
Color color = const Color(0xFF000000),
Offset offset = Offset.zero,
double blurRadius = 0.0,
this.blurStyle = BlurStyle.normal,
}) : super(color: color, offset: offset, blurRadius: blurRadius);
@override
Paint toPaint() {
final Paint result = Paint()
..color = color
..maskFilter = MaskFilter.blur(this.blurStyle, blurSigma);
assert(() {
if (debugDisableShadows)
result.maskFilter = null;
return true;
}());
return result;
}
}
Run Code Online (Sandbox Code Playgroud)
Now we can use it like this :
new CustomBoxShadow(
color: Colors.black,
offset: new Offset(5.0, 5.0),
blurRadius: 5.0,
blurStyle: BlurStyle.outer
)
Run Code Online (Sandbox Code Playgroud)
Container(
height: 200.0,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 10.0, // soften the shadow
spreadRadius: 7.0, //extend the shadow
offset: Offset(
5.0, // Move to right 10 horizontally
5.0, // Move to bottom 5 Vertically
),
)
],
),
child: Text(" ", style:TextStyle(fontSize:30)),
Run Code Online (Sandbox Code Playgroud)
);
| 归档时间: |
|
| 查看次数: |
18027 次 |
| 最近记录: |