Using the Text widget with text that's read from disk, that contains new line characters \n, does not go to new line. Anyone have suggestions of how I can get around this? The text in the file is
您在上面看到的图像的代码如下:
Text(valueFromFile, style: TextStyle(color: Colors.red))
我的文本是从我的资产文件夹中包含的 Xml 文件中读取的。
上面 uaraven 的评论
您的文件是否包含实际的“\n”字符?如果是这样,那么这不是一个新行字符......
帮助我想出了一个解决方案。由于文本小部件将 \n 字符解释为普通字符,因此我只是对其进行了替换并插入了实际的转义字符。
var correctlyEscapedString = valueFromFile.replaceAll('\\n', '\n');
Text(correctlyEscapedString, style: TextStyle(color: Colors.red));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)