gpt4 book ai didi

flutter - 调整 flutter AppBar 中领先小部件的大小

转载 作者:行者123 更新时间:2023-12-02 12:09:23 24 4
gpt4 key购买 nike

我正在制作一个比典型 AppBar 更高的自定义 AppBar。我还想调整前导小部件/图标的大小,并利用 automaticallyImplyLeading 默认行为(以便自动实现菜单图标和后退图标)。

这是我认为我会实现的解决方案:

class AppAppBar extends PreferredSize{
AppAppBar(String title) : super(
preferredSize: Size.fromHeight(56.0),
child: AppBar(
centerTitle: true,
title: Text(title, style: textStyle)
)) {
(child as AppBar).leading =
SizedBox(width: 30.0, height: 30.0, child: (child as AppBar).leading);
}

static const textStyle = TextStyle(fontSize: 32.0);
}

但是这当然行不通,因为 (child as AppBar).leading 是最终的。

因此,在下面的 AppBar 中(出于说明目的,文本大小显着变大),我想让自动添加的汉堡包图标相比之下更大。

enter image description here

你觉得怎么样?有没有解决方案,或者我应该放弃自动图标并自己添加它们?

编辑:添加了一张图片来显示我的意思

最佳答案

你不能,因为它是一个预定义的小部件。

您可以使用 Row 小部件解决此问题:

Scaffold(
key:_scaffoldKey,
drawer: Drawer(),
appBar: AppBar(
automaticallyImplyLeading: false
title: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(
height: 20, // Your Height
width: 20, // Your width
child: IconButton( // Your drawer Icon
onPressed: () => _scaffoldKey.currentState.openDrawer()),
icon: Icon(Icons.arrow_back, color: Colors.white),
),)
// Your widgets here
],
),
),
)

您需要 key 才能使用 _scaffoldKey.currentState.openDrawer() 打开抽屉。

automaticallyImplyLeading: false 将阻止默认抽屉图标。

关于flutter - 调整 flutter AppBar 中领先小部件的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52082857/

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