【问题标题】:Flutter-Is it possible to put a RichText class within a Container class in flutterFlutter-Flutter中是否可以在Container类中放入RichText类
【发布时间】:2020-12-19 01:28:21
【问题描述】:

所以我目前正在开发一个应用程序项目,我已经到了一个地步,我想将两行文本放在一行中。作为一个例子,它应该像这样 app demo created with figma。到目前为止,我有一排相同高度上的每个元素都包含在其中,但是我很难将 2 个元素放在一行中。我发现了这个名为 Stack 的类,但我很难实现它。在我的 Stack 类中,我有一个 RichText 类。从flutter api,我了解到您必须使用容器(才能定义位置)。所以我想知道是否应该在 Stack 类之后立即切换到容器类,然后在每个 Container 类中放置一个 RichText?如果我能对此有一些建议,或者只是关于如何在图片中创建类似的东西,那就太好了。提前致谢。

【问题讨论】:

  • 我的回答能解决你的问题吗?
  • 哦,是的,它就像一个魅力!非常感谢,我很难学习如何用颤振实现所有这些类。很抱歉耽搁了我正忙于学校工作,所以无法处理我的副业。

标签: flutter dart stack richtext


【解决方案1】:

添加了您想要实现的目标的演示:

        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            // row containing the avatar, name, date and icons (likes and comments)
            Row(
              children: [
                // circle avatart
                CircleAvatar(
                  backgroundColor: Colors.blue,
                  radius: 25,
                ),
                // spacing
                SizedBox(
                  width: 10,
                ),

                // the name of poster and date in a column
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      'Claire',
                    ),
                    Text(
                      'July 03 at 13:08PM',
                    ),
                  ],
                ),
                // spacer
                Spacer(),

                // likes icon
                Icon(Icons.favorite_border),
                Text(
                  '32',
                ),

                // spacing
                SizedBox(
                  width: 10,
                ),

                // comments icon
                Icon(
                  Icons.comment,
                ),
                Text(
                  '32',
                ),
              ],
            ),
            // spacing
            SizedBox(
              height: 10,
            ),
            // title text
            Text(
              'Dorm recommendation',
            ),

            // decription
            Text(
              'Any recommendations on dorm application? Does anyone know how\'s the facility at Talent Apartment? Are there teamrooms and gym in TA? Also, updates on the location of washers and dryers?',
              maxLines: 3,
              overflow: TextOverflow.ellipsis,
            ),
          ],
        ),

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-22
    • 2018-08-16
    • 2019-12-19
    • 2020-07-03
    • 2021-11-01
    相关资源
    最近更新 更多