答案 0 :(得分:0)
ClipPath
可能是您的解决方案,您可以像这样创建自定义快船:
class MyClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Path myPath = Path();
myPath.lineTo(0.0, size.height);
myPath.quadraticBezierTo(
size.width / 4,
size.height / 1.2,
size.width / 2,
size.height / 1.2
);
myPath.quadraticBezierTo(
size.width - (size.width / 4),
size.height / 1.2,
size.width,
size.height);
myPath.lineTo(size.width, 0.0);
return myPath;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return false;
}
}
我在下面发布了我的整个代码,您可以使用它并转换为所需的内容:
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Container(
child: Center(
child: ClipPath(
clipper: MyClipper(),
child: Container(
height: 200,
width: 300,
color: Colors.black26,
),
)),
),
),
);
}
}
class MyClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
Path myPath = Path();
myPath.lineTo(0.0, size.height);
myPath.quadraticBezierTo(
size.width / 4,
size.height / 1.2,
size.width / 2,
size.height / 1.2
);
myPath.quadraticBezierTo(
size.width - (size.width / 4),
size.height / 1.2,
size.width,
size.height);
myPath.lineTo(size.width, 0.0);
return myPath;
}
@override
bool shouldReclip(CustomClipper<Path> oldClipper) {
return false;
}
}