import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
title: "clipRect矩形剪裁",
theme: ThemeData(
primaryColor: Colors.lightGreen,
),
home: Scaffold(
appBar: AppBar(
title: Text('clipRect矩形剪裁'),
),
body: Center(
//圆形剪裁
child: ClipRect(
//指定Cliper
clipper: RectClipper(),
child: SizedBox(
width: 300,
height: 300,
child: Image.asset(
"images/8.jpeg",
fit: BoxFit.fill,
),
),
),
)),
);
}
}
class RectClipper extends CustomClipper<Rect> {
@override
Rect getClip(Size size) {
return Rect.fromLTRB(100, 100, size.width - 100, size.height - 100);
}
@override
bool shouldReclip(CustomClipper<Rect> oldClipper) {
return true;
}
}
网友评论