@@ -24,22 +24,22 @@ class ChatRoomMasterTileSubTitle extends StatelessWidget with WatchItMixin {
2424 initialValue: room.lastEvent,
2525 ).data;
2626
27- return typingUsers.isEmpty
28- ? _LastEvent (
29- key: ObjectKey ( lastEvent),
30- lastEvent: lastEvent ?? room.lastEvent,
31- fallbackText :
32- room.membership == Membership .invite ? room.name : null ,
33- )
34- : Text (
35- typingUsers.length > 1
36- ? context.l10n. numUsersTyping ( typingUsers.length)
37- : context.l10n
38- .userIsTyping (typingUsers.first.displayName ?? '' ),
39- style: context.textTheme.bodyMedium
40- ? .copyWith (color: context.colorScheme.primary),
41- maxLines: 1 ,
42- );
27+ if ( typingUsers.isEmpty) {
28+ return _LastEvent (
29+ key: ValueKey ( '${ lastEvent ?. eventId }lastevent' ),
30+ lastEvent: room.lastEvent,
31+ fallbackText : room.membership == Membership .invite ? room.name : null ,
32+ );
33+ }
34+
35+ return Text (
36+ typingUsers.length > 1
37+ ? context.l10n. numUsersTyping (typingUsers.length)
38+ : context.l10n .userIsTyping (typingUsers.first.displayName ?? '' ),
39+ style: context.textTheme.bodyMedium
40+ ? .copyWith (color: context.colorScheme.primary),
41+ maxLines: 1 ,
42+ );
4343 }
4444}
4545
@@ -60,21 +60,42 @@ class _LastEvent extends StatefulWidget with WatchItStatefulWidgetMixin {
6060class _LastEventState extends State <_LastEvent > {
6161 late final Future <String > _future;
6262
63+ static final Map <String , String > _cache = {};
64+
6365 @override
6466 void initState () {
6567 super .initState ();
66- _future = widget.lastEvent
67- ? .calcLocalizedBody (const MatrixDefaultLocalizations ()) ??
68- Future .value (widget.lastEvent? .body ?? '' );
68+ _future = widget.lastEvent != null &&
69+ _cache.containsKey (widget.lastEvent! .eventId)
70+ ? Future .value (_cache[widget.lastEvent! .eventId]! )
71+ : widget.lastEvent
72+ ? .calcLocalizedBody (const MatrixDefaultLocalizations ()) ??
73+ Future .value (widget.lastEvent? .body ?? '' );
6974 }
7075
7176 @override
7277 Widget build (BuildContext context) {
78+ if (widget.lastEvent != null &&
79+ _cache.containsKey (widget.lastEvent! .eventId)) {
80+ return Text (
81+ _cache[widget.lastEvent! .eventId]! ,
82+ maxLines: 1 ,
83+ );
84+ }
85+
7386 return FutureBuilder (
7487 future: _future,
7588 builder: (context, snapshot) {
89+ if (snapshot.hasData && widget.lastEvent != null ) {
90+ _cache[widget.lastEvent! .eventId] = snapshot.data! ;
91+ return Text (
92+ snapshot.data! ,
93+ maxLines: 1 ,
94+ );
95+ }
96+
7697 return Text (
77- snapshot.hasData ? snapshot.data ! : ( widget.fallbackText ?? ' ' ) ,
98+ widget.fallbackText ?? ' ' ,
7899 maxLines: 1 ,
79100 );
80101 },
0 commit comments