gpt4 book ai didi

将Container的Flutter夹部分制成两个半圆(半圆)

转载 作者:行者123 更新时间:2023-12-03 13:31:01 26 4
gpt4 key购买 nike

在 flutter 打中,我想剪辑Container的可选部分以制作此小部件:

enter image description here

裁剪小部件,使其顶部和底部有两个半圆。

对于此裁剪的小部件的某些功能,我希望具有一些可选功能,例如:

enter image description here

剪裁顶部,该可选内容的底部和右侧的空白处。如何使用可选功能剪切Container

最佳答案

您可以使用自定义Clipper + arcToPoint路径方法来创建干净的弧。

像那样:

enter image description here

import 'package:flutter/material.dart';
import 'package:vector_math/vector_math.dart' as v_math;

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: Scaffold(
body: SafeArea(
child: MyHomePage(),
),
),
);
}
}

class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ClipPath(
clipper: DolDurmaClipper(right: 40, holeRadius: 20),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(15),
),
color: Colors.blueAccent,
),
width: 300,
height: 95,
padding: EdgeInsets.all(15),
child: Text('first example'),
),
),
SizedBox(
height: 20,
),
ClipPath(
clipper: DolDurmaClipper(right: 100, holeRadius: 40),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(15),
),
color: Colors.amber,
),
width: 200,
height: 250,
padding: EdgeInsets.all(35),
child: Text('second example'),
),
),
]);
}
}

class DolDurmaClipper extends CustomClipper<Path> {
DolDurmaClipper({@required this.right, @required this.holeRadius});

final double right;
final double holeRadius;

@override
Path getClip(Size size) {
final path = Path()
..moveTo(0, 0)
..lineTo(size.width - right - holeRadius, 0.0)
..arcToPoint(
Offset(size.width - right, 0),
clockwise: false,
radius: Radius.circular(1),
)
..lineTo(size.width, 0.0)
..lineTo(size.width, size.height)
..lineTo(size.width - right, size.height)
..arcToPoint(
Offset(size.width - right - holeRadius, size.height),
clockwise: false,
radius: Radius.circular(1),
);

path.lineTo(0.0, size.height);

path.close();
return path;
}

@override
bool shouldReclip(DolDurmaClipper oldClipper) => true;
}

关于将Container的Flutter夹部分制成两个半圆(半圆),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57860813/

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