Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Created February 16, 2020 15:35
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save ryanlid/f59267cedbe4b96905d153c79d2409bb to your computer and use it in GitHub Desktop.
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