【发布时间】:2020-11-16 09:48:55
【问题描述】:
您好,下面的颤动代码从相机胶卷中加载照片,然后在视频上显示它,我要做的是恢复文件的路径,为此我在 @ 中使用下面的代码987654322@ 函数但是当我运行代码时出现以下错误:
尝试将名称更正为现有 getter 的名称,或定义 一个名为“路径”的 getter 或字段。 print("\n 想象一下: "+imageFile.path);
颤振代码:
Future<File> imageFile;
//Costruttore
ArticoloEditPage(){
aggiornaValori();
BackButtonInterceptor.add(myInterceptor);
setData(new DateTime.now());
}
//Disabilito il bottone di back su android
bool myInterceptor(bool stopDefaultButtonEvent, RouteInfo info) {
return true;
}
//Funzione di init
void init() {
aggiornaValori();
BackButtonInterceptor.add(myInterceptor);
}
//Funzione che esegue la creazione dell'utente
Future<bool> inserimento(BuildContext context) async {
print("\n Immagine: "+imageFile.path);
// var base64File=await Supporto.castDocumentToBase64(imgPath);
//print("\n Immagine in base64: "+imgPath);
}
pickImageFromGallery(ImageSource source) {
setState(() {
imageFile = ImagePicker.pickImage(source: source);
});
}
Widget showImage() {
return FutureBuilder<File>(
future: imageFile,
builder: (BuildContext context, AsyncSnapshot<File> snapshot) {
if (snapshot.connectionState == ConnectionState.done &&
snapshot.data != null) {
return Image.file(
snapshot.data,
width: 300,
height: 300,
);
} else if (snapshot.error != null) {
return const Text(
'Errore caricamento non riuscito',
textAlign: TextAlign.center,
);
} else {
return const Text(
'Nessuna immagine selezionata',
textAlign: TextAlign.center,
);
}
},
);
}
【问题讨论】:
-
您的变量
imageFile是Future<File>,而不是File,因此它没有路径。转到程序中将Future解析为实际File的位置,然后对文件执行任何您想做的操作。 -
这能回答你的问题吗? What is a Future and how do I use it?
-
@nvoigt 好的,但是如何实现图像的加载路径?