![](/img/trans.png)
[英]Error in background image from asset in SliverAppBar in flutter
[英]Is there a way in flutter to make an Asset from an Image I got from imagePicker?
我想用 buildGriedView plot 多個資產。 我已經擁有 plot 的一些資產。 但我想在這個資產列表中添加一些我使用 imagePicker 獲得的圖像。 我想問一下是否可以制作這些圖像(來自 imagePicker)資產,這樣我也可以將它們添加到列表中,並使用 buildGridView 將它們添加到 plot 中。
以下是Flutter 文檔中關於資產的內容:
Flutter 應用程序可以包含代碼和資產(有時稱為資源)。 資產是與您的應用程序捆綁和部署的文件,可在運行時訪問。 [...]
所以不,一旦您的應用程序被編譯,您將無法添加任何資產。 如果要使用圖像選擇器中的圖像,則需要使用解決方法,例如讀取文件的字節(您可以使用小部件Image.memory
)。 package image_picker(我想是您正在使用的那個)為檢索到的文件提供了一種方法readAsBytes()
。
final myImage = await pickImage(source: ImageSource.gallery);
if (myImage != null) {
final myImageBytes = await myImage.readAsBytes();
return Image.memory(myImageBytes);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.