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