fix media not shown if stored and alread in chat

This commit is contained in:
otsmr 2026-05-16 18:42:44 +02:00
parent d0eee1893e
commit 91eedc76b0

View file

@ -36,8 +36,9 @@ class _InChatMediaViewerState extends State<InChatMediaViewer> {
int? galleryItemIndex; int? galleryItemIndex;
StreamSubscription<Message?>? messageStream; StreamSubscription<Message?>? messageStream;
Timer? _timer; Timer? _timer;
late final ValueNotifier<String?> _activeMediaIdNotifier = late final ValueNotifier<String?> _activeMediaIdNotifier = ValueNotifier(
ValueNotifier(widget.message.mediaId); widget.message.mediaId,
);
@override @override
void initState() { void initState() {
@ -46,14 +47,25 @@ class _InChatMediaViewerState extends State<InChatMediaViewer> {
unawaited(initStream()); unawaited(initStream());
} }
@override
void didUpdateWidget(InChatMediaViewer oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.message.mediaStored != oldWidget.message.mediaStored ||
widget.galleryItems != oldWidget.galleryItems) {
if (widget.message.mediaStored) {
unawaited(loadIndexAsync());
}
}
}
Future<void> loadIndexAsync() async { Future<void> loadIndexAsync() async {
if (!widget.message.mediaStored) return; _timer?.cancel();
_timer = Timer.periodic(const Duration(milliseconds: 10), (timer) { _timer = Timer.periodic(const Duration(milliseconds: 10), (timer) {
/// when the galleryItems are updated this widget is not reloaded /// when the galleryItems are updated this widget is not reloaded
/// so using this timer as a workaround /// so using this timer as a workaround
if (loadIndex()) { if (loadIndex()) {
timer.cancel(); timer.cancel();
setState(() {}); if (mounted) setState(() {});
} }
}); });
} }