正如您在
BoxShadow类中看到的那样,它们将
toPaint()方法子类化为:
Paint toPaint() { final Paint result = Paint() ..color = color ..maskFilter = MaskFilter.blur(BlurStyle.normal, blurSigma); assert(() { if (debugDisableShadows) result.maskFilter = null; return true; }()); return result;}
…与
BlurStyle.normal而不是
BlurStyle.outer我们想要的。
让我们创建一个
BoxShadow使用
BlurStyleas参数的自定义。
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; }}
现在我们可以像这样使用它:
new CustomBoxShadow( color: Colors.black, offset: new Offset(5.0, 5.0), blurRadius: 5.0, blurStyle: BlurStyle.outer)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)