首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对齐问题Appbar

对齐问题Appbar
EN

Stack Overflow用户
提问于 2020-02-14 19:40:37
回答 1查看 37关注 0票数 0

如何将名称放在离"Welcome Back“文本更近的位置?我试过用centerTitle: true和textAlign: TextAlign.center来做这件事,但到目前为止还没有成功?我错过了什么?

代码语言:javascript
复制
 return new Scaffold(
      appBar: new AppBar(
          brightness: Brightness.light,
          backgroundColor: Colors.white,
          elevation: 0,
          centerTitle: true,
          title: Text(
            "Welcome Back,",
            textAlign: TextAlign.center,
            style: TextStyle(
                color: Color.fromRGBO(49, 39, 79, 1),
                fontWeight: FontWeight.bold,
                fontSize: 20),
          ),
          actions: <Widget>[
            Row(
              children: <Widget>[
                Container(
                    child: Text(name,
                        textAlign: TextAlign.center,
                        style: TextStyle(
                            color: Color.fromRGBO(49, 39, 79, 1),
                            fontWeight: FontWeight.bold,
                            fontSize: 20))),

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-15 00:35:19

只需在Padding()中自定义left:

代码语言:javascript
复制
actions: <Widget>[
  Row(
    children: <Widget>[
    Container(
      child: Text(name, style: TextStyle(color: Color.fromRGBO(49, 39, 79, 1), fontWeight: FontWeight.bold,fontSize: 20))
    ),
    /// Play with the parameter `left: ...`
    Padding(padding: const EdgeInsets.only(left: 30, right: 8.0, top: 8.0, bottom: 8.0),
      child: CircleAvatar(
               backgroundImage: NetworkImage(imageUrl)),
      ),
    ],
  ),
]

另一种解决方案:在AppBar-Title中使用变量name

代码语言:javascript
复制
title: Text("Welcome Back, $name", style: TextStyle(color: Color.fromRGBO(49, 39, 79, 1), fontWeight: FontWeight.bold,fontSize: 20),),
actions: <Widget>[
  Row(
    children: <Widget>[
    /// Play with the parameter `left: ...`
    Padding(padding: const EdgeInsets.only(left: 30, right: 8.0, top: 8.0, bottom: 8.0),
      child: CircleAvatar(
               backgroundImage: NetworkImage(imageUrl)),
      ),
    ],
  ),
]

结果:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60225638

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档