簡體   English   中英

Flutter如何在左側放置AppBar標題

[英]How To Place AppBar Title in Left Side in Flutter

這是我的 AppBar Title 代碼,但它不起作用

 Widget build(BuildContext context){
return new Scaffold(
  appBar: new AppBar(
    title: new Padding(
      padding: const EdgeInsets.only(left: 20.0),
      child: new Text("App Name"),
    ),
  ),
);}

centerTitle屬性設置為 false。

Transform 是用於在 xyz 維度中強制轉換小部件的小部件。

return Scaffold(
        appBar: AppBar(
          centerTitle: false,
          titleSpacing: 0.0,
          title:  Transform(
              // you can forcefully translate values left side using Transform
              transform:  Matrix4.translationValues(-20.0, 0.0, 0.0),
              child: Text(
                "HOLIDAYS",
                style: TextStyle(
                  color: dateBackgroundColor,
                ),
              ),
            ),
        ),
      );

在 AppBar 中將centerTile屬性設置為 false 和leadingWidth: 0

只需在 AppBar 小部件centerTile屬性設置為false

 AppBar(
        ...
        centerTitle: false,
        title: Text("App Name"),
        ...
        )

AppBar 標題默認位於中心位置。 要使文本在左側,您應該將屬性 centerTitle 設置為 false,如下所示:

Widget build(BuildContext context){
  return new Scaffold(
    appBar: new AppBar(
      centerTitle: false
      title: new Padding(
        padding: const EdgeInsets.only(left: 20.0),
        child: new Text("App Name"),
      ),
    ),
  );
}
appBar: AppBar(
  centerTitle: false,
  backgroundColor: Color(0xff98A8D0),
  title: Image.asset(
    'assets/covalent_dark_icon.png',
    height: 45,
    width: 120,
  ),
)

這是實際的方法。 使用 Transform 會降低你的 UI 響應速度。

對我來說, automaticallyImplyLeading: false解決了這個問題。

如果你想在 appbar 的最左邊顯示標題

Widget build(BuildContext context){
  return new Scaffold(
    appBar: new AppBar(
      centerTitle: false,
      leadingWidth: 0, // this is also im
      title: new Padding(
        padding: const EdgeInsets.only(left: 25.0),
        child: new Text("App Name"),
      ),
    ),
  );
}

將強制文本到應用欄的最左側

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM