flutter - flutter 中的自动扩展容器——适用于所有设备

标签 flutter containers expand

我需要一个包含一些文本的容器来自动展开。我有一个 API 调用,它可以是 5 到 500 个单词之间的任何内容。我不想只有 1 个很大但包含 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 应该根据 child 包装。

Otherwise, the widget has a child but no height, no width, no constraints, and no alignment, and the Container passes the constraints from the parent to the child and sizes itself to match the child.

以上是 Container 官方 flutter 文档的摘录。

这里是 flutter 的官方文档 link .

关于flutter - flutter 中的自动扩展容器——适用于所有设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55609811/

相关文章:

flutter - searchable_dropdown 不适用于类列表

go - 从源代码构建 runc 时出错

jquery - 如何让 jQuery .expander 在加载时调用,而不仅仅是在单击时调用?

ios - 使用 Flutter 包 firebase_messaging 的后台通知不适用于 iOS

android - Flutter 更改所选选项卡的背景

flutter - 按字母顺序对文件进行排序

css - 用CSS展开和折叠

mysql - Kubernetes mysql 8.0.13 无法从 ENV 正确初始化

c++ - 如果类包含标准容器,我可以将类 move 操作标记为 noexcept 吗?

java - 如何扩展 JTree 节点(提前),但保持它们不可见