Flutter snackbar 在显示多行文本时抛出渲染溢出错误

Flutter snackbar throws render overflow error when displaying multiple lines of text

有没有办法在 snackbar 上显示多行文本而不引发 renderflex 错误?

我尝试用 Flexible 和 Expanded 小部件包装它,但两者都没有帮助,我仍然遇到错误。以下方法收到的errorMessage有时可能会很长。

  void displayMessage(context, errorMessage) {
    ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Expanded(
            child: Row(
                children: [
                  const Icon(
                    Icons.warning,
                    color: Colors.red,
                    size: 22,
                  ),
                  const SizedBox(
                    width: 7,
                  ),
                  Text(
                    errorMessage,
                    style: const TextStyle(
                        fontWeight: FontWeight.normal,
                        fontSize: 17,
                        color: Colors.red),
                  ),
                ],
              ),
          ),
          backgroundColor: Colors.black,
          padding: const EdgeInsets.all(20),
          duration: const Duration(milliseconds: 5000),
          behavior: SnackBarBehavior.floating,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10.0),
          ),
        )
    );
  }

删除 Expanded 并将 Text 换成 Flexible,

 content: Row(
          children: [
            const Icon(
              Icons.warning,
              color: Colors.red,
              size: 22,
            ),
            const SizedBox(
              width: 7,
            ),
            Flexible(
              child: Text(
                errorMessage,
                style: const TextStyle(
                    fontWeight: FontWeight.normal,
                    fontSize: 17,
                    color: Colors.red),
              ),
            ),
          ],
        ),