gpt4 book ai didi

flutter : Achieved Sliverappbar Shape

转载 作者:行者123 更新时间:2023-12-03 04:15:18 28 4
gpt4 key购买 nike

我在 Dribble 中发现了一些 Appbar 设计 https://dribbble.com/shots/9175650-Beauty-Salon-App/attachments/1218583?mode=media ,我尝试创建相同的内容,但我对彼此的边界半径感到困惑。

没有背景的试验1:

试用2,脚手架背景颜色为蓝色

试用3,背景颜色深橙色

我怎样才能实现像链接这样的应用栏设计?

源代码

import 'package:flutter/material.dart';
import 'package:flutter_iconpicker/flutter_iconpicker.dart';

class TestingScreen extends StatelessWidget {
static const routeName = "/testing-screen";
@override
Widget build(BuildContext context) {
var mediaQuery = MediaQuery.of(context);

return Scaffold(
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
expandedHeight: mediaQuery.size.height / 4,
backgroundColor: Colors.deepOrange,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.only(bottomRight: Radius.circular(80))),
),
SliverList(
delegate: SliverChildListDelegate(
[
Container(
height: mediaQuery.size.height,
decoration: BoxDecoration(
color: Colors.blue,
borderRadius:
BorderRadius.only(topLeft: Radius.circular(80))),
child: Center(child: Text('data')),
)
],
),
)
],
),
);
}
}

最佳答案

您实际上可以使用CustomClipper为此,请使用 Path quadraticBezierTo 方法:

class MyHomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Stack(
children: <Widget>[
Container(color: Colors.orange),
ClipPath(
clipper: TheCustomClipper(),
child: Container(
color: Colors.greenAccent,
),
),
],
),
),
);
}
}

class TheCustomClipper extends CustomClipper<Path> {
@override
getClip(Size size) {
var path = Path();
path.lineTo(0, size.height / 3);
var firstControlPoint = Offset(0, size.height / 3.5); // adjust the height to move start of the first curve
var firstEndPoint = Offset(size.width / 4.2, size.height / 3.5 + 10); // adjust the width to add the end controll point and height to move end of the first curve

var secControlPoint = Offset(size.width, size.height / 2.8); // adjust the height to move end of the second curve
var secEndPoint = Offset(size.width, size.height / 3 - 40); // adjust the width to add the right first controll point and height to move start of the second curve

path.quadraticBezierTo(firstControlPoint.dx, firstControlPoint.dy,
firstEndPoint.dx, firstEndPoint.dy);
path.quadraticBezierTo(
secControlPoint.dx, secControlPoint.dy, secEndPoint.dx, secEndPoint.dy);

path.lineTo(size.width, size.height / 3);
path.lineTo(size.width, 0);
path.close();
return path;
}

@override
bool shouldReclip(CustomClipper oldClipper) {
return null;
}
}

请注意,我只向第一个小部件添加了曲线。如果您想将另一个 CustomClipper 添加到 Stack 的第一个 Container 中,请通过执行相反的逻辑来完成。

输出:

enter image description here

关于 flutter : Achieved Sliverappbar Shape,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59518644/

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