flutter - 为什么base64字符串没有完全显示?
问题描述
所以这是我的代码
_image1 = File(pickedImage.path);
List<int> imageBytes = _image1.readAsBytesSync();
String base64Image = base64.encode(imageBytes);
_shcpImg = base64Image;
但是当我打印 string 时_shcpImg
,它只打印了字符串的一部分,因为当我将该 base64 复制并粘贴到在线转换器中时,它只显示了一小部分图像。所以问题是字符串没有完全显示或者base64编码器不能正常工作。有什么建议么?
解决方案
从评论中,由于您使用的是 VsCode 并且您无法打印完整的字符串(长字符串)
您可以使用log
from dart: developer
,
如果字符串真的很长,有一个解决方法来解决这个问题,想法是将你的长字符串分成小块(在示例中,每块长度为 800)RegExp
,然后迭代到结果中并打印每一块。
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)));
}
推荐阅读
- spring - 如何在 Spring JPA 中获取特定列?
- python - 根据条件为自定义列分配值
- mysql - 配对表查询
- python - 为什么安装mysqlclient时显示错误?
- javascript - 为什么我在运行 changeword.js 时会得到 undefined 这个词?
- java - 如何将文件转换为 array2D?
- java - OneToOne 与复合 PK 与相关表中的列
- swift - 如何在 SwiftUI 中给 DatePicker 一个分钟间隔
- docusignapi - Docusign API 日期和名称选项卡不显示
- reactjs - 当您使用 React 生成静态标记时,是否不需要“key”道具?