Может кто-нибудь помочь мне в выравнивании макета в флаттер? - PullRequest
0 голосов
/ 26 мая 2019

Ниже приведен скриншот с неверным макетом:

Screenshot for reference

Как вы можете видеть выше, столбец внутри строки отталкивает других дочерних элементов.

Я удалил столбец из строки, и макет отображался как ожидалось. Однако мне нужно, чтобы этот столбец был частью строки.

class TitleSection extends StatelessWidget{
  @override
    Widget build(BuildContext context) {
      // TODO: implement build
      return Container(
        padding: EdgeInsets.all(32),
        child: Row(
          children: <Widget>[
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: <Widget>[
                  Text("Kratos",style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 20
                  )),
                  Text("The God Of War",
                    style: TextStyle(
                      color: Colors.grey[500]
                    ),
                  ),
                ],
              ),
            ),
            Icon(
              Icons.star,
              color: Colors.red,
            ),
            Text("143")
          ],
        )
      );
    }

}

1 Ответ

0 голосов
/ 26 мая 2019

Вместо того, чтобы обернуть Column в Expanded, который будет занимать как можно больше места, используйте Flexible, а также оберните другие виджеты внутри Column, чтобы вы могли легко расположить их:

 class TitleSection extends StatelessWidget{
    @override
    Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.all(32),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Flexible(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text("Kratos",style: TextStyle(
                    fontWeight: FontWeight.bold,
                    fontSize: 20
                )),
                Text("The God Of War",
                  style: TextStyle(
                      color: Colors.grey[500]
                  ),
                ),
              ],
            ),
          ),
          Flexible(
            child: Column(
              children: <Widget>[
                Row(
                  children: <Widget>[
                    Icon(
                      Icons.star,
                      color: Colors.red,
                    ),
                    Text("143")
                  ],
                ),
              ],
            ),
          ),
        ],
      )
    );
  }
}
...