【问题标题】:Why is the base64 string not showing completely?为什么base64字符串没有完全显示?
【发布时间】:2021-02-09 23:34:30
【问题描述】:

这是我的代码

_image1 = File(pickedImage.path);
List<int> imageBytes = _image1.readAsBytesSync();
String base64Image = base64.encode(imageBytes);
_shcpImg = base64Image;

但是当我打印字符串_shcpImg 时,它只打印了字符串的一部分,因为当我将该base64 复制并粘贴到在线转换器中时,它只显示了一小部分图像。所以问题是字符串没有完全显示或者base64编码器不能正常工作。 有什么建议吗?

【问题讨论】:

标签: flutter dart


【解决方案1】:

来自 cmets,因为您使用的是 VsCode,并且无法打印完整的字符串(长字符串)

您可以从dart: developer 使用log

如果字符串真的很长,有一个解决方法来解决这个问题,想法是使用RegExp 将长字符串分成小块(在示例中,每块长度为 800),然后迭代到结果中并打印每一件。

void printWrapped(String text) {
  final pattern = new RegExp('.{1,800}'); // 800 is the size of each chunk
  pattern.allMatches(text).forEach((match) => print(match.group(0)));
}

【讨论】:

  • 好的,我也更新了答案,也许将来会对其他人有所帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多