首页 > 解决方案 > 星星出现在容器的末尾

问题描述

我正在制作一个应用程序,但我不知道如何使评论中的星星出现在该容器的末尾(并且不使用 sizedBox(width:50) )任何想法?我已经尝试在行中使用 crossAligmentAxis 和 Main.. 但它没有帮助。

  return Container(
                                              margin: EdgeInsets.only(right:12, top:8 , bottom:0),
                                    width: MediaQuery.of(context).size.width - 140,
                                          decoration: BoxDecoration(
                                            color: Colors.white,
                                              boxShadow: [
                                                BoxShadow(
                                                    color: Colors.black
                                                        .withOpacity(0.1),
                                                    blurRadius: 2,
                                                    spreadRadius: 1)
                                              ],
                                              borderRadius:
                                                  BorderRadius.circular(4)),
                                          child: Column(
                                            children: [
                                              Row(
                                                children: [
                                                  CircleAvatar(
                                                    backgroundImage:
                                                        NetworkImage(snapshot
                                                            .data
                                                            .documents[index]
                                                            .data["avatarUrl"]),
                                                  ),
                                                  SizedBox(width: 8),
                                                  Text(
                                                      snapshot
                                                          .data
                                                          .documents[index]
                                                          .data["name"],
                                                      style: TextStyle(
                                                          fontWeight:
                                                              FontWeight.bold)),
                                                              SizedBox(width:50),
                                                                 Row(
                                                children: [
                                                  _buildRatingStars(snapshot
                                                      .data
                                                      .documents[index]
                                                      .data["rating"]),
                                                ],
                                                                 )
                                                                 ],
                                              ),

标签: flutter

解决方案


有一些miss的概念,这里你不要直接在row下使用children,我们应该尝试如下:

Column(
          children: [
          Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              CircleAvatar(
                backgroundImage:
                NetworkImage(snapshot
                    .data
                    .documents[index]
                    .data["avatarUrl"]),
              ),
              SizedBox(width: 8),
              Text(
                  snapshot
                      .data
                      .documents[index]
                      .data["name"],
                  style: TextStyle(
                      fontWeight:
                      FontWeight.bold)),
              SizedBox(width:50),
              Text(snapshot
                  .data
                  .documents[index]
                  .data["rating"])
            ],
          ),

推荐阅读