Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
164 views
in Technique[技术] by (71.8m points)

flutter中ClipOval等组件不会自动裁剪?

import 'package:flutter/material.dart';

class ClipRoute extends StatefulWidget {
  ClipRoute({Key key}) : super(key: key);
  @override
  _ClipRouteState createState() => _ClipRouteState();
}

class _ClipRouteState extends State<ClipRoute> {
  @override
  Widget build(BuildContext context) {
    Widget avator = Image.asset('image/t.png', width: 60);
    return Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.grey,
          title: Text('ClipRoute'),
        ),
        body: Column(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          mainAxisSize: MainAxisSize.max,
          children: <Widget>[
            avator,
            ClipOval(
              child: avator,
            ),
            ClipOval(
              child: avator,
              clipper: MyClipper(),
            ),
            ClipRRect(
              child: avator,
              borderRadius: BorderRadius.circular(10),
            ),
            ClipRect(
              child: avator,
            )
          ],
        ));
  }
}

class MyClipper extends CustomClipper<Rect> {
  @override
  Rect getClip(Size size) {
    return new Rect.fromLTRB(10.0, 10.0, size.width - 10.0, size.height - 10.0);
  }

  @override
  bool shouldReclip(CustomClipper<Rect> oldClipper) {
    return true;
  }
}

image.png


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...