Flutter: Setting the height of the AppBar

前端 未结 7 2138
刺人心
刺人心 2020-12-08 01:49

How can I simply set the height of the AppBar in Flutter?

The title of the bar should be staying centered vertically (in that AppBar).

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 02:26

    In addition to @Cinn's answer, you can define a class like this

    class MyAppBar extends AppBar with PreferredSizeWidget {
      @override
      get preferredSize => Size.fromHeight(50);
    
      MyAppBar({Key key, Widget title}) : super(
        key: key,
        title: title,
        // maybe other AppBar properties
      );
    }
    

    or this way

    class MyAppBar extends PreferredSize {
      MyAppBar({Key key, Widget title}) : super(
        key: key,
        preferredSize: Size.fromHeight(50),
        child: AppBar(
          title: title,
          // maybe other AppBar properties
        ),
      );
    }
    

    and then use it instead of standard one

提交回复
热议问题