0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Widget更新時にImageが更新されない場合の対処

Last updated at Posted at 2023-09-18

下記の様に実装していた。setStateでWidgetの更新自体は発火していたが、画像が差し替えされなかった

child: Image.file(
  imagePath,
),

Image.fileの代わりにImage.memoryを使えばいいらしい

child: Image.memory(
  File(imagePath).readAsBytesSync(),
)

参考元
Flutter Image Widget won't update on change state
https://stackoverflow.com/questions/58794144/flutter-image-widget-wont-update-on-change-state

Image.file()の説明にも下記の様に書いてあるので、この辺りが起因している?

Loading an image from a file creates an in memory copy of the file, which is retained in the ImageCache.
ファイルから画像をロードすると、ファイルのメモリ内コピーが作成され、ImageCache に保持されます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?