flutter - 更喜欢 const 文字作为 @immutable 类上构造函数的参数

标签 flutter flutter-layout

我正在遵循 this 的示例教程。

如果我想将两个文本组件添加到子数组中,我会收到标题警告。

例如:

Widget titleSection = Container(
  child: Row(
    //need to expand the rows on the column
    children: [
      Expanded(
        child: Column(
          children: [
            const Text(
              'Hello1',
            ),
            const Text(
              'Hello2',
            ),
          ],
      )         
    ],
  ),
);

我做错了什么?

最佳答案

在你的情况下应该是

    Widget titleSection = Container(
      child: Row(
        //need to expand the rows on the column
        children: [
          Expanded(
            child: Column(
              children: const [
                Text(
                  'Hello1',
                ),
                Text(
                  'Hello2',
                ),
              ],
            ),
          )
        ],
      ),
    );

关于flutter - 更喜欢 const 文字作为 @immutable 类上构造函数的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69002584/

相关文章:

json - Flutter:FutureBuilder 类型 'FormatException' 不是类型 'Widget' 的子类型

flutter - 我的 Flutter ListView 总是从列表中删除最后一项

flutter - 将映射列表显示到列中以进行抖动

Flutter - 自动调整 AlertDialog 大小以适应列表内容

flutter - 如何在 Flutter 的 SliverAppBar 的 flexibleSpace 中移动 Action 和标题?

flutter - 如何等待功能完成?

flutter - 如何在 flutter 中将 List<Asset> 转换为 List<File>

flutter - 如何使用 onFieldSubmitted 单独验证 TextFormField

flutter - Flutter float 操作按钮位置问题

ios - Flutter TextField Ipad中文输入法,选择始终放在最前面