颤动中的自动扩展容器--适用于所有设备 [英] Auto expanding Container in flutter -- for all devices

查看:0
本文介绍了颤动中的自动扩展容器--适用于所有设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个包含一些文本的容器来自动展开。我有一个API调用,可以是从5个单词到500个单词的任何内容。我不想只有一个固定的大小,很大,但包含10个单词。

我尝试过Expanded()和SizedBox.Expand(),但可能用错了

Card( 
 elevation: defaultTargetPlatform ==
      TargetPlatform.android ? 5.0 : 0.0,
  child: Column(
    children: <Widget>[
      Container(
        margin: const EdgeInsets.all(0.0),
        padding: const EdgeInsets.all(2.0),
        decoration: BoxDecoration(color: Colors.black),
        width: _screenSize.width,
        height: 250,
        child: Column(
          children: <Widget>[
            Container(
              color: Colors.black,
              width: _screenSize.width,
              height: 35,
              child: Padding(
                padding: const EdgeInsets.only(
                    left: 15, top: 11),
                child: Text("Title".toUpperCase(),
                  style: TextStyle(
                      color: Colors.white
                  ),
                ),
              ),
            ),
            Container(
              color: Colors.white,
              width: _screenSize.width,
              height: 210,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                mainAxisAlignment: MainAxisAlignment.start,
                children: <Widget>[
                  Padding(
                    padding: const EdgeInsets.only(top: 8, bottom: 5),
                    child: Text("Title of expanding text", style: TextStyle(
                      fontSize: 25,
                    ),
                    ),
                  ),
                  Text("Expanding text", style: TextStyle(
                      fontSize: 35,
                      fontWeight: FontWeight.w800
                  ),),
                ],
              ),
            ),
          ],
        ),
      ),
    ],
  ),
),

我只需要容器扩展,但保持小/变大

推荐答案

您是否尝试过根本不指定height?在这种情况下,Container应根据子项进行换行。

否则,该小部件有一个子级,但没有高度、宽度和 约束,并且没有对齐,并且容器传递 约束,并调整自身大小以匹配 孩子。

以上摘自Container的官方颤振文档。

这是官方颤振文档link

这篇关于颤动中的自动扩展容器--适用于所有设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆