第11章组件装饰和视觉效果-Clip剪裁处理-ClipRect矩形剪裁
防采集标记:亢少军老师的课程和资料
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'ClipRect矩形剪裁示例',
home: Scaffold(
appBar: AppBar(
title: Text(
'ClipRect矩形剪裁示例',
style: TextStyle(color: Colors.white),
),
),
body: Center(
child: new ClipRect(
clipper: new RectClipper(),//指定自定义Clipper
child:new SizedBox(
width: 300.0,
height:300.0,
child: new Image.asset("images/8.jpeg",fit: BoxFit.fill,),
) ,
),
),
),
);
}
}
//自定义Clipper,类型为Rect
class RectClipper extends CustomClipper{
//重写获取剪裁范围
@override
Rect getClip(Size size) {
return new Rect.fromLTRB(100.0, 100.0, size.width - 100.0, size.height- 100.0);
}
//重写是否重新剪裁
@override
bool shouldReclip(CustomClipper oldClipper) {
return true;
}
}
- Flutter技术入门与实战: http://product.dangdang.com/26485813.html
- Flutter交流学习群:894109159
- Flutter开源项目请关注: https://github.com/kangshaojun
- Flutter****:https://edu.****.net/lecturer/2436
@作者: 亢少军