美文网首页
flutter clipRect矩形剪裁

flutter clipRect矩形剪裁

作者: 喜剧收尾_XWX | 来源:发表于2020-08-14 07:59 被阅读0次
    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;
      }
    }
    

    相关文章

      网友评论

          本文标题:flutter clipRect矩形剪裁

          本文链接:https://www.haomeiwen.com/subject/bviydktx.html