Remove extra part after clipping in Flutter

若如初见. 提交于 2019-12-11 14:56:56

问题


Clipping allows me to draw only the part which I want to show. How do I remove the extra part which is not drawn but still takes up space?


The code

import 'package:flutter/material.dart';

class ClipTut extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Row(
          children: <Widget>[
            ClipRect(
              clipper: CustomRect(),
              child: Container(
                decoration: BoxDecoration(
                  border: Border.all(width: 4, color: Colors.black),
                  color: Colors.blue,
                ),
                width: 200.0,
                height: 200.0,
              ),
            ),
            Container(
              height: 200,
              width: 100,
              decoration: BoxDecoration(
                border: Border.all(width: 4, color: Colors.black),
                color: Colors.green,
              ),
            )
          ],
        ),
      ),
    );
  }
}

class CustomRect extends CustomClipper<Rect> {
  @override
  Rect getClip(Size size) => Rect.fromLTRB(0, 0.0, size.width/2, size.height);

  @override
  bool shouldReclip(CustomRect oldClipper) => true;
}

来源:https://stackoverflow.com/questions/58554601/remove-extra-part-after-clipping-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!