首页 > 解决方案 > 根据 Appbar 高度更改前导和标题

问题描述

return Scaffold(
  appBar: 
    PreferredSize(
      preferredSize: Size.fromHeight(120),// change appbar size
    
      child:AppBar(
        backgroundColor: Color.fromARGB(255,254,202,8),
        leading:RawMaterialButton( 
          constraints: BoxConstraints(),
          padding: EdgeInsets.all(0), 
          child: Image.asset("assets/img/home.png",height:110), // set height as 110
        ),

        title:Text("mytitle");

我改变了appbar的高度preferredSize

并将前导图像高度设置为100

AppBar 高度已更改,但前导图标大小未更改。

还有文字。

如何根据应用栏大小更改前导和文本大小?

标签: flutterdart

解决方案


无法更改 中的leading大小AppBar,但一种解决方法是使用Row包含图像和标题的 并将此行设置为flexibleSpaceAppBar

AppBar(
              backgroundColor: Color.fromARGB(255, 254, 202, 8),
              flexibleSpace: Row(
                children: <Widget>[
                  RawMaterialButton(
                    constraints: BoxConstraints(),
                    padding: EdgeInsets.all(0),
                    child: Image.asset(
                      "assets/img/home.png",
                      height: 110,
                    ),
                  ),
                  Text("mytitle"),
                ],
              ),
            ),

推荐阅读