我正在研究剪切图像为曲线,但是CustomClipper不能突然工作。
仅clipper
的{{1}}属性无效。我该如何解决?
IreneClipper
错误消息
I / flutter(25014):══╡渲染库引起的异常 ╞═════════════════════════════════════════════════ ════════我/扑 (25014):在performLayout()期间引发了以下断言: I / flutter(25014):_ScaffoldLayout自定义多子布局 代表忘记布置以下孩子:I / flutter(25014):
_ScaffoldSlot.body:RenderClipPath#ab20f NEEDS-LAYOUT NEEDS-PAINT I / flutter(25014):每个孩子必须精确地布置一次。我/扑 (25014):I / flutter(25014):当引发异常时,这是 堆栈:I / flutter(25014):#0
MultiChildLayoutDelegate._callPerformLayout。 (package:flutter / src / rendering / custom_layout.dart:222:13)I / flutter (25014):#1 MultiChildLayoutDelegate._callPerformLayout (package:flutter / src / rendering / custom_layout.dart:230:8)
扑打医生
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Clock',
theme: ThemeData(
primarySwatch: Colors.blue
),
home: IreneClip(),
);
}
}
class IreneClip extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(backgroundColor: Colors.orange,),
body: ClipPath(
child: Image.asset('assets/irene.jpg'),
clipper: IreneClipper(),
),
);
}
}
class IreneClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Path path = Path();
path.moveTo(0.0, size.height);
return Path();
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return false;
}
}
答案 0 :(得分:0)
我解决了,如果您想热重载剪辑图像,shouldReclip
方法必须返回true
。
class IreneClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Path path = Path();
path.lineTo(0.0, size.height-40);
path.lineTo(size.width, size.height-60);
path.lineTo(size.width, 0.0);
path.close();
return path;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return true;
}
}