flutter clipRect矩形剪裁

2020-08-14  本文已影响0人  喜剧收尾_XWX
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;
  }
}
上一篇下一篇

猜你喜欢

热点阅读