首页 > 解决方案 > 如何解决“A RenderFlex 在右侧溢出”。行错误?

问题描述

我在 Row 小部件上收到错误消息。我该如何解决?

在此处输入图像描述

Column(
    children: [
      Padding(
        padding: const EdgeInsets.all(20.0),
        child: Row( // error is shown on this line
          children: [
            const Image(
              height: 120,
              width: 120,
              image: NetworkImage(...),
            ),
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Wrap(
                spacing: 5.0,
                runSpacing: 5.0,
                direction: Axis.vertical,
                children: [
                  Text('Message:'),
                  Text('Hello world! How are you doing?'),
                ],
              ),
            )
          ],
        ),
      ),
    ],
),

右侧的 RenderFlex 溢出了 16 个像素。

标签: flutter

解决方案


Expanded顶部的小部件Padding为您解决问题

Column(
        children: [
          Padding(
            padding: const EdgeInsets.all(0.0),
            child: Row(
              // error is shown on this line
              children: [
                Image(
                  height: 120,
                  width: 120,
                  image: NetworkImage(""),
                ),
                Expanded(
                    child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Wrap(
                    spacing: 5.0,
                    runSpacing: 5.0,
                    direction: Axis.vertical,
                    children: [
                      Text('Message:'),
                      Text(
                          'Hello world! How are you doing?',),
                    ],
                  ),
                ))
              ],
            ),
          ),
        ],
      ),

推荐阅读