add online indicator to useravatar
This commit is contained in:
@@ -49,6 +49,7 @@ class ChannelImage extends StatelessWidget {
|
|||||||
this.channel,
|
this.channel,
|
||||||
this.constraints,
|
this.constraints,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
|
this.showOnlineStatus = true,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
/// The channel to show the image of
|
/// The channel to show the image of
|
||||||
@@ -60,9 +61,11 @@ class ChannelImage extends StatelessWidget {
|
|||||||
/// The function called when the image is tapped
|
/// The function called when the image is tapped
|
||||||
final VoidCallback onTap;
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
final bool showOnlineStatus;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final client = StreamChat.of(context);
|
final streamChat = StreamChat.of(context);
|
||||||
final channel = this.channel ?? StreamChannel.of(context).channel;
|
final channel = this.channel ?? StreamChannel.of(context).channel;
|
||||||
return StreamBuilder<Map<String, dynamic>>(
|
return StreamBuilder<Map<String, dynamic>>(
|
||||||
stream: channel.extraDataStream,
|
stream: channel.extraDataStream,
|
||||||
@@ -73,8 +76,26 @@ class ChannelImage extends StatelessWidget {
|
|||||||
image = snapshot.data['image'];
|
image = snapshot.data['image'];
|
||||||
} else if (channel.state.members.length == 2) {
|
} else if (channel.state.members.length == 2) {
|
||||||
final otherMember = channel.state.members
|
final otherMember = channel.state.members
|
||||||
.firstWhere((member) => member.user.id != client.user.id);
|
.firstWhere((member) => member.user.id != streamChat.user.id);
|
||||||
image = otherMember.user.extraData['image'];
|
return StreamBuilder<User>(
|
||||||
|
stream: streamChat.client.state.usersStream
|
||||||
|
.map((users) => users[otherMember.userId]),
|
||||||
|
initialData: otherMember.user,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
return UserAvatar(
|
||||||
|
user: snapshot.data ?? otherMember.user,
|
||||||
|
constraints: constraints ??
|
||||||
|
StreamChatTheme.of(context)
|
||||||
|
.channelPreviewTheme
|
||||||
|
.avatarTheme
|
||||||
|
.constraints,
|
||||||
|
onTap: onTap != null
|
||||||
|
? (_) {
|
||||||
|
onTap();
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return ClipRRect(
|
return ClipRRect(
|
||||||
|
|||||||
@@ -426,6 +426,7 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
child: UserAvatar(
|
child: UserAvatar(
|
||||||
user: e.user,
|
user: e.user,
|
||||||
constraints: BoxConstraints.loose(Size.fromRadius(16)),
|
constraints: BoxConstraints.loose(Size.fromRadius(16)),
|
||||||
|
showOnlineStatus: false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -648,6 +649,7 @@ class _MessageWidgetState extends State<MessageWidget> {
|
|||||||
user: widget.message.user,
|
user: widget.message.user,
|
||||||
onTap: widget.onUserAvatarTap,
|
onTap: widget.onUserAvatarTap,
|
||||||
constraints: widget.messageTheme.avatarTheme.constraints,
|
constraints: widget.messageTheme.avatarTheme.constraints,
|
||||||
|
showOnlineStatus: false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
+70
-37
@@ -9,55 +9,88 @@ class UserAvatar extends StatelessWidget {
|
|||||||
Key key,
|
Key key,
|
||||||
@required this.user,
|
@required this.user,
|
||||||
this.constraints,
|
this.constraints,
|
||||||
|
this.onlineIndicatorConstraints,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
|
this.showOnlineStatus = true,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
final User user;
|
final User user;
|
||||||
final BoxConstraints constraints;
|
final BoxConstraints constraints;
|
||||||
|
final BoxConstraints onlineIndicatorConstraints;
|
||||||
final void Function(User) onTap;
|
final void Function(User) onTap;
|
||||||
|
final bool showOnlineStatus;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: onTap != null
|
||||||
if (onTap != null) {
|
? () {
|
||||||
onTap(user);
|
if (onTap != null) {
|
||||||
}
|
onTap(user);
|
||||||
},
|
}
|
||||||
child: ClipRRect(
|
}
|
||||||
borderRadius: StreamChatTheme.of(context)
|
: null,
|
||||||
.ownMessageTheme
|
child: Stack(
|
||||||
.avatarTheme
|
children: <Widget>[
|
||||||
.borderRadius,
|
ClipRRect(
|
||||||
child: Container(
|
borderRadius: StreamChatTheme.of(context)
|
||||||
constraints: constraints ??
|
.ownMessageTheme
|
||||||
StreamChatTheme.of(context)
|
.avatarTheme
|
||||||
.ownMessageTheme
|
.borderRadius,
|
||||||
.avatarTheme
|
child: Container(
|
||||||
.constraints,
|
constraints: constraints ??
|
||||||
decoration: BoxDecoration(
|
StreamChatTheme.of(context)
|
||||||
color: StreamChatTheme.of(context).accentColor,
|
.ownMessageTheme
|
||||||
|
.avatarTheme
|
||||||
|
.constraints,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: StreamChatTheme.of(context).accentColor,
|
||||||
|
),
|
||||||
|
child: user.extraData?.containsKey('image') ?? false
|
||||||
|
? CachedNetworkImage(
|
||||||
|
imageUrl: user.extraData['image'],
|
||||||
|
errorWidget: (_, __, ___) {
|
||||||
|
return Center(
|
||||||
|
child: Text(
|
||||||
|
user.extraData?.containsKey('name') ?? false
|
||||||
|
? user.extraData['name'][0]
|
||||||
|
: '',
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
)
|
||||||
|
: StreamChatTheme.of(context).defaultUserImage(context, user),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: user.extraData?.containsKey('image') ?? false
|
if (showOnlineStatus && user.online)
|
||||||
? CachedNetworkImage(
|
Positioned(
|
||||||
imageUrl: user.extraData['image'],
|
top: 0,
|
||||||
errorWidget: (_, __, ___) {
|
right: 0,
|
||||||
return Center(
|
child: Material(
|
||||||
child: Text(
|
child: Center(
|
||||||
user.extraData?.containsKey('name') ?? false
|
child: Container(
|
||||||
? user.extraData['name'][0]
|
padding: const EdgeInsets.all(2.0),
|
||||||
: '',
|
constraints: onlineIndicatorConstraints ??
|
||||||
style: TextStyle(
|
BoxConstraints.tightFor(
|
||||||
color: Colors.white,
|
width: 12,
|
||||||
fontWeight: FontWeight.bold,
|
height: 12,
|
||||||
),
|
),
|
||||||
),
|
child: Material(
|
||||||
);
|
shape: CircleBorder(),
|
||||||
},
|
color: Color(0xff20E070),
|
||||||
fit: BoxFit.cover,
|
),
|
||||||
)
|
),
|
||||||
: StreamChatTheme.of(context).defaultUserImage(context, user),
|
),
|
||||||
),
|
shape: CircleBorder(),
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user