gpt4 book ai didi

flutter - 如何在 Flutter 的屏幕顶部创建一个半椭圆?

转载 作者:行者123 更新时间:2023-12-05 03:56:55 25 4
gpt4 key购买 nike

有没有办法在屏幕顶部创建一个椭圆形?我尝试使用 RenderBox,但感觉这不是一个正确的解决方案。 enter image description here

最佳答案

使用 CustomPainter 并使用曲线:

enter image description here

class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
CustomPaint(
painter: ShapesPainter(),
child: Container(height: 300),
),
Text('Text')
],
),
),
);
}
}

const double _kCurveHeight = 35;

class ShapesPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final p = Path();
p.lineTo(0, size.height - _kCurveHeight);
p.relativeQuadraticBezierTo(size.width / 2, 2 * _kCurveHeight, size.width, 0);
p.lineTo(size.width, 0);
p.close();

canvas.drawPath(p, Paint()..color = Colors.red);
}

@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}

关于flutter - 如何在 Flutter 的屏幕顶部创建一个半椭圆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58892349/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com