From 3e8d34a622fb8836fe990fcf6d00b7a5ceb94195 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Sun, 19 Apr 2020 23:37:18 +0200 Subject: [PATCH] fix channel image and user avatar widget size --- lib/src/channel_image.dart | 26 +++++++++++++------------- lib/src/channel_name.dart | 13 +++++++------ lib/src/user_avatar.dart | 6 +++--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/lib/src/channel_image.dart b/lib/src/channel_image.dart index 45363064..6ecbc861 100644 --- a/lib/src/channel_image.dart +++ b/lib/src/channel_image.dart @@ -38,7 +38,7 @@ import 'package:stream_chat_flutter/stream_chat_flutter.dart'; /// The widget uses a [StreamBuilder] to render the channel information image as soon as it updates. /// /// By default the widget radius size is 40x40 pixels. -/// Set the property [size] to set a custom dimension. +/// Set the property [constraints] to set a custom dimension. /// /// The widget renders the ui based on the first ancestor of type [StreamChatTheme]. /// Modify it to change the widget appearance. @@ -46,14 +46,14 @@ class ChannelImage extends StatelessWidget { const ChannelImage({ Key key, this.channel, - this.size = 40, + this.constraints, }) : super(key: key); /// The channel to show the image of final Channel channel; /// The diameter of the image - final double size; + final BoxConstraints constraints; @override Widget build(BuildContext context) { @@ -63,14 +63,13 @@ class ChannelImage extends StatelessWidget { stream: channel.extraDataStream, initialData: channel.extraData, builder: (context, snapshot) { - var image = ''; + String image; if (snapshot.data?.containsKey('image') == true) { image = snapshot.data['image']; } else if (channel.state.members.length == 2) { - final otherMember = channel.state.members.firstWhere( - (member) => member.user.id != client.user.id - ); - image = otherMember.user.image; + final otherMember = channel.state.members + .firstWhere((member) => member.user.id != client.user.id); + image = otherMember.user.extraData['image']; } return ClipRRect( @@ -79,14 +78,15 @@ class ChannelImage extends StatelessWidget { .avatarTheme .borderRadius, child: Container( - constraints: StreamChatTheme.of(context) - .channelPreviewTheme - .avatarTheme - .constraints, + constraints: constraints ?? + StreamChatTheme.of(context) + .channelPreviewTheme + .avatarTheme + .constraints, decoration: BoxDecoration( color: StreamChatTheme.of(context).accentColor, ), - child: image != '' + child: image != null ? CachedNetworkImage( imageUrl: image, errorWidget: (_, __, ___) { diff --git a/lib/src/channel_name.dart b/lib/src/channel_name.dart index ce563804..2200b351 100644 --- a/lib/src/channel_name.dart +++ b/lib/src/channel_name.dart @@ -28,17 +28,18 @@ class ChannelName extends StatelessWidget { stream: channel.extraDataStream, initialData: channel.extraData, builder: (context, snapshot) { - var title; - if (snapshot.data['name'] == null && channel.state.members.length == 2) { - final otherMember = channel.state.members.firstWhere( - (member) => member.user.id != client.user.id - ); + String title; + if (snapshot.data['name'] == null && + channel.state.members.length == 2) { + final otherMember = channel.state.members + .firstWhere((member) => member.user.id != client.user.id); title = otherMember.user.name; } else { title = snapshot.data['name'] ?? channel.id; } - return Text(title, + return Text( + title, style: textStyle, ); }, diff --git a/lib/src/user_avatar.dart b/lib/src/user_avatar.dart index 478ae3b3..aaaa6a27 100644 --- a/lib/src/user_avatar.dart +++ b/lib/src/user_avatar.dart @@ -8,11 +8,11 @@ class UserAvatar extends StatelessWidget { const UserAvatar({ Key key, @required this.user, - this.radius = 16, + this.constraints, }) : super(key: key); final User user; - final double radius; + final BoxConstraints constraints; @override Widget build(BuildContext context) { @@ -20,7 +20,7 @@ class UserAvatar extends StatelessWidget { borderRadius: StreamChatTheme.of(context).ownMessageTheme.avatarTheme.borderRadius, child: Container( - constraints: + constraints: constraints ?? StreamChatTheme.of(context).ownMessageTheme.avatarTheme.constraints, decoration: BoxDecoration( color: StreamChatTheme.of(context).accentColor,