Use localChannel if present instead of creating a new
Signed-off-by: Sahil Kumar <[email protected]>
This commit is contained in:
@@ -335,10 +335,11 @@ class _ChannelListPageState extends State<ChannelListPage> {
|
|||||||
onItemTap: (messageResponse) async {
|
onItemTap: (messageResponse) async {
|
||||||
final client = StreamChat.of(context).client;
|
final client = StreamChat.of(context).client;
|
||||||
final message = messageResponse.message;
|
final message = messageResponse.message;
|
||||||
final channel = Channel.fromState(
|
final channel = client.channel(
|
||||||
client,
|
messageResponse.channel.type,
|
||||||
ChannelState(channel: messageResponse.channel),
|
id: messageResponse.channel.id,
|
||||||
);
|
);
|
||||||
|
await channel.watch();
|
||||||
Navigator.pushNamed(
|
Navigator.pushNamed(
|
||||||
context,
|
context,
|
||||||
Routes.CHANNEL_PAGE,
|
Routes.CHANNEL_PAGE,
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
final messageIndex = messages.indexWhere((e) {
|
final messageIndex = messages.indexWhere((e) {
|
||||||
return e.id == streamChannel.initialMessageId;
|
return e.id == streamChannel.initialMessageId;
|
||||||
});
|
});
|
||||||
return totalMessages - messageIndex - 1;
|
return totalMessages - messageIndex;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -234,7 +234,14 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
initialAlignment = _initialAlignment;
|
initialAlignment = _initialAlignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
return StreamBuilder<List<Message>>(
|
return WillPopScope(
|
||||||
|
onWillPop: () async {
|
||||||
|
if (!_upToDate) {
|
||||||
|
await streamChannel.reloadChannel();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
child: StreamBuilder<List<Message>>(
|
||||||
stream: messagesStream?.map((messages) => messages
|
stream: messagesStream?.map((messages) => messages
|
||||||
?.where((e) =>
|
?.where((e) =>
|
||||||
!e.isDeleted ||
|
!e.isDeleted ||
|
||||||
@@ -269,7 +276,8 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
final newMessagesListLength = messages.length;
|
final newMessagesListLength = messages.length;
|
||||||
|
|
||||||
if (_bottomPaginationActive) {
|
if (_bottomPaginationActive) {
|
||||||
if (_itemPositionListener.itemPositions.value?.isNotEmpty == true &&
|
if (_itemPositionListener.itemPositions.value?.isNotEmpty ==
|
||||||
|
true &&
|
||||||
_messageListLength != null) {
|
_messageListLength != null) {
|
||||||
final first = _itemPositionListener.itemPositions.value.first;
|
final first = _itemPositionListener.itemPositions.value.first;
|
||||||
final diff = newMessagesListLength - _messageListLength;
|
final diff = newMessagesListLength - _messageListLength;
|
||||||
@@ -294,7 +302,8 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
if (!_upToDate) {
|
if (!_upToDate) {
|
||||||
_topPaginationActive = false;
|
_topPaginationActive = false;
|
||||||
_bottomPaginationActive = true;
|
_bottomPaginationActive = true;
|
||||||
return _paginateData(streamChannel, QueryDirection.bottom);
|
return _paginateData(
|
||||||
|
streamChannel, QueryDirection.bottom);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onEndOfPage: () async {
|
onEndOfPage: () async {
|
||||||
@@ -335,8 +344,9 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
'Start of thread',
|
'Start of thread',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
color:
|
color: Theme.of(context)
|
||||||
Theme.of(context).accentColor.withAlpha(50),
|
.accentColor
|
||||||
|
.withAlpha(50),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -401,7 +411,8 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
messageWidget,
|
messageWidget,
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 12.0),
|
padding:
|
||||||
|
const EdgeInsets.symmetric(vertical: 12.0),
|
||||||
child: widget.dateDividerBuilder != null
|
child: widget.dateDividerBuilder != null
|
||||||
? widget.dateDividerBuilder(
|
? widget.dateDividerBuilder(
|
||||||
nextMessage.createdAt.toLocal())
|
nextMessage.createdAt.toLocal())
|
||||||
@@ -450,7 +461,8 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
});
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _paginateData(
|
Future<void> _paginateData(
|
||||||
|
|||||||
@@ -307,16 +307,29 @@ class StreamChannelState extends State<StreamChannel> {
|
|||||||
if (initialMessageId != null) false,
|
if (initialMessageId != null) false,
|
||||||
],
|
],
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
|
if (snapshot.hasError) {
|
||||||
|
if (snapshot.error is Error) {
|
||||||
|
print((snapshot.error as Error).stackTrace);
|
||||||
|
}
|
||||||
|
var message = snapshot.error.toString();
|
||||||
|
if (snapshot.error is DioError) {
|
||||||
|
final dioError = snapshot.error as DioError;
|
||||||
|
if (dioError.type == DioErrorType.RESPONSE) {
|
||||||
|
message = dioError.message;
|
||||||
|
} else {
|
||||||
|
message = 'Check your connection and retry';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Center(
|
||||||
|
child: Text(message),
|
||||||
|
);
|
||||||
|
}
|
||||||
final initialized = snapshot.data[0];
|
final initialized = snapshot.data[0];
|
||||||
final dataLoaded = initialMessageId == null ? true : snapshot.data[1];
|
final dataLoaded = initialMessageId == null ? true : snapshot.data[1];
|
||||||
if (widget.showLoading && (!initialized || !dataLoaded)) {
|
if (widget.showLoading && (!initialized || !dataLoaded)) {
|
||||||
return Center(
|
return Center(
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
);
|
);
|
||||||
} else if (snapshot.hasError) {
|
|
||||||
return Center(
|
|
||||||
child: Text(snapshot.error),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return widget.child;
|
return widget.child;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user