diff --git a/lib/src/channel_header.dart b/lib/src/channel_header.dart index ae68bcb7..659a24eb 100644 --- a/lib/src/channel_header.dart +++ b/lib/src/channel_header.dart @@ -57,11 +57,19 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget { /// By default it calls [Navigator.pop] final VoidCallback onBackPressed; + /// Callback to call when the header is tapped. + final VoidCallback onTitleTap; + + /// Callback to call when the image is tapped. + final VoidCallback onImageTap; + /// Creates a channel header ChannelHeader({ Key key, this.showBackButton = true, this.onBackPressed, + this.onTitleTap, + this.onImageTap, }) : preferredSize = Size.fromHeight(kToolbarHeight), super(key: key); @@ -76,27 +84,33 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget { actions: [ Padding( padding: const EdgeInsets.only(right: 10.0), - child: Stack( - children: [ - Center( - child: ChannelImage(), - ), - ], + child: Center( + child: ChannelImage( + onTap: onImageTap, + ), ), ), ], centerTitle: true, - title: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - ChannelName( - textStyle: StreamChatTheme.of(context) - .channelTheme - .channelHeaderTheme - .title, + title: InkWell( + onTap: onTitleTap, + child: Container( + height: preferredSize.height, + width: preferredSize.width, + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + ChannelName( + textStyle: StreamChatTheme.of(context) + .channelTheme + .channelHeaderTheme + .title, + ), + _buildLastActive(context, channel), + ], ), - _buildLastActive(context, channel), - ], + ), ), ); } diff --git a/lib/src/channel_image.dart b/lib/src/channel_image.dart index 6ecbc861..7d674ac1 100644 --- a/lib/src/channel_image.dart +++ b/lib/src/channel_image.dart @@ -47,6 +47,7 @@ class ChannelImage extends StatelessWidget { Key key, this.channel, this.constraints, + this.onTap, }) : super(key: key); /// The channel to show the image of @@ -55,6 +56,9 @@ class ChannelImage extends StatelessWidget { /// The diameter of the image final BoxConstraints constraints; + /// The function called when the image is tapped + final VoidCallback onTap; + @override Widget build(BuildContext context) { final client = StreamChat.of(context); @@ -86,25 +90,36 @@ class ChannelImage extends StatelessWidget { decoration: BoxDecoration( color: StreamChatTheme.of(context).accentColor, ), - child: image != null - ? CachedNetworkImage( - imageUrl: image, - errorWidget: (_, __, ___) { - return Center( - child: Text( - snapshot.data?.containsKey('name') ?? false - ? snapshot.data['name'][0] - : '', - style: TextStyle( - color: Colors.white, - fontWeight: FontWeight.bold, - ), - ), - ); - }, - fit: BoxFit.cover, - ) - : SizedBox(), + child: Stack( + fit: StackFit.expand, + children: [ + image != null + ? CachedNetworkImage( + imageUrl: image, + errorWidget: (_, __, ___) { + return Center( + child: Text( + snapshot.data?.containsKey('name') ?? false + ? snapshot.data['name'][0] + : '', + style: TextStyle( + color: Colors.white, + fontWeight: FontWeight.bold, + ), + ), + ); + }, + fit: BoxFit.cover, + ) + : SizedBox(), + Material( + color: Colors.transparent, + child: InkWell( + onTap: onTap, + ), + ), + ], + ), ), ); }); diff --git a/lib/src/channel_list_view.dart b/lib/src/channel_list_view.dart index e968e6c0..1d5992c7 100644 --- a/lib/src/channel_list_view.dart +++ b/lib/src/channel_list_view.dart @@ -56,6 +56,7 @@ class ChannelListView extends StatefulWidget { this.channelWidget, this.channelPreviewBuilder, this.errorBuilder, + this.onImageTap, }) : super(key: key); final Widget Function(Error error) errorBuilder; @@ -94,6 +95,9 @@ class ChannelListView extends StatefulWidget { /// Builder used to create a custom channel preview final ChannelPreviewBuilder channelPreviewBuilder; + /// The function called when the image is tapped + final Function(Channel) onImageTap; + @override _ChannelListViewState createState() => _ChannelListViewState(); } @@ -215,8 +219,6 @@ class _ChannelListViewState extends State { if (i < channels.length) { final channel = channels[i]; - final channelClient = streamChat.client.channels[channel.cid]; - ChannelTapCallback onTap; if (widget.onChannelTap != null) { onTap = widget.onChannelTap; @@ -237,11 +239,11 @@ class _ChannelListViewState extends State { } return StreamChannel( - key: ValueKey('CHANNEL-${channelClient.id}'), - channel: channelClient, + key: ValueKey('CHANNEL-${channel.id}'), + channel: channel, child: StreamBuilder( - initialData: channelClient.updatedAt, - stream: channelClient.updatedAtStream, + initialData: channel.updatedAt, + stream: channel.updatedAtStream, builder: (context, snapshot) { Widget child; if (widget.channelPreviewBuilder != null) { @@ -249,14 +251,14 @@ class _ChannelListViewState extends State { children: [ widget.channelPreviewBuilder( context, - channelClient, + channel, ), Positioned.fill( child: Material( color: Colors.transparent, child: InkWell( onTap: () { - onTap(channelClient, widget.channelWidget); + onTap(channel, widget.channelWidget); }, ), ), @@ -265,9 +267,14 @@ class _ChannelListViewState extends State { ); } else { child = ChannelPreview( - channel: channelClient, - onTap: (channelClient) { - onTap(channelClient, widget.channelWidget); + channel: channel, + onImageTap: widget.onImageTap != null + ? () { + widget.onImageTap(channel); + } + : null, + onTap: (channel) { + onTap(channel, widget.channelWidget); }, ); } diff --git a/lib/src/channel_preview.dart b/lib/src/channel_preview.dart index b6e3beba..9b949a68 100644 --- a/lib/src/channel_preview.dart +++ b/lib/src/channel_preview.dart @@ -25,10 +25,14 @@ class ChannelPreview extends StatelessWidget { /// Channel displayed final Channel channel; + /// The function called when the image is tapped + final VoidCallback onImageTap; + ChannelPreview({ @required this.channel, Key key, this.onTap, + this.onImageTap, }) : super(key: key); @override @@ -37,7 +41,9 @@ class ChannelPreview extends StatelessWidget { onTap: () { onTap(channel); }, - leading: ChannelImage(), + leading: ChannelImage( + onTap: onImageTap, + ), title: ChannelName( textStyle: StreamChatTheme.of(context).channelPreviewTheme.title, ),