【问题标题】:AppBar Title sticks to the left side of the screenAppBar Title 贴在屏幕左侧
【发布时间】:2018-03-19 19:19:04
【问题描述】:

为什么标题贴在左边而不是留一些空间?

这是脚手架代码

return new Scaffold(
        appBar: new AppBar(title: const Text('Friendlychat')),);

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

    有几种方法可以修改它:

    您可以将title 小部件包装在Padding 小部件中,并使用padding 属性缩进左侧区域。

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

    或者您可以在AppBarleading 属性中添加一个空的Container

    @override
      Widget build(BuildContext context) {
        return new Scaffold(
            appBar: new AppBar(
              title:new Text ("Friendly Chat"),
              leading: new Container(),
            ),
        );
      }
    

    如果您希望标题居中,请将AppBar 中的属性centerTitle 设置为true

    @override
      Widget build(BuildContext context) {
        return new Scaffold(
            appBar: new AppBar(
              title:new Text ("Friendly Chat"),
              centerTitle: true,
            ),
        );
      }
    

    【讨论】:

      【解决方案2】:

      这是当前 Flutter alpha 版本的回归,已在 master 中修复 - 请参阅此 issue

      目前,aziza 的答案中提到的任何解决方法都可以使用,但是当新的 alpha 发布时您必须恢复它

      【讨论】:

        【解决方案3】:

        这是当前flutter alpha版本的回归,正如@aptik.Thanks所指出的那样,它已在master中修复

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-03-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多