首页 > 解决方案 > 在 Flutter 中添加新文本行的问题

问题描述

appBar: PreferredSize(
preferredSize: Size.fromHeight(330.0),
child: AppBar (
  backgroundColor: Color(0xFF1D153B),
  title: RichText(
    text: TextSpan (
      style: DefaultTextStyle.of(context).style,
      children: <TextSpan> [
        TextSpan (text :'Makan Bang'),
        TextSpan (text :'Makan Bang'),
        TextSpan (text :'Makan Bang'),
      ],
    ),
  ),
),

终端说“没有名为'children'的命名参数”。除了使用 RichText 小部件之外,我还有其他方法可以添加新的文本行吗?

标签: flutterdart

解决方案


在剪切标题小部件的边界之前,您最多可以有两/三行:

child: AppBar(
          backgroundColor: Color(0xFF1D153B),
          title: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text('first line'),
                Text('second line'),
              ],
            ),
        ),

或者您可以使用 AppBar 的灵活空间属性(背景空间)来添加小部件:

        child: AppBar(
          backgroundColor: Color(0xFF1D153B),
          flexibleSpace: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text('example text'),
              Text('example text'),
              Text('example text'),
              Text('example text'),
              Text('example text'),
              Text('example text'),
              Text('example text'),
              Text('example text'),
            ],
          ),
        ),

推荐阅读