mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-05-25 06:42:12 +00:00
fix media not shown if stored and alread in chat
This commit is contained in:
parent
d0eee1893e
commit
91eedc76b0
1 changed files with 16 additions and 4 deletions
|
|
@ -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(() {});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue