Skip to content

Commit

Permalink
Update timeline_event_view_url_previews.dart
Browse files Browse the repository at this point in the history
  • Loading branch information
Airyzz committed Jun 6, 2024
1 parent 45bfd58 commit aa56fa9
Showing 1 changed file with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@ class _TimelineEventViewUrlPreviewsState
extends State<TimelineEventViewUrlPreviews>
implements TimelineEventViewWidget {
UrlPreviewData? data;
bool loading = false;

GlobalKey key = GlobalKey();

@override
Widget build(BuildContext context) {
BenchmarkValues.numTimelineUrlPreviewBuilt += 1;
return Padding(
padding: const EdgeInsets.fromLTRB(0, 2, 40, 2),
child: UrlPreviewWidget(
key: key,
data,
onTap: () {
LinkUtils.open(data!.uri);
},
),
child: (loading || data != null)
? UrlPreviewWidget(
key: key,
data,
onTap: () {
LinkUtils.open(data!.uri);
},
)
: Container(),
);
}

Expand All @@ -65,6 +69,9 @@ class _TimelineEventViewUrlPreviewsState
});

if (cachedData == null) {
setState(() {
loading = true;
});
widget.component.getPreview(widget.timeline.room, event).then(
(value) async {
if (mounted) {
Expand All @@ -76,6 +83,7 @@ class _TimelineEventViewUrlPreviewsState
}

setState(() {
loading = false;
data = value;
key = GlobalKey();
});
Expand Down

0 comments on commit aa56fa9

Please sign in to comment.