Files
stream-chat-flutter/packages/stream_chat_flutter/lib/src/unread_indicator.dart
T
a42b3de6f4 test: add tests for stream chat flutter (#335)
* feat: Added tests

* feat: Added header test

* feat: Added new tests

* fix

* feat: Added test, fmt

* feat: Added delete test

* added system and unread ind tests

* fix: analysis

* added new tests

* fix: analysis

* added tests

* add attachment actions modal tests

* fix analysis

* fix analysis

* add backbutton tests

* fix analysis

* increase timeout

* add channelheader tests

* add infotile tests

* add reactions modal and channel unread indicator tests

* add golden test for reaction bubble

* add dark tests

* add system message golden

* add deletd message golden

* add message action modal tests

* update goldens

* update workflow runner

* update goldens

* remove channel unread indicator in favor of unread indicator

* move file and media screen to sample app

* add channel image tesst

* add channel_list_header test

* add thread_header test

* bump up test threashold

* fix review

Co-authored-by: Salvatore Giordano <[email protected]>
2021-04-08 17:43:08 +02:00

57 lines
1.7 KiB
Dart

import 'package:flutter/material.dart';
import 'package:stream_chat_flutter/src/stream_chat_theme.dart';
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
class UnreadIndicator extends StatelessWidget {
const UnreadIndicator({
Key key,
this.cid,
}) : super(key: key);
/// Channel cid used to retrieve unread count
final String cid;
@override
Widget build(BuildContext context) {
final client = StreamChat.of(context).client;
return IgnorePointer(
child: StreamBuilder<int>(
stream: cid != null
? client.state.channels[cid].state.unreadCountStream
: client.state.totalUnreadCountStream,
initialData: cid != null
? client.state.channels[cid].state.unreadCount
: client.state.totalUnreadCount,
builder: (context, snapshot) {
if (!snapshot.hasData || snapshot.data == 0) {
return SizedBox();
}
return Material(
borderRadius: BorderRadius.circular(8),
color: StreamChatTheme.of(context)
.channelPreviewTheme
.unreadCounterColor,
child: Padding(
padding: const EdgeInsets.only(
left: 5.0,
right: 5.0,
top: 2,
bottom: 1,
),
child: Center(
child: Text(
'${snapshot.data > 99 ? '99+' : snapshot.data}',
style: TextStyle(
fontSize: 11,
color: Colors.white,
),
),
),
),
);
},
),
);
}
}