Adding support for one-on-one conversation to channel preview
This commit is contained in:
@@ -57,11 +57,20 @@ class ChannelImage extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final client = StreamChat.of(context);
|
||||
final channel = this.channel ?? StreamChannel.of(context).channel;
|
||||
return StreamBuilder<Map<String, dynamic>>(
|
||||
stream: channel.extraDataStream,
|
||||
initialData: channel.extraData,
|
||||
builder: (context, snapshot) {
|
||||
var image = '';
|
||||
if (snapshot.data?.containsKey('image') ?? false) {
|
||||
image = snapshot.data['image'];
|
||||
} else if (channel.state.members.length == 2) {
|
||||
final otherMemberIndex = channel.state.members[0].user.id == client.user.id ? 1 : 0;
|
||||
image = channel.state.members[otherMemberIndex].user.image;
|
||||
}
|
||||
|
||||
return ClipRRect(
|
||||
borderRadius: StreamChatTheme.of(context)
|
||||
.channelPreviewTheme
|
||||
@@ -75,9 +84,9 @@ class ChannelImage extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
color: StreamChatTheme.of(context).accentColor,
|
||||
),
|
||||
child: snapshot.data?.containsKey('image') ?? false
|
||||
child: image != ''
|
||||
? CachedNetworkImage(
|
||||
imageUrl: snapshot.data['image'],
|
||||
imageUrl: image,
|
||||
errorWidget: (_, __, ___) {
|
||||
return Center(
|
||||
child: Text(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
|
||||
import '../stream_chat_flutter.dart';
|
||||
import 'stream_channel.dart';
|
||||
|
||||
/// It shows the current [Channel] name using a [Text] widget.
|
||||
@@ -21,15 +22,21 @@ class ChannelName extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final client = StreamChat.of(context);
|
||||
final channel = this.channel ?? StreamChannel.of(context).channel;
|
||||
return StreamBuilder<Map<String, dynamic>>(
|
||||
stream: channel.extraDataStream,
|
||||
initialData: channel.extraData,
|
||||
builder: (context, snapshot) {
|
||||
return Text(
|
||||
snapshot.data != null
|
||||
? (snapshot.data['name'] ?? channel.cid)
|
||||
: channel.cid,
|
||||
var title;
|
||||
if (snapshot.data['name'] == null && channel.state.members.length == 2) {
|
||||
final otherMemberIndex = channel.state.members[0].user.id == client.user.id ? 1 : 0;
|
||||
title = channel.state.members[otherMemberIndex].user.name;
|
||||
} else {
|
||||
title = snapshot.data['name'] ?? channel.id;
|
||||
}
|
||||
|
||||
return Text(title,
|
||||
style: textStyle,
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user