【问题标题】:How to solve truncated text in flutter?如何解决flutter中截断的文本?
【发布时间】:2022-10-02 07:19:41
【问题描述】:

存在文章内容较长时,文章出不来的问题。我不知道如何用我的代码解决这个问题……我使用了 firebase 数据库服务。

这是我的代码。

   Widget _buildBody() {
    return SafeArea(
     child: StreamBuilder<QuerySnapshot>(
       stream: Firestore.instance.collection(\'post\').snapshots(),
       builder: (context, snapshot) {
         if (!snapshot.hasData) {
           return _buildNoPostBody();
              }
            return _buildHasPostBody(snapshot.data.documents);
           }
         ),
       );
     }

      Widget _buildNoPostBody() {
       return SingleChildScrollView(

          );
        }

      Widget _buildHasPostBody(List<DocumentSnapshot> documents) {
      final myPosts = documents
      .where((doc) => doc[\'email\'] == user.email)
      .take(999999999999999)
      .toList();

      final otherPosts = documents
     .where((doc) => doc[\'email\'] != user.email)
     .take(999999999999999)
     .toList();

      myPosts.addAll(otherPosts);

      return ListView(
         children: myPosts.map((doc) => FeedWidget(doc, user)).toList(),
             );
          }

       }

标签: flutter firebase dart


【解决方案1】:

希望你好好的,

很抱歉,我误解了您的问题,所以让我们通过将此代码添加到您的 feed_widget.dart 来解决此问题。

Center(
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text(
              '좋아요 5 개',
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15.0),
            ),
            const SizedBox(height: 8),
            Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: const [
                Text(
                  "display name",
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                SizedBox(
                  width: 8.0,
                ),
                Expanded(child: Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat")),
              ],
            ),
          ],
        ),
      ),
    ),
  • 在这里你只需要用expanded 包裹你的text widget,这样它就可以根据可用的内容进行扩展。

  • end result screenshot

  • 希望我能帮上忙,祝你有美好的一天:)

【讨论】:

  • 此代码将包含在 feed_widget?
猜你喜欢
  • 2019-10-12
  • 1970-01-01
  • 2013-08-07
  • 2016-03-08
  • 2019-03-23
  • 2017-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多