File 文件已更改的颤振重建小部件是否可能?
我有一个小的缩略图小部件,可以获取文件并显示它:File 文件已更改的颤振重建小部件是否可能?,file,flutter,setstate,File,Flutter,Setstate,我有一个小的缩略图小部件,可以获取文件并显示它: class ThumbnailViewer extends StatelessWidget { ThumbnailViewer({this.key, this.image}) : super(key: key); Key key; File image; @override Widget build(BuildContext context) { return getThumbnail(); }
class ThumbnailViewer extends StatelessWidget {
ThumbnailViewer({this.key, this.image}) : super(key: key);
Key key;
File image;
@override
Widget build(BuildContext context) {
return getThumbnail();
}
Widget getThumbnail() {
return ClipRRect(
borderRadius: BorderRadius.circular(10),
child: Center(
child: Image.file(
image,
fit: BoxFit.fitWidth,
width: double.infinity,
filterQuality: FilterQuality.none,
),
),
);
}
}
此小部件首先创建如下:
return ThumbnailViewer(image: File(FileHelper.getPhotoPath(shroom.photo, shroom.id)));
然后更改该路径引用的文件并调用setState。但是,不会显示新图像
重建时颤振不会注意到文件更改吗?有没有办法监听文件更改?
谢谢你把setState称为哪里?我这样做的实际场景更复杂。在showModalBottomSheet生成器中,我推到一个更改图像的新屏幕,一旦该屏幕弹出,我就这样调用我的“modalSetState”:showModalBottomSheet(生成器:(BuildContext上下文){return StatefulBuilder(生成器:(context,modalSetState){.then({modalSetState((){});})“ThumbnailViewer”在何处实现?缩略图小部件在模式中的statefulBuilder内部使用