[UI-KIT] Fix channel_image.dart, remove defaultChannelPreview from theme
Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
@@ -83,121 +83,117 @@ class ChannelImage extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final streamChat = StreamChat.of(context);
|
final streamChat = StreamChat.of(context);
|
||||||
final channel = this.channel ?? StreamChannel.of(context).channel;
|
final channel = this.channel ?? StreamChannel.of(context).channel;
|
||||||
|
|
||||||
|
assert(channel.state != null, 'Channel ${channel.id} is not initialized');
|
||||||
|
|
||||||
|
final chatThemeData = StreamChatTheme.of(context);
|
||||||
|
final colorTheme = chatThemeData.colorTheme;
|
||||||
|
final previewTheme = chatThemeData.channelPreviewTheme.avatarTheme;
|
||||||
|
|
||||||
return BetterStreamBuilder<Map<String, dynamic>>(
|
return BetterStreamBuilder<Map<String, dynamic>>(
|
||||||
stream: channel.extraDataStream,
|
stream: channel.extraDataStream,
|
||||||
initialData: channel.extraData,
|
initialData: channel.extraData,
|
||||||
builder: (context, data) {
|
builder: (context, extraData) {
|
||||||
String? image;
|
final channelImage = extraData['image'];
|
||||||
final chatThemeData = StreamChatTheme.of(context);
|
|
||||||
if (data.containsKey('image') == true) {
|
|
||||||
image = data['image'];
|
|
||||||
} else if (channel.state?.members.length == 2) {
|
|
||||||
final otherMember = channel.state?.members
|
|
||||||
.firstWhere((member) => member.user?.id != streamChat.user?.id);
|
|
||||||
return BetterStreamBuilder<User?>(
|
|
||||||
stream: streamChat.client.state.usersStream
|
|
||||||
.map((users) =>
|
|
||||||
users[otherMember?.userId] ?? otherMember!.user!)
|
|
||||||
.distinct(),
|
|
||||||
initialData: otherMember!.user,
|
|
||||||
builder: (context, user) => UserAvatar(
|
|
||||||
borderRadius: borderRadius ??
|
|
||||||
chatThemeData
|
|
||||||
.channelPreviewTheme.avatarTheme?.borderRadius,
|
|
||||||
user: user ?? otherMember.user!,
|
|
||||||
constraints: constraints ??
|
|
||||||
chatThemeData
|
|
||||||
.channelPreviewTheme.avatarTheme?.constraints,
|
|
||||||
onTap: onTap != null ? (_) => onTap!() : null,
|
|
||||||
selected: selected,
|
|
||||||
selectionColor: selectionColor ??
|
|
||||||
chatThemeData.colorTheme.accentPrimary,
|
|
||||||
selectionThickness: selectionThickness,
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
final images = channel.state?.members
|
|
||||||
.where((member) =>
|
|
||||||
member.user?.id != streamChat.user?.id &&
|
|
||||||
member.user?.extraData['image'] != null)
|
|
||||||
.take(4)
|
|
||||||
// ignore: cast_nullable_to_non_nullable
|
|
||||||
.map((e) => e.user?.extraData['image'] as String)
|
|
||||||
.toList();
|
|
||||||
return GroupImage(
|
|
||||||
images: images ?? [],
|
|
||||||
borderRadius: borderRadius ??
|
|
||||||
chatThemeData.channelPreviewTheme.avatarTheme?.borderRadius,
|
|
||||||
constraints: constraints ??
|
|
||||||
chatThemeData.channelPreviewTheme.avatarTheme?.constraints,
|
|
||||||
onTap: onTap,
|
|
||||||
selected: selected,
|
|
||||||
selectionColor:
|
|
||||||
selectionColor ?? chatThemeData.colorTheme.accentPrimary,
|
|
||||||
selectionThickness: selectionThickness,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget child = ClipRRect(
|
if (channelImage != null) {
|
||||||
borderRadius: borderRadius ??
|
Widget child = ClipRRect(
|
||||||
chatThemeData.channelPreviewTheme.avatarTheme?.borderRadius,
|
borderRadius: borderRadius ?? previewTheme?.borderRadius,
|
||||||
child: Container(
|
child: Container(
|
||||||
constraints: constraints ??
|
constraints: constraints ?? previewTheme?.constraints,
|
||||||
chatThemeData.channelPreviewTheme.avatarTheme?.constraints,
|
decoration: BoxDecoration(color: colorTheme.accentPrimary),
|
||||||
decoration: BoxDecoration(
|
child: InkWell(
|
||||||
color: chatThemeData.colorTheme.accentPrimary,
|
onTap: onTap,
|
||||||
),
|
child: CachedNetworkImage(
|
||||||
child: Stack(
|
imageUrl: channelImage,
|
||||||
alignment: Alignment.center,
|
errorWidget: (_, __, ___) => Center(
|
||||||
fit: StackFit.expand,
|
child: Text(
|
||||||
children: <Widget>[
|
extraData['name']?[0] ?? '',
|
||||||
if (image != null)
|
style: TextStyle(
|
||||||
CachedNetworkImage(
|
color: colorTheme.barsBg,
|
||||||
imageUrl: image,
|
fontWeight: FontWeight.bold,
|
||||||
errorWidget: (_, __, ___) => Center(
|
|
||||||
child: Text(
|
|
||||||
data.containsKey('name') ? data['name'][0] : '',
|
|
||||||
style: TextStyle(
|
|
||||||
color: chatThemeData.colorTheme.barsBg,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
fit: BoxFit.cover,
|
|
||||||
)
|
|
||||||
else
|
|
||||||
chatThemeData.defaultChannelImage(
|
|
||||||
context,
|
|
||||||
channel,
|
|
||||||
),
|
|
||||||
Material(
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: InkWell(
|
|
||||||
onTap: onTap,
|
|
||||||
),
|
),
|
||||||
|
fit: BoxFit.cover,
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (selected) {
|
|
||||||
child = ClipRRect(
|
|
||||||
key: const Key('selectedImage'),
|
|
||||||
borderRadius: (borderRadius ??
|
|
||||||
chatThemeData.ownMessageTheme.avatarTheme?.borderRadius ??
|
|
||||||
BorderRadius.zero) +
|
|
||||||
BorderRadius.circular(selectionThickness),
|
|
||||||
child: Container(
|
|
||||||
constraints: constraints ??
|
|
||||||
chatThemeData.ownMessageTheme.avatarTheme?.constraints,
|
|
||||||
color: selectionColor ?? chatThemeData.colorTheme.accentPrimary,
|
|
||||||
child: Padding(
|
|
||||||
padding: EdgeInsets.all(selectionThickness),
|
|
||||||
child: child,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (selected) {
|
||||||
|
child = ClipRRect(
|
||||||
|
key: const Key('selectedImage'),
|
||||||
|
borderRadius: BorderRadius.circular(selectionThickness) +
|
||||||
|
(borderRadius ??
|
||||||
|
previewTheme?.borderRadius ??
|
||||||
|
BorderRadius.zero),
|
||||||
|
child: Container(
|
||||||
|
constraints: constraints ?? previewTheme?.constraints,
|
||||||
|
color: selectionColor ?? colorTheme.accentPrimary,
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(selectionThickness),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return child;
|
||||||
}
|
}
|
||||||
return child;
|
|
||||||
|
final currentUser = streamChat.user!;
|
||||||
|
final otherMembers = channel.state!.members
|
||||||
|
.where((it) => it.userId != currentUser.id)
|
||||||
|
.toList(growable: false);
|
||||||
|
|
||||||
|
// our own space, no other members
|
||||||
|
if (otherMembers.isEmpty) {
|
||||||
|
return BetterStreamBuilder<User>(
|
||||||
|
stream: streamChat.client.state.userStream.map((it) => it!),
|
||||||
|
initialData: currentUser,
|
||||||
|
builder: (context, user) => UserAvatar(
|
||||||
|
borderRadius: borderRadius ?? previewTheme?.borderRadius,
|
||||||
|
user: user,
|
||||||
|
constraints: constraints ?? previewTheme?.constraints,
|
||||||
|
onTap: onTap != null ? (_) => onTap!() : null,
|
||||||
|
selected: selected,
|
||||||
|
selectionColor: selectionColor ?? colorTheme.accentPrimary,
|
||||||
|
selectionThickness: selectionThickness,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1-1 Conversation
|
||||||
|
if (otherMembers.length == 1) {
|
||||||
|
final member = otherMembers.first;
|
||||||
|
final user = member.user!;
|
||||||
|
return BetterStreamBuilder<User>(
|
||||||
|
stream: streamChat.client.state.usersStream
|
||||||
|
.map((users) => users[member.userId ?? user.id] ?? user)
|
||||||
|
.distinct(),
|
||||||
|
initialData: user,
|
||||||
|
builder: (context, user) => UserAvatar(
|
||||||
|
borderRadius: borderRadius ?? previewTheme?.borderRadius,
|
||||||
|
user: user,
|
||||||
|
constraints: constraints ?? previewTheme?.constraints,
|
||||||
|
onTap: onTap != null ? (_) => onTap!() : null,
|
||||||
|
selected: selected,
|
||||||
|
selectionColor: selectionColor ?? colorTheme.accentPrimary,
|
||||||
|
selectionThickness: selectionThickness,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Group conversation
|
||||||
|
return GroupImage(
|
||||||
|
members: otherMembers,
|
||||||
|
borderRadius: borderRadius ?? previewTheme?.borderRadius,
|
||||||
|
constraints: constraints ?? previewTheme?.constraints,
|
||||||
|
onTap: onTap,
|
||||||
|
selected: selected,
|
||||||
|
selectionColor: selectionColor ?? colorTheme.accentPrimary,
|
||||||
|
selectionThickness: selectionThickness,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import 'package:cached_network_image/cached_network_image.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
import 'package:stream_chat_flutter/stream_chat_flutter.dart';
|
||||||
|
|
||||||
@@ -7,7 +6,7 @@ class GroupImage extends StatelessWidget {
|
|||||||
/// Constructor for creating a [GroupImage]
|
/// Constructor for creating a [GroupImage]
|
||||||
const GroupImage({
|
const GroupImage({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.images,
|
required this.members,
|
||||||
this.constraints,
|
this.constraints,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
this.borderRadius,
|
this.borderRadius,
|
||||||
@@ -17,7 +16,7 @@ class GroupImage extends StatelessWidget {
|
|||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// List of images to display
|
/// List of images to display
|
||||||
final List<String> images;
|
final List<Member> members;
|
||||||
|
|
||||||
/// Constraints on the widget
|
/// Constraints on the widget
|
||||||
final BoxConstraints? constraints;
|
final BoxConstraints? constraints;
|
||||||
@@ -39,20 +38,22 @@ class GroupImage extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Widget? avatar;
|
final streamChat = StreamChat.of(context);
|
||||||
final streamChatTheme = StreamChatTheme.of(context);
|
final channel = StreamChannel.of(context).channel;
|
||||||
|
|
||||||
avatar = GestureDetector(
|
assert(channel.state != null, 'Channel ${channel.id} is not initialized');
|
||||||
|
|
||||||
|
final streamChatTheme = StreamChatTheme.of(context);
|
||||||
|
final colorTheme = streamChatTheme.colorTheme;
|
||||||
|
final previewTheme = streamChatTheme.channelPreviewTheme.avatarTheme;
|
||||||
|
|
||||||
|
Widget avatar = GestureDetector(
|
||||||
onTap: onTap,
|
onTap: onTap,
|
||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: borderRadius ??
|
borderRadius: borderRadius ?? previewTheme?.borderRadius,
|
||||||
streamChatTheme.ownMessageTheme.avatarTheme?.borderRadius,
|
|
||||||
child: Container(
|
child: Container(
|
||||||
constraints: constraints ??
|
constraints: constraints ?? previewTheme?.constraints,
|
||||||
streamChatTheme.ownMessageTheme.avatarTheme?.constraints,
|
decoration: BoxDecoration(color: colorTheme.accentPrimary),
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: streamChatTheme.colorTheme.accentPrimary,
|
|
||||||
),
|
|
||||||
child: Flex(
|
child: Flex(
|
||||||
direction: Axis.vertical,
|
direction: Axis.vertical,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
@@ -62,48 +63,62 @@ class GroupImage extends StatelessWidget {
|
|||||||
child: Flex(
|
child: Flex(
|
||||||
direction: Axis.horizontal,
|
direction: Axis.horizontal,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: images
|
children: members.take(2).map((member) {
|
||||||
.take(2)
|
final user = member.user!;
|
||||||
.map((url) => Flexible(
|
return Flexible(
|
||||||
fit: FlexFit.tight,
|
fit: FlexFit.tight,
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
child: Transform.scale(
|
child: Transform.scale(
|
||||||
scale: 1.2,
|
scale: 1.2,
|
||||||
child: CachedNetworkImage(
|
child: BetterStreamBuilder<User>(
|
||||||
imageUrl: url,
|
stream: streamChat.client.state.usersStream
|
||||||
fit: BoxFit.cover,
|
.map((users) =>
|
||||||
),
|
users[member.userId ?? user.id] ?? user)
|
||||||
),
|
.distinct(),
|
||||||
|
initialData: user,
|
||||||
|
builder: (context, user) => UserAvatar(
|
||||||
|
user: user,
|
||||||
|
borderRadius: BorderRadius.zero,
|
||||||
),
|
),
|
||||||
))
|
),
|
||||||
.toList(),
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (images.length > 2)
|
if (members.length > 2)
|
||||||
Flexible(
|
Flexible(
|
||||||
fit: FlexFit.tight,
|
fit: FlexFit.tight,
|
||||||
child: Flex(
|
child: Flex(
|
||||||
direction: Axis.horizontal,
|
direction: Axis.horizontal,
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: images
|
children: members.skip(2).take(2).map((member) {
|
||||||
.skip(2)
|
final user = member.user!;
|
||||||
.map((url) => Flexible(
|
return Flexible(
|
||||||
fit: FlexFit.tight,
|
fit: FlexFit.tight,
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
fit: BoxFit.cover,
|
fit: BoxFit.cover,
|
||||||
clipBehavior: Clip.antiAlias,
|
clipBehavior: Clip.antiAlias,
|
||||||
child: Transform.scale(
|
child: Transform.scale(
|
||||||
scale: 1.2,
|
scale: 1.2,
|
||||||
child: CachedNetworkImage(
|
child: BetterStreamBuilder<User>(
|
||||||
imageUrl: url,
|
stream: streamChat.client.state.usersStream
|
||||||
fit: BoxFit.cover,
|
.map((users) =>
|
||||||
),
|
users[member.userId ?? user.id] ?? user)
|
||||||
),
|
.distinct(),
|
||||||
|
initialData: user,
|
||||||
|
builder: (context, user) => UserAvatar(
|
||||||
|
user: user,
|
||||||
|
borderRadius: BorderRadius.zero,
|
||||||
),
|
),
|
||||||
))
|
),
|
||||||
.toList(),
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -114,14 +129,11 @@ class GroupImage extends StatelessWidget {
|
|||||||
|
|
||||||
if (selected) {
|
if (selected) {
|
||||||
avatar = ClipRRect(
|
avatar = ClipRRect(
|
||||||
borderRadius: (borderRadius ??
|
borderRadius: BorderRadius.circular(selectionThickness) +
|
||||||
streamChatTheme.ownMessageTheme.avatarTheme?.borderRadius ??
|
(borderRadius ?? previewTheme?.borderRadius ?? BorderRadius.zero),
|
||||||
BorderRadius.zero) +
|
|
||||||
BorderRadius.circular(selectionThickness),
|
|
||||||
child: Container(
|
child: Container(
|
||||||
color: selectionColor ?? streamChatTheme.colorTheme.accentPrimary,
|
constraints: constraints ?? previewTheme?.constraints,
|
||||||
height: 64,
|
color: selectionColor ?? colorTheme.accentPrimary,
|
||||||
width: 64,
|
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.all(selectionThickness),
|
padding: EdgeInsets.all(selectionThickness),
|
||||||
child: avatar,
|
child: avatar,
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ class StreamChatThemeData {
|
|||||||
required this.otherMessageTheme,
|
required this.otherMessageTheme,
|
||||||
required this.ownMessageTheme,
|
required this.ownMessageTheme,
|
||||||
required this.messageInputTheme,
|
required this.messageInputTheme,
|
||||||
required this.defaultChannelImage,
|
|
||||||
required this.defaultUserImage,
|
required this.defaultUserImage,
|
||||||
required this.primaryIconTheme,
|
required this.primaryIconTheme,
|
||||||
required this.reactionIcons,
|
required this.reactionIcons,
|
||||||
@@ -145,9 +144,6 @@ class StreamChatThemeData {
|
|||||||
/// Theme dedicated to the [MessageInput] widget
|
/// Theme dedicated to the [MessageInput] widget
|
||||||
final MessageInputTheme messageInputTheme;
|
final MessageInputTheme messageInputTheme;
|
||||||
|
|
||||||
/// The widget that will be built when the channel image is unavailable
|
|
||||||
final Widget Function(BuildContext, Channel) defaultChannelImage;
|
|
||||||
|
|
||||||
/// The widget that will be built when the user image is unavailable
|
/// The widget that will be built when the user image is unavailable
|
||||||
final Widget Function(BuildContext, User) defaultUserImage;
|
final Widget Function(BuildContext, User) defaultUserImage;
|
||||||
|
|
||||||
@@ -179,7 +175,6 @@ class StreamChatThemeData {
|
|||||||
textTheme: this.textTheme.merge(textTheme),
|
textTheme: this.textTheme.merge(textTheme),
|
||||||
colorTheme: this.colorTheme.merge(colorTheme),
|
colorTheme: this.colorTheme.merge(colorTheme),
|
||||||
primaryIconTheme: this.primaryIconTheme.merge(primaryIconTheme),
|
primaryIconTheme: this.primaryIconTheme.merge(primaryIconTheme),
|
||||||
defaultChannelImage: defaultChannelImage ?? this.defaultChannelImage,
|
|
||||||
defaultUserImage: defaultUserImage ?? this.defaultUserImage,
|
defaultUserImage: defaultUserImage ?? this.defaultUserImage,
|
||||||
channelPreviewTheme:
|
channelPreviewTheme:
|
||||||
this.channelPreviewTheme.merge(channelPreviewTheme),
|
this.channelPreviewTheme.merge(channelPreviewTheme),
|
||||||
@@ -199,7 +194,6 @@ class StreamChatThemeData {
|
|||||||
textTheme: textTheme.merge(other.textTheme),
|
textTheme: textTheme.merge(other.textTheme),
|
||||||
colorTheme: colorTheme.merge(other.colorTheme),
|
colorTheme: colorTheme.merge(other.colorTheme),
|
||||||
primaryIconTheme: other.primaryIconTheme,
|
primaryIconTheme: other.primaryIconTheme,
|
||||||
defaultChannelImage: other.defaultChannelImage,
|
|
||||||
defaultUserImage: other.defaultUserImage,
|
defaultUserImage: other.defaultUserImage,
|
||||||
channelPreviewTheme: channelPreviewTheme.merge(other.channelPreviewTheme),
|
channelPreviewTheme: channelPreviewTheme.merge(other.channelPreviewTheme),
|
||||||
channelTheme: channelTheme.merge(other.channelTheme),
|
channelTheme: channelTheme.merge(other.channelTheme),
|
||||||
@@ -223,7 +217,6 @@ class StreamChatThemeData {
|
|||||||
textTheme: textTheme,
|
textTheme: textTheme,
|
||||||
colorTheme: colorTheme,
|
colorTheme: colorTheme,
|
||||||
primaryIconTheme: iconTheme,
|
primaryIconTheme: iconTheme,
|
||||||
defaultChannelImage: (context, channel) => const SizedBox(),
|
|
||||||
defaultUserImage: (context, user) => Center(
|
defaultUserImage: (context, user) => Center(
|
||||||
child: CachedNetworkImage(
|
child: CachedNetworkImage(
|
||||||
filterQuality: FilterQuality.high,
|
filterQuality: FilterQuality.high,
|
||||||
|
|||||||
Reference in New Issue
Block a user