首页 > 解决方案 > 如何增加 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(),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );

截图如下:

我想要达到的目标

我想要达到的目标

我得到了什么

在此处输入图像描述

是否有任何解决方法或无论如何可以增加高度?谢谢!

标签: flutterflutter-layoutflutter-sliverflutter-cupertino

解决方案


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”解决方案有用!

结果: 演示图像


推荐阅读