【问题标题】:How To Place AppBar Title in Left Side in Flutter如何在 Flutter 中将 AppBar 标题放在左侧
【发布时间】:2020-03-13 17:57:33
【问题描述】:

这是我的 AppBar Tittle 代码,但它不起作用

 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"),
    ),
  ),
);}

【问题讨论】:

    标签: flutter flutter-appbar


    【解决方案1】:

    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"),
          ),
        ),
      );
    }
    

    【讨论】:

      【解决方案2】:

      Transform 是用于在 x-y-z 维度上强制转换小部件的小部件。

      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,
                      ),
                    ),
                  ),
              ),
            );
      

      【讨论】:

      • 如果有人使用SliverAppBar -> FlexibleSpaceBar 也设置centerTitle: falseFlexibleSpaceBar 中。
      • 标题间距也可以使用负值。
      【解决方案3】:

      只需在 AppBar 小部件中将 centerTile 属性设置为 false

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

      【讨论】:

        【解决方案4】:

        centerTitle 属性设置为 false。

        【讨论】:

        • 不设置leadingwidth似乎无法工作
        【解决方案5】:

        在 AppBar 中将 centerTile 属性设置为 false 和 leadingWidth: 0

        【讨论】:

        • 获得相同尺寸的前导小部件:leadingWidth: NavigationToolbar.kMiddleSpacing,
        【解决方案6】:

        如果你想在 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"),
              ),
            ),
          );
        }
        

        将文本强制放在应用栏的最左侧

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-06-18
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2020-04-02
          • 1970-01-01
          • 2018-03-19
          • 1970-01-01
          相关资源
          最近更新 更多