您好,我尝试将文件转换为字节时出现错误。知道该怎么做;)
onTap: () async {
_pickedImage =
await _picker.getImage(source: ImageSource.gallery);
File _imageFile = File(_pickedImage.path);
ByteData bytes = await _imageFile
.readAsBytes()
.then((data) => ByteData.view(data as ByteBuffer));
错误输出
[VERBOSE-2:ui_dart_state.cc(166)] Unhandled Exception: Converting object to an encodable object failed: TypedDataView(cid: 148)
#0 _JsonStringifier.writeObject (dart:convert/json.dart:687:7)
#1 _JsonStringifier.writeMap (dart:convert/json.dart:768:7)
#2 _JsonStringifier.writeJsonValue (dart:convert/json.dart:723:21)
#3 _JsonStringifier.writeObject (dart:convert/json.dart:678:9)
#4 _JsonStringStringifier.printOn (dart:convert/json.dart:876:17)
#5 _JsonStringStringifier.stringify (dart:convert/json.dart:861:5)
#6 JsonEncoder.convert (dart:convert/json.dart:261:30)
#7 JsonCodec.encode (dart:convert/json.dart:171:45)
#8 _RegisterFormScreenState.uploadPictureApiCall (package:korki/register_form_screen.dart:61:18)
<asynchronous suspension>
#9 _RegisterFormScreenState.build.<anonymous closure> (package:korki/register_form_screen.dart:142:38)
#10 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:945:19)
#11 _InkResponseState.bui<…>
答案 0 :(得分:0)
您不能直接将UinitList8转换为Bytebuffer。但是它确实提供了将其转换为更高版本的吸气剂
onPressed: () async {
_pickedImage = await _picker.getImage(source: ImageSource.gallery);
_imageFile = File(_pickedImage.path);
ByteData bytes = await _imageFile
.readAsBytes()
// change here
.then((Uint8List data) => ByteData.view(data.buffer));
},