class BackDropCanvas extends CustomPainter { ui.Image background; BuildContext context; var dx = 0.0, dy = 0.0; static const double smallScan = 200.0; BackDropCanvas(this.context, this.background, this.dx, this.dy);
@override void paint(Canvas canvas, Size size) { canvas.clipPath(Path() ..moveTo((Screen.width - smallScan) * 0.5 + dx, (Screen.height - smallScan) * 0.5 + dy) ..lineTo((Screen.width + smallScan) * 0.5 + dx, (Screen.height - smallScan) * 0.5 + dy) ..lineTo((Screen.width + smallScan) * 0.5 + dx, (Screen.height + smallScan) * 0.5 + dy) ..lineTo((Screen.width - smallScan) * 0.5 + dx, (Screen.height + smallScan) * 0.5 + dy)); canvas.drawImage(this.background, ui.Offset.zero, Paint()); }
@override bool shouldRepaint(CustomPainter oldDelegate) { return true; }}
class _BackedDropPage extends State<BackedDropPage> { ui.Image _background; bool _prepDone; var dx = 0.0, dy = 0.0; static const double smallScan = 200.0;
@override void initState() { _prepDone = false; super.initState(); _prepare(); }
@override Widget build(BuildContext context) { return Scaffold( body: Stack(children: <Widget>[ Container( width: Screen.width, height: Screen.height, child: Stack(children: <Widget>[ Center(child: Image.asset('images/icon_hzw04_1.jpg')), BackdropFilter( filter: ImageFilter.blur(sigmaX: 4.0, sigmaY: 4.0), child: Container(color: Colors.black.withOpacity(0.2))) ])), _prepDone ? Container( width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.height, child: CustomPaint( painter: BackDropCanvas(context, _background, dx, dy))) : Container(color: Colors.grey), GestureDetector(onPanUpdate: (d) { if (d.globalPosition.dx >= smallScan * 0.5 && d.globalPosition.dx <= Screen.width - smallScan * 0.5) { dx = d.globalPosition.dx - Screen.width * 0.5; } if (d.globalPosition.dy >= smallScan * 0.5 && d.globalPosition.dy <= Screen.height - smallScan * 0.5) { dy = d.globalPosition.dy - Screen.height * 0.5; } setState(() {}); }) ])); }
_prepare() { loadImage('images/icon_hzw04_1.jpg').then((image) { _background = image; }).whenComplete(() { _prepDone = true; setState(() {}); }); }}
评论