mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-12-25 06:52:35 +01:00
Merge branch 'soru/fix-audo-cancel' into 'main'
fix: Don't re-render message widgets on insertion of new messages, making e.g.... Closes #190 See merge request ChristianPauly/fluffychat-flutter!261
This commit is contained in:
commit
5c375d0c15
@ -601,19 +601,26 @@ class _ChatState extends State<_Chat> {
|
|||||||
|
|
||||||
final filteredEvents = getFilteredEvents();
|
final filteredEvents = getFilteredEvents();
|
||||||
|
|
||||||
return ListView.builder(
|
// create a map of eventId --> index to greatly improve performance of
|
||||||
padding: EdgeInsets.symmetric(
|
// ListView's findChildIndexCallback
|
||||||
horizontal: max(
|
final thisEventsKeyMap = <String, int>{};
|
||||||
0,
|
for (var i = 0; i < filteredEvents.length; i++) {
|
||||||
(MediaQuery.of(context).size.width -
|
thisEventsKeyMap[filteredEvents[i].eventId] = i;
|
||||||
AdaptivePageLayout.defaultMinWidth *
|
}
|
||||||
3.5) /
|
|
||||||
2),
|
return ListView.custom(
|
||||||
),
|
padding: EdgeInsets.symmetric(
|
||||||
reverse: true,
|
horizontal: max(
|
||||||
itemCount: filteredEvents.length + 2,
|
0,
|
||||||
controller: _scrollController,
|
(MediaQuery.of(context).size.width -
|
||||||
itemBuilder: (BuildContext context, int i) {
|
AdaptivePageLayout.defaultMinWidth *
|
||||||
|
3.5) /
|
||||||
|
2),
|
||||||
|
),
|
||||||
|
reverse: true,
|
||||||
|
controller: _scrollController,
|
||||||
|
childrenDelegate: SliverChildBuilderDelegate(
|
||||||
|
(BuildContext context, int i) {
|
||||||
return i == filteredEvents.length + 1
|
return i == filteredEvents.length + 1
|
||||||
? _loadingHistory
|
? _loadingHistory
|
||||||
? Container(
|
? Container(
|
||||||
@ -675,7 +682,8 @@ class _ChatState extends State<_Chat> {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
: AutoScrollTag(
|
: AutoScrollTag(
|
||||||
key: ValueKey(i - 1),
|
key: ValueKey(
|
||||||
|
filteredEvents[i - 1].eventId),
|
||||||
index: i - 1,
|
index: i - 1,
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
child: Swipeable(
|
child: Swipeable(
|
||||||
@ -738,7 +746,27 @@ class _ChatState extends State<_Chat> {
|
|||||||
: null),
|
: null),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
},
|
||||||
|
childCount: filteredEvents.length + 2,
|
||||||
|
findChildIndexCallback: (Key key) {
|
||||||
|
// this method is called very often. As such, it has to be optimized for speed.
|
||||||
|
if (!(key is ValueKey)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final eventId = (key as ValueKey).value;
|
||||||
|
if (!(eventId is String)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// first fetch the last index the event was at
|
||||||
|
final index = thisEventsKeyMap[eventId];
|
||||||
|
if (index == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// we need to +1 as 0 is the typing thing at the bottom
|
||||||
|
return index + 1;
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
Reference in New Issue
Block a user