Flutter Clipper失败,布尔值为null

时间:2019-09-16 13:41:01

标签: flutter flutter-layout

我正在尝试裁剪一个装饰有图像的容器,但是每第二次启动该应用程序都会失败

  

I / flutter(23288):断言失败:布尔表达式不能为空

     

I / flutter(23288):#0 _RenderCustomClip.clipper = {package:flutter / src / rendering / proxy_box.dart:1172:20)

enter image description here

Scaffold(
 body: ClipPath(
   clipper: RoundClip(),
   clipBehavior: Clip.antiAlias,
   child: Container(
     height: MediaQuery.of(context).size.width,
     width: double.infinity,
     margin: EdgeInsets.only(left: 32.0),
     decoration: BoxDecoration(
      image: DecorationImage(image: NetworkImageCache.of(context).getImageProviderByUrlLargestImagePossible('image-url'), fit: BoxFit.cover)
     )
    ),
  ),
),

我的圆形夹很简单:

class RoundClip extends CustomClipper<Path> {
@override
Path getClip(Size size) {
var path = Path();

path.lineTo(48, 0);
path.quadraticBezierTo(size.width/8, size.height, size.width+100, size.height);

path.lineTo(size.width, 0);
path.close();

return path;
}

@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
// TODO: implement shouldReclip
return null;
}
}

1 个答案:

答案 0 :(得分:0)

对于那些可能正在寻找解决方案的人。 将shouldReclip()方法的返回值从null更改为任何bool(say true or false)

或者只需将shouldReclip() method类本身中的下面的给定代码替换为clipper

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    // TODO: implement shouldReclip
    return true;
  }

Link to the Source供参考。