gpt4 book ai didi

flutter - Sliver Appbar [Collapsing Toolbar] 在 Flutter 中从左到中心动画标题

转载 作者:行者123 更新时间:2023-12-04 00:22:55 25 4
gpt4 key购买 nike

这是我用于折叠工具栏的 Build 方法:-

     @override
Widget build(BuildContext context) {
return SafeArea(
child: CustomScrollView(
controller: controller,
slivers: <Widget>[
SliverAppBar(
pinned: true,
expandedHeight: appBarHeight,
leading: IconButton(
icon: Icon(
Icons.arrow_back_ios,
color: Colors.black,
),
onPressed: () => null,
),
floating: true,
flexibleSpace: FlexibleSpaceBar(

titlePadding: EdgeInsets.only(left:leftV , bottom:bottomV ),
title: Text(
"Title ",
style: TextStyle(
color: Colors.black,
fontSize: 16.0,
),
),
),
),
SliverList(delegate:
SliverChildBuilderDelegate((BuildContext context, int index) {
return ListTile(title: Text("Flutter / $index"));
}))
],
),
);
}

根据文档,我得到了删除填充的解决方案:-

/// By default the value of this property is /// EdgeInsetsDirectional.only(start: 72, bottom: 16) if the title is /// not centered, EdgeInsetsDirectional.only(start 0, bottom: 16) otherwise. final EdgeInsetsGeometry titlePadding;



但我得到的输出为:-

enter image description here

当应用栏完全折叠时,我想将标题居中。

问题也已在 github 中提交 check here.

最佳答案

我自己找到了解决方案!!!

将以下代码添加到您的 Sliver 应用栏 …………

 flexibleSpace: LayoutBuilder(
builder:
(BuildContext context, BoxConstraints constraints) {
double percent =
((constraints.maxHeight - kToolbarHeight) *
100 /
(appBarHeight - kToolbarHeight));
double dx = 0;

dx = 100 - percent;
if (constraints.maxHeight == 100) {
dx = 0;
}

return Stack(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(
top: kToolbarHeight / 4, left: 0.0),
child: Transform.translate(
child: Text(
title,
style: MyTextStyle.getAppBarTextStyle(
screenUtil, appColors),
),
offset: Offset(
dx, constraints.maxHeight - kToolbarHeight),
),
),
],
);
},
),

Percentage is calculated based on the scroll and it animation has been placed accordingly.



enter image description here

关于flutter - Sliver Appbar [Collapsing Toolbar] 在 Flutter 中从左到中心动画标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59243525/

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