Expand The App bar in Flutter to Allow Multi-Line Title?

前端 未结 6 951
名媛妹妹
名媛妹妹 2021-02-04 02:28

Does anyone know how I can create an app bar with a multi-line title, as per the material guidelines show here?

https://material.io/design/components/app-bars-top.html#

6条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-04 03:01

    This can be achieved by replacing the "title" property of AppBar with "flexibleSpace":

      Scaffold(
        appBar: AppBar(
          flexibleSpace: Center(
            child: Column(
              children: [
                Text('Title Line One'),
                Text('Title Line Two'),
              ],
            ),
          ),
        ),
        body: body
      ),
    

    If overflow occurs due to height, just wrap AppBar with a PreferredSize widget and set the height to a higher value than the default one:

      Scaffold(
        appBar: PreferredSize(
          preferredSize: Size.fromHeight(100),
          child: AppBar(...),
        ),
      ),
    

提交回复
热议问题