【问题标题】:how to reduce appbar size in flutter如何在颤动中减小应用栏的大小
【发布时间】:2021-12-17 18:53:05
【问题描述】:

我有一个表单页面。在页面顶部,我写下了表格的名称。但问题是这个名字占用了很多空间(高度)。有没有可能降低这个高度?? 我的头像:

我的代码

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,),
      body: SingleChildScrollView(

【问题讨论】:

标签: flutter dart


【解决方案1】:

您可以使用 PreferredSize 小部件制作自定义应用栏。

return Scaffold(
      appBar: CustomAppBar(height: 50....

...

PreferredSize CustomAppBar({
  BoxDecoration decoration,
  EdgeInsets padding,
  Widget child,
  double height,
}) {
  return PreferredSize(
    preferredSize: Size.fromHeight(height),

    child: Container(
      padding: padding,
      decoration: decoration,
      child: child
      ),
  );
}

【讨论】:

    【解决方案2】:

    尝试使用 SafeArea 小部件,参考下面的代码希望对您有所帮助。参考 SafeArea here

     return SafeArea(
      child: Scaffold(
        appBar: AppBar(
          centerTitle: true,
          title: Text(
            'Search Here',
          ),
            ),
        body: SingleChildScrollView(),
      ),
    );
    

    您的结果屏幕->

    【讨论】:

      【解决方案3】:

      在 AppBar 中使用 toolbarHeight 设置高度

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2023-03-29
      • 2023-03-19
      • 2021-09-16
      • 2021-11-24
      • 1970-01-01
      • 1970-01-01
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多