add image on tap to channel preview

This commit is contained in:
Salvatore Giordano
2020-04-20 12:21:42 +02:00
parent 9ad7d56217
commit e02e1be174
2 changed files with 25 additions and 12 deletions
+18 -11
View File
@@ -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<ChannelListView> {
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<ChannelListView> {
}
return StreamChannel(
key: ValueKey<String>('CHANNEL-${channelClient.id}'),
channel: channelClient,
key: ValueKey<String>('CHANNEL-${channel.id}'),
channel: channel,
child: StreamBuilder<DateTime>(
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<ChannelListView> {
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<ChannelListView> {
);
} 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);
},
);
}
+7 -1
View File
@@ -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,
),