颤动的文本在右侧溢出

时间:2019-11-09 10:09:40

标签: flutter dart

我有一张卡片,其左列带有一个图标,而右列带有两个文本,右侧第一个文本出现溢出。 我可以在达到正确的限制时使正确的文字出现在缺点上。

      home: Scaffold(
        body: SafeArea(
          child: Container(
            height: 60,
            child: Card(
              child: Row(

                children: <Widget>[
                  Column(children: <Widget>[Padding(
                    padding: const EdgeInsets.all(10.0),
                    child: Icon(Icons.access_alarm),
                  )]),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                    Row(

                      children: <Widget>[
                        Text(

                        'This is the text one This is the textThis is the textThis is the textThis is the text',
                      )],
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        Text('This is the second text'),
                      ],
                    )
                  ],),
                ],
              ),
            ),
          ),
        ),
      ),
    );```

1 个答案:

答案 0 :(得分:2)

由于RowColumn的宽度不是静态的,因此它将展开以使屏幕溢出。为防止这种情况,请用children小部件包装Expanded

Scaffold(
      body: Container(
        height: 60,
        child: Card(
          child: Row(
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.all(10.0),
                child: Icon(Icons.access_alarm),
              ),
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(
                      'This is the text one This is the textThis is the textThis is the textThis is the text',
                    ),
                    Text('This is the second text'),
                  ],
                ),
              ),
            ],
          ),
        ),
      ),
    ),

由于有一些不必要的小部件,所以我对您的代码做了一些修改。