You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter开发中如何减小AppBar的高度以节省页面空间?

Flutter调整AppBar高度方案

直接修改AppBar组件的toolbarHeight属性即可自定义高度,该属性默认值为56,你可以根据视觉需求下调到合适数值,示例修改后的代码如下:

class Form_ttn extends StatefulWidget {
  @override
  _SettingsScreenState createState() => _SettingsScreenState();
}

class _SettingsScreenState extends State<Form_ttn> {
  bool lockInBackground = true;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('ТТН'), 
        centerTitle: true,
        backgroundColor: Colors.blueGrey,
        // 新增此行调整AppBar高度,数值可按需修改
        toolbarHeight: 42,
      ),
      body: SingleChildScrollView(
      // 你的原有后续代码
      )
    );
  }
}

补充说明

  • 如果你的AppBar带有左侧返回按钮,觉得按钮边距过大可以同步调整leadingWidth属性,比如设置为leadingWidth: 30来压缩左侧占位
  • 如果你需要全局调整所有AppBar的高度,可以在根组件的ThemeData中统一配置appBarTheme: AppBarTheme(toolbarHeight: 42)

你当前的效果参考:
效果展示图

内容的提问来源于stack exchange,提问作者MaksIngenr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 18:54:08