fix thread unread indicator
This commit is contained in:
@@ -9,11 +9,15 @@ class StreamBackButton extends StatelessWidget {
|
|||||||
Key key,
|
Key key,
|
||||||
this.onPressed,
|
this.onPressed,
|
||||||
this.showUnreads = false,
|
this.showUnreads = false,
|
||||||
|
this.cid,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final VoidCallback onPressed;
|
final VoidCallback onPressed;
|
||||||
final bool showUnreads;
|
final bool showUnreads;
|
||||||
|
|
||||||
|
/// Channel cid used to retrieve unread count
|
||||||
|
final String cid;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Stack(
|
return Stack(
|
||||||
@@ -45,7 +49,9 @@ class StreamBackButton extends StatelessWidget {
|
|||||||
Positioned(
|
Positioned(
|
||||||
top: 7,
|
top: 7,
|
||||||
right: 7,
|
right: 7,
|
||||||
child: UnreadIndicator(),
|
child: UnreadIndicator(
|
||||||
|
cid: cid,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -187,7 +187,6 @@ class MessageListView extends StatefulWidget {
|
|||||||
|
|
||||||
class _MessageListViewState extends State<MessageListView> {
|
class _MessageListViewState extends State<MessageListView> {
|
||||||
ItemScrollController _scrollController;
|
ItemScrollController _scrollController;
|
||||||
bool _bottomWasVisible = false;
|
|
||||||
Function _onThreadTap;
|
Function _onThreadTap;
|
||||||
bool _showScrollToBottom = false;
|
bool _showScrollToBottom = false;
|
||||||
ItemPositionsListener _itemPositionListener;
|
ItemPositionsListener _itemPositionListener;
|
||||||
@@ -692,14 +691,13 @@ class _MessageListViewState extends State<MessageListView> {
|
|||||||
key: ValueKey<String>('BOTTOM-MESSAGE'),
|
key: ValueKey<String>('BOTTOM-MESSAGE'),
|
||||||
onVisibilityChanged: (visibility) {
|
onVisibilityChanged: (visibility) {
|
||||||
final isVisible = visibility.visibleBounds != Rect.zero;
|
final isVisible = visibility.visibleBounds != Rect.zero;
|
||||||
if (isVisible && !_bottomWasVisible) {
|
if (isVisible) {
|
||||||
final channel = streamChannel.channel;
|
final channel = streamChannel.channel;
|
||||||
if (_upToDate &&
|
if (_upToDate &&
|
||||||
channel.config?.readEvents == true &&
|
channel.config?.readEvents == true &&
|
||||||
channel.state.unreadCount > 0) {
|
channel.state.unreadCount > 0) {
|
||||||
streamChannel.channel.markRead();
|
streamChannel.channel.markRead();
|
||||||
}
|
}
|
||||||
_bottomWasVisible = !isVisible;
|
|
||||||
}
|
}
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
setState(() => _showScrollToBottom = !isVisible);
|
setState(() => _showScrollToBottom = !isVisible);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:stream_chat/stream_chat.dart';
|
import 'package:stream_chat/stream_chat.dart';
|
||||||
import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
|
import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
|
||||||
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
|
|
||||||
import 'back_button.dart';
|
import 'back_button.dart';
|
||||||
import 'channel_name.dart';
|
import 'channel_name.dart';
|
||||||
@@ -81,6 +82,7 @@ class ThreadHeader extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
elevation: 1,
|
elevation: 1,
|
||||||
leading: showBackButton
|
leading: showBackButton
|
||||||
? StreamBackButton(
|
? StreamBackButton(
|
||||||
|
cid: StreamChannel.of(context).channel.cid,
|
||||||
onPressed: onBackPressed,
|
onPressed: onBackPressed,
|
||||||
showUnreads: true,
|
showUnreads: true,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,14 +5,22 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
|||||||
class UnreadIndicator extends StatelessWidget {
|
class UnreadIndicator extends StatelessWidget {
|
||||||
const UnreadIndicator({
|
const UnreadIndicator({
|
||||||
Key key,
|
Key key,
|
||||||
|
this.cid,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
/// Channel cid used to retrieve unread count
|
||||||
|
final String cid;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final client = StreamChat.of(context).client;
|
final client = StreamChat.of(context).client;
|
||||||
return StreamBuilder<int>(
|
return StreamBuilder<int>(
|
||||||
stream: client.state.totalUnreadCountStream,
|
stream: cid != null
|
||||||
initialData: client.state.totalUnreadCount,
|
? client.state.channels[cid].state.unreadCountStream
|
||||||
|
: client.state.totalUnreadCountStream,
|
||||||
|
initialData: cid != null
|
||||||
|
? client.state.channels[cid].state.unreadCount
|
||||||
|
: client.state.totalUnreadCount,
|
||||||
builder: (context, snapshot) {
|
builder: (context, snapshot) {
|
||||||
if (!snapshot.hasData || snapshot.data == 0) {
|
if (!snapshot.hasData || snapshot.data == 0) {
|
||||||
return SizedBox();
|
return SizedBox();
|
||||||
|
|||||||
Reference in New Issue
Block a user