ClipRect 矩形裁剪
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return MaterialApp( | |
title: "ClipRect矩形裁剪", | |
home: Scaffold( | |
appBar: AppBar( | |
title: Text("ClipRect矩形裁剪"), | |
), | |
body: Center( | |
child: ClipRect( | |
clipper: RectClipper(), | |
child: SizedBox( | |
width: 300.0, | |
height: 300.0, | |
child: Image.network( | |
"https://start.lidong.me/asset/dong.png", | |
fit: BoxFit.cover, | |
), | |
), | |
), | |
), | |
), | |
); | |
} | |
} | |
//自定义 Clipper 类型为 Rect | |
class RectClipper extends CustomClipper<Rect> { | |
// 重写获取剪裁范围 | |
@override | |
Rect getClip(Size size) { | |
return Rect.fromLTRB(100.0, 100.0, size.width, size.height); | |
} | |
// 重写是否重新裁剪 | |
@override | |
bool shouldReclip(CustomClipper<Rect> oldClipper) { | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment