Панель приложения Alignment Issue - PullRequest
0 голосов
/ 14 февраля 2020

Как разместить имя ближе к тексту "Добро пожаловать назад"? Я пытался сделать это с помощью centerTitle: true и textAlign: TextAlign.center, но пока не повезло? Чего мне не хватает?

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

enter image description here

1 Ответ

2 голосов
/ 14 февраля 2020

Просто настройте left: в Padding():

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

Другое решение: используйте переменную name в AppBar-Title:

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

Результат:

enter image description here

...