无法将 XFile 类型的值分配给 List<XFile>
A value of type XFile cant be assigned to List<XFile>
我想将相机拍摄的图像保存到列表以在 GridView 中显示多个图像。但我不知道该怎么做 it.I 想将 XFile 列表添加到变量 _imagesList
List<XFile> _imagesList=[];
void selectCamera(ImageSource imagesource,BuildContext cntxt) async {
File cameraImages = await _picker.pickImage(source: imagesource); //error
if(cameraImages!=null){
_imagesList.addAll(cameraImages);
}
for(var img in _imagesList){
final appDir = await getApplicationDocumentsDirectory();
final fileName = basename(img.path);
final savedImage = await File(img.path).copy('${appDir.path}/$fileName');
}
}
试试这个 - 希望它能帮到你。觉得有帮助就点对吧。
List<XFile> _imagesList=[];
void selectCamera(ImageSource imagesource,BuildContext cntxt) async {
List<XFile> cameraImages = await _picker.pickImage(source: imagesource);
if(cameraImages!=null){
_imagesList.addAll(cameraImages);
}
for(var img in _imagesList){
final appDir = await getApplicationDocumentsDirectory();
final fileName = basename(img.path);
final savedImage = await File(img.path).copy('${appDir.path}/$fileName');
}
}
我想将相机拍摄的图像保存到列表以在 GridView 中显示多个图像。但我不知道该怎么做 it.I 想将 XFile 列表添加到变量 _imagesList
List<XFile> _imagesList=[];
void selectCamera(ImageSource imagesource,BuildContext cntxt) async {
File cameraImages = await _picker.pickImage(source: imagesource); //error
if(cameraImages!=null){
_imagesList.addAll(cameraImages);
}
for(var img in _imagesList){
final appDir = await getApplicationDocumentsDirectory();
final fileName = basename(img.path);
final savedImage = await File(img.path).copy('${appDir.path}/$fileName');
}
}
试试这个 - 希望它能帮到你。觉得有帮助就点对吧。
List<XFile> _imagesList=[];
void selectCamera(ImageSource imagesource,BuildContext cntxt) async {
List<XFile> cameraImages = await _picker.pickImage(source: imagesource);
if(cameraImages!=null){
_imagesList.addAll(cameraImages);
}
for(var img in _imagesList){
final appDir = await getApplicationDocumentsDirectory();
final fileName = basename(img.path);
final savedImage = await File(img.path).copy('${appDir.path}/$fileName');
}
}