refactor(ui): Replace channel.extraDataStream with channel.nameStream, channel.imageStream in ChannelName and ChannelAvatar widget respectively.
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -90,12 +90,11 @@ class ChannelAvatar extends StatelessWidget {
|
||||
final colorTheme = chatThemeData.colorTheme;
|
||||
final previewTheme = chatThemeData.channelPreviewTheme.avatarTheme;
|
||||
|
||||
return BetterStreamBuilder<Map<String, dynamic>>(
|
||||
stream: channel.extraDataStream,
|
||||
initialData: channel.extraData,
|
||||
builder: (context, extraData) {
|
||||
final channelImage = extraData['image'];
|
||||
|
||||
return StreamBuilder<String?>(
|
||||
stream: channel.imageStream,
|
||||
initialData: channel.image,
|
||||
builder: (context, snapshot) {
|
||||
final channelImage = snapshot.data;
|
||||
if (channelImage != null) {
|
||||
Widget child = ClipRRect(
|
||||
borderRadius: borderRadius ?? previewTheme?.borderRadius,
|
||||
@@ -108,7 +107,7 @@ class ChannelAvatar extends StatelessWidget {
|
||||
imageUrl: channelImage,
|
||||
errorWidget: (_, __, ___) => Center(
|
||||
child: Text(
|
||||
extraData['name']?[0] ?? '',
|
||||
channel.name?[0] ?? '',
|
||||
style: TextStyle(
|
||||
color: colorTheme.barsBg,
|
||||
fontWeight: FontWeight.bold,
|
||||
|
||||
@@ -27,40 +27,40 @@ class ChannelName extends StatelessWidget {
|
||||
final client = StreamChat.of(context);
|
||||
final channel = StreamChannel.of(context).channel;
|
||||
|
||||
return BetterStreamBuilder<Map<String, Object?>>(
|
||||
stream: channel.extraDataStream,
|
||||
initialData: channel.extraData,
|
||||
builder: (context, data) => _buildName(
|
||||
data,
|
||||
channel.state?.members,
|
||||
assert(channel.state != null, 'Channel ${channel.id} is not initialized');
|
||||
|
||||
return StreamBuilder<String?>(
|
||||
stream: channel.nameStream,
|
||||
initialData: channel.name,
|
||||
builder: (context, snapshot) => _buildName(
|
||||
snapshot.data,
|
||||
channel.state!.members,
|
||||
client,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildName(
|
||||
Map<String, dynamic> extraData,
|
||||
List<Member>? members,
|
||||
String? name,
|
||||
List<Member> members,
|
||||
StreamChatState client,
|
||||
) =>
|
||||
LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
var title = context.translations.noTitleText;
|
||||
if (extraData['name'] != null) {
|
||||
title = extraData['name'];
|
||||
} else {
|
||||
var title = name;
|
||||
if (title == null && members.isNotEmpty) {
|
||||
final otherMembers = members
|
||||
?.where((member) => member.userId != client.currentUser!.id);
|
||||
if (otherMembers?.length == 1) {
|
||||
if (otherMembers!.first.user != null) {
|
||||
.where((member) => member.userId != client.currentUser!.id);
|
||||
if (otherMembers.length == 1) {
|
||||
if (otherMembers.first.user != null) {
|
||||
title = otherMembers.first.user!.name;
|
||||
}
|
||||
} else if (otherMembers?.isNotEmpty == true) {
|
||||
} else if (otherMembers.isNotEmpty == true) {
|
||||
final maxWidth = constraints.maxWidth;
|
||||
final maxChars = maxWidth / (textStyle?.fontSize ?? 1);
|
||||
var currentChars = 0;
|
||||
final currentMembers = <Member>[];
|
||||
otherMembers!.forEach((element) {
|
||||
otherMembers.forEach((element) {
|
||||
final newLength =
|
||||
currentChars + (element.user?.name.length ?? 0);
|
||||
if (newLength < maxChars) {
|
||||
@@ -77,7 +77,7 @@ class ChannelName extends StatelessWidget {
|
||||
}
|
||||
|
||||
return Text(
|
||||
title,
|
||||
title ?? context.translations.noTitleText,
|
||||
style: textStyle,
|
||||
overflow: textOverflow,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user