【问题标题】:How to move the flutter app bar logo to center left如何将颤动的应用栏徽标移动到左侧中心
【发布时间】:2021-11-11 06:29:27
【问题描述】:

我想在应用栏上显示一个标志,并通过以下代码实现。

 appBar: AppBar(
      backgroundColor: Colors.white,
      elevation: 3,
      title: Align(
        alignment: Alignment.centerLeft,
        child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Align(
                alignment: Alignment.centerLeft,
                child: Image.asset(
                  'assets/logo/logo.jpg',
                  fit: BoxFit.fitWidth,
                  height: MediaQuery.of(context).size.height * 0.3,
                  width: MediaQuery.of(context).size.width * 0.2,
                ),
              ),
            ]),
      )),

输出越来越好

这里的问题是图标居中怎么能这样粘在右边

期望的输出

和上面的代码一样,我已经试过了

 alignment: Alignment.centerLeft,

crossAxisAlignment: CrossAxisAlignment.start,

仍然没有工作有人知道吗?请支持。

【问题讨论】:

  • 尝试在Appbar Widget 中将automaticallyImplyLeading 属性设置为false。
  • 感谢朋友的帮助(:如果您发布答案,我将接受答案。

标签: flutter appbar


【解决方案1】:

试试下面的代码希望它对你有帮助。只需更改动作标签内的小部件(如您的图像)

Scaffold(
  appBar: AppBar(
    title:Image.network(
      'https://image.shutterstock.com/image-photo/kiev-ukraine-may-03-2015-260nw-275974145.jpg',
    ),
    automaticallyImplyLeading:false,
    actions: <Widget>[
      Icon(Icons.add),
      Icon(Icons.person),
    ],
  ),
)

您的结果屏幕->

【讨论】:

  • 我想要图像作为徽标。我不想要title:Text('title here')。在我的代码中看到我正在使用行小部件将图像显示为徽标。 title: Row().....
  • 检查更新的答案,只需更改您的图像而不是我的图像
  • 这帮助我解决了这个问题。 automaticallyImplyLeading:false。谢谢你的回答。
【解决方案2】:

看起来您的代码几乎完成了。这是将您的徽标放在 appbar 左侧的 sn-p。

AppBar(
      backgroundColor: Colors.white,
      elevation: 3,
      title: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Image.asset(
              'assets/nividata-logo.png',
              fit: BoxFit.fitWidth,
              height: MediaQuery.of(context).size.height * 0.3,
              width: MediaQuery.of(context).size.width * 0.2,
            ),
          ])),

好的,正如你所看到的,我刚刚使用了 row 并给出了 mainAxisAlignment 开始,所以这会将每个元素从开始放在 row 内。

如果我将其更改为下面的代码,那么它将开始从右侧(结束)放置元素。

mainAxisAlignment: MainAxisAlignment.end,

您还可以查看下面的屏幕截图,了解我使用上述代码获得的结果。

【讨论】:

  • 请参阅我的代码中还使用了mainAxisAlignment: MainAxisAlignment.start,。但它仍然不会开始
  • 请尝试复制我的代码并尝试运行,我的代码左侧也有徽标。我认为您的代码没有错,可能是您没有添加所有代码。可能是其他一些代码阻止了预期的结果。
  • 是的,您的回答在逻辑上是正确的,但是,这帮助我解决了这个问题。 automaticallyImplyLeading:false。感谢您的回答,我赞成您的回答。
【解决方案3】:

是的,从其中一条评论中得到了答案。 automaticallyImplyLeading:false。 这解决了问题

【讨论】:

    【解决方案4】:

    这仅仅是因为当您从另一个页面导航时应用栏应用了默认行距,并且不知何故该行距图标为白色。

    如果您在开发工具中启用显示边界,您会看到默认前导图标占据了该空白点。

    这个问题有两种可能的结果。

    You can change the color to any visible color.
    
    - This will help the user to navigate back.
    
    You can try to set the "automaticallyImplyLeading" property to "false" in the "Appbar" Widget.
    
    - This will disable the default leading icon in the Appbar.
    

    【讨论】:

    • 是的,你是对的
    猜你喜欢
    • 1970-01-01
    • 2018-04-19
    • 2021-03-15
    • 2020-05-13
    • 1970-01-01
    • 2023-03-23
    • 2019-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多