flutter - 如何增加 CupertinoSliverNavigationBar 的高度
问题描述
我试图用颤振克隆 WhatsApp(iOS 版本)Cupertino Widgets
。
在尝试制作标题时,CupertinoSliverNavigationBar
我注意到CupertinoSliverNavigationBar
无法增加高度。
我的代码
return CupertinoPageScaffold(
child: NotificationListener<ScrollNotification>(
onNotification: (scrollNotification) {
if (scrollNotification is ScrollStartNotification) {
_onStartScroll(scrollNotification.metrics);
} else if (scrollNotification is ScrollUpdateNotification) {
_onUpdateScroll(scrollNotification.metrics);
} else if (scrollNotification is ScrollEndNotification) {
_onEndScroll(scrollNotification.metrics);
}
},
child: CustomScrollView(
slivers: <Widget>[
CupertinoSliverNavigationBar(
leading: GestureDetector(
child: Padding(
padding: EdgeInsets.only(top: 10.0),
child: Text(
"Edit",
style: TextStyle(
color: Constants.primaryColor,
fontSize: 18.0,
),
),
),
onTap: ()=>print("Tapped"),
),
trailing: GestureDetector(
child: Icon(
CupertinoIcons.create_solid,
size: 25.0,
),
onTap: ()=>print("Tapped"),
),
automaticallyImplyLeading: false,
largeTitle: Column(
children: <Widget>[
Container(
child: Text(
"Chats",
textAlign: TextAlign.left,
),
),
GestureDetector(
child: SearchBar(),
),
],
),
),
],
),
),
);
截图如下:
我想要达到的目标
我得到了什么
是否有任何解决方法或无论如何可以增加高度?谢谢!
解决方案
Flutter 纯粹主义者和拥护者会杀了我,但这些尺寸是常量值的一部分(如 MaterialDesign 指南值),2 个快速选项:
方案一: 直接修改SDK:Ctrl(或Cmd)+点击CustomScrollView,会打开flutter/lib/src/cupertino/nav_bar.dart
修改第 22 或 26 行:
/// This height is constant and independent of accessibility as it is in iOS.
const double _kNavBarPersistentHeight = 44.0;
/// Size increase from expanding the navigation bar into an iOS-11-style large title
/// form in a [CustomScrollView].
const double _kNavBarLargeTitleHeightExtension = 52.0; // change this one!
选项 2: 直接在项目中复制 nav_bar.dart 并进行修改,或者更好的是,获取 CustomScrollView() 的所有依赖项,并将您自己的名称和您自己的值放在那里......我想这不仅仅是一个标准根据 Apple 的设计指南,多个开发人员需要能够更改这些值。也许我们应该打开一个 Github 请求。
希望您发现我的“hacky”解决方案有用!
推荐阅读
- testing - 通过在 TestCafe 中包含文本来选择元素
- hp-nonstop - TACL 如何使用多个参数
- python - 将nan转换为数字
- java - 如何使用带有命名属性和声明为附加属性的属性的 openAPI 模型的 swagger-codegen
- javascript - Fabric Js无法设置值originY底部
- python - OSError: [WinError 126] 在 Python 中找不到指定的模块
- proxy - WSDL.exe - 如何生成 cs 文件
- google-cloud-platform - 如何一次性将整个 blob(图像)文件夹从谷歌存储桶下载到 AI Platform Notebooks?
- c# - PropertyGrid:仅为特定属性删除自定义数据类型的属性
- c++ - C++ 过滤器管道