Dart 为什么CustomClipper没有突然工作?
我正在研究将图像剪裁为曲线,但CustomClipper并没有突然工作。 只有Dart 为什么CustomClipper没有突然工作?,dart,flutter,Dart,Flutter,我正在研究将图像剪裁为曲线,但CustomClipper并没有突然工作。 只有IreneClipper的clipper属性不起作用。我怎样才能修好它 import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { retur
IreneClipper
的clipper
属性不起作用。我怎样才能修好它
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;
}
}
我解决了,
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;
}
}
类IreneClipper扩展了CustomClipper{
@凌驾
路径getClip(大小){
路径=路径();
path.lineTo(0.0,大小。高度-40);
path.lineTo(size.width,size.height-60);
path.lineTo(size.width,0.0);
path.close();
返回路径;
}
@凌驾
bool shouldReclip(CustomClipper oldClipper){
返回true;
}
}
I solved,
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;
}
}
类IreneClipper扩展了CustomClipper{
@凌驾
路径getClip(大小){
路径=路径();
path.lineTo(0.0,大小。高度-40);
path.lineTo(size.width,size.height-60);
path.lineTo(size.width,0.0);
path.close();
返回路径;
}
@凌驾
bool shouldReclip(CustomClipper oldClipper){
返回true;
}
}
我不知道你说的突然是什么意思。早些时候有用吗?其次,我运行了你的代码,它没有给我错误。你能添加你的
颤振医生-v
结果吗?它工作了,但现在不工作了。我不知道你说的突然是什么意思。早些时候有用吗?其次,我运行了你的代码,它没有给我错误。你能添加你的颤振医生-v
结果吗?它工作了,但现在不工作了。我补充说,最好将其实现为oldcipper!=这是
。最好将其实现为oldcipper!=这是
。