Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Created Feb 16, 2020
Embed
What would you like to do?
ClipRect 矩形裁剪
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