Flutter: Setting the height of the AppBar

前端 未结 7 2127
刺人心
刺人心 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条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 02:34

    You can use PreferredSize:

    class MyApp extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Example',
          home: Scaffold(
            appBar: PreferredSize(
              preferredSize: Size.fromHeight(50.0), // here the desired height
              child: AppBar(
                // ...
              )
            ),
            body: // ...
          )
        );
      }
    }
    

提交回复
热议问题