Merge branches 'develop' and 'feat/pinned' of https://github.com/GetStream/stream-chat-flutter into feat/pinned

This commit is contained in:
Deven Joshi
2021-05-31 15:44:24 +05:30
11 changed files with 290 additions and 33 deletions
@@ -574,9 +574,9 @@ class _MessageListViewState extends State<MessageListView> {
return const SizedBox();
}
var index = _getTopElement(values).index;
var index = _getTopElement(values)?.index;
if (index > messages.length) {
if (index == null || index > messages.length) {
return const SizedBox();
}
@@ -602,10 +602,17 @@ class _MessageListViewState extends State<MessageListView> {
StreamChannelState? channel, QueryDirection direction) =>
_messageListController.paginateData!(direction: direction);
ItemPosition _getTopElement(Iterable<ItemPosition> values) => values
.where((ItemPosition position) => position.itemLeadingEdge < 0.9)
.reduce((ItemPosition max, ItemPosition position) =>
position.itemLeadingEdge > max.itemLeadingEdge ? position : max);
ItemPosition? _getTopElement(Iterable<ItemPosition> values) {
final inView =
values.where((ItemPosition position) => position.itemLeadingEdge < 0.9);
if (inView.isEmpty) {
return null;
}
return inView.reduce((ItemPosition max, ItemPosition position) =>
position.itemLeadingEdge > max.itemLeadingEdge ? position : max);
}
Widget _buildScrollToBottom() => StreamBuilder<Tuple2<bool, int>>(
stream: Rx.combineLatest2(
@@ -39,6 +39,7 @@ class StreamChat extends StatefulWidget {
this.streamChatThemeData,
this.onBackgroundEventReceived,
this.backgroundKeepAlive = const Duration(minutes: 1),
this.connectivityStream,
}) : super(key: key);
/// Client to do chat ops with
@@ -59,6 +60,11 @@ class StreamChat extends StatefulWidget {
/// upon the [Event.type]
final EventHandler? onBackgroundEventReceived;
/// Stream of connectivity result
/// Visible for testing
@visibleForTesting
final Stream<ConnectivityResult>? connectivityStream;
@override
StreamChatState createState() => StreamChatState();
@@ -102,6 +108,7 @@ class StreamChatState extends State<StreamChat> {
client: client,
onBackgroundEventReceived: widget.onBackgroundEventReceived,
backgroundKeepAlive: widget.backgroundKeepAlive,
connectivityStream: widget.connectivityStream,
child: widget.child ?? const Offstage(),
),
);