如何增加 CupertinoSliverNavigationBar 的高度
How to increase height of CupertinoSliverNavigationBar
我正在尝试使用 Cupertino Widgets
.
克隆 WhatsApp(iOS 版本)
在尝试使用 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 个快速选项:
选项 1:
直接修改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" 解决方案对您有用!
结果:
您不需要修改 SDK 或类似的东西。
我找到了一个简单的解决方案。
将此添加到 CustomScrollView,调整锚点,直到获得合适的 UI。
自定义滚动视图(
锚点:0.07,
See the image here
我正在尝试使用 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 个快速选项:
选项 1: 直接修改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" 解决方案对您有用!
结果:
您不需要修改 SDK 或类似的东西。 我找到了一个简单的解决方案。
将此添加到 CustomScrollView,调整锚点,直到获得合适的 UI。 自定义滚动视图( 锚点:0.07,
See the image here