add image on tap
This commit is contained in:
@@ -57,15 +57,19 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
/// By default it calls [Navigator.pop]
|
/// By default it calls [Navigator.pop]
|
||||||
final VoidCallback onBackPressed;
|
final VoidCallback onBackPressed;
|
||||||
|
|
||||||
/// Callback to call when pressing the header is tapped.
|
/// Callback to call when the header is tapped.
|
||||||
final VoidCallback onTitleTap;
|
final VoidCallback onTitleTap;
|
||||||
|
|
||||||
|
/// Callback to call when the image is tapped.
|
||||||
|
final VoidCallback onImageTap;
|
||||||
|
|
||||||
/// Creates a channel header
|
/// Creates a channel header
|
||||||
ChannelHeader({
|
ChannelHeader({
|
||||||
Key key,
|
Key key,
|
||||||
this.showBackButton = true,
|
this.showBackButton = true,
|
||||||
this.onBackPressed,
|
this.onBackPressed,
|
||||||
this.onTitleTap,
|
this.onTitleTap,
|
||||||
|
this.onImageTap,
|
||||||
}) : preferredSize = Size.fromHeight(kToolbarHeight),
|
}) : preferredSize = Size.fromHeight(kToolbarHeight),
|
||||||
super(key: key);
|
super(key: key);
|
||||||
|
|
||||||
@@ -80,18 +84,16 @@ class ChannelHeader extends StatelessWidget implements PreferredSizeWidget {
|
|||||||
actions: <Widget>[
|
actions: <Widget>[
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(right: 10.0),
|
padding: const EdgeInsets.only(right: 10.0),
|
||||||
child: Stack(
|
child: Center(
|
||||||
children: <Widget>[
|
child: ChannelImage(
|
||||||
Center(
|
onTap: onImageTap,
|
||||||
child: ChannelImage(),
|
),
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
title: InkWell(
|
title: InkWell(
|
||||||
onTap: () {},
|
onTap: onTitleTap,
|
||||||
child: Container(
|
child: Container(
|
||||||
height: preferredSize.height,
|
height: preferredSize.height,
|
||||||
width: preferredSize.width,
|
width: preferredSize.width,
|
||||||
|
|||||||
+34
-19
@@ -47,6 +47,7 @@ class ChannelImage extends StatelessWidget {
|
|||||||
Key key,
|
Key key,
|
||||||
this.channel,
|
this.channel,
|
||||||
this.constraints,
|
this.constraints,
|
||||||
|
this.onTap,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// The channel to show the image of
|
/// The channel to show the image of
|
||||||
@@ -55,6 +56,9 @@ class ChannelImage extends StatelessWidget {
|
|||||||
/// The diameter of the image
|
/// The diameter of the image
|
||||||
final BoxConstraints constraints;
|
final BoxConstraints constraints;
|
||||||
|
|
||||||
|
/// The function called when the image is tapped
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final client = StreamChat.of(context);
|
final client = StreamChat.of(context);
|
||||||
@@ -86,25 +90,36 @@ class ChannelImage extends StatelessWidget {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: StreamChatTheme.of(context).accentColor,
|
color: StreamChatTheme.of(context).accentColor,
|
||||||
),
|
),
|
||||||
child: image != null
|
child: Stack(
|
||||||
? CachedNetworkImage(
|
fit: StackFit.expand,
|
||||||
imageUrl: image,
|
children: <Widget>[
|
||||||
errorWidget: (_, __, ___) {
|
image != null
|
||||||
return Center(
|
? CachedNetworkImage(
|
||||||
child: Text(
|
imageUrl: image,
|
||||||
snapshot.data?.containsKey('name') ?? false
|
errorWidget: (_, __, ___) {
|
||||||
? snapshot.data['name'][0]
|
return Center(
|
||||||
: '',
|
child: Text(
|
||||||
style: TextStyle(
|
snapshot.data?.containsKey('name') ?? false
|
||||||
color: Colors.white,
|
? snapshot.data['name'][0]
|
||||||
fontWeight: FontWeight.bold,
|
: '',
|
||||||
),
|
style: TextStyle(
|
||||||
),
|
color: Colors.white,
|
||||||
);
|
fontWeight: FontWeight.bold,
|
||||||
},
|
),
|
||||||
fit: BoxFit.cover,
|
),
|
||||||
)
|
);
|
||||||
: SizedBox(),
|
},
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
)
|
||||||
|
: SizedBox(),
|
||||||
|
Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user