fromRxChat static method
- RxChat? chat, {
- Key? key,
- AvatarRadius? radius,
- double opacity = 1,
- FutureOr<
void> onForbidden()?, - AvatarShape shape = AvatarShape.circle,
Creates an AvatarWidget from the specified RxChat.
Implementation
static Widget fromRxChat(
RxChat? chat, {
Key? key,
AvatarRadius? radius,
double opacity = 1,
FutureOr<void> Function()? onForbidden,
AvatarShape shape = AvatarShape.circle,
}) {
if (chat == null) {
return AvatarWidget(key: key, radius: radius, opacity: opacity);
}
return Obx(() {
if (chat.chat.value.isMonolog) {
return AvatarWidget.fromMonolog(
chat.chat.value,
chat.me,
radius: radius,
opacity: opacity,
shape: shape,
);
}
final bool isDialog = chat.chat.value.isDialog;
final RxUser? user = chat.members.values
.firstWhereOrNull((e) => e.user.id != chat.me)
?.user;
final bool isOnline = isDialog && user?.user.value.online == true;
final bool isAway =
isDialog && user?.user.value.presence == UserPresence.away;
if (isDialog && user?.id.isSupport == true) {
return AvatarWidget.support(
isOnline: isOnline,
isAway: isAway,
radius: radius,
opacity: opacity,
shape: shape,
);
}
return AvatarWidget(
key: key,
isOnline: isOnline,
isAway: isAway,
avatar: chat.avatar.value,
title: chat.title(withDeletedLabel: false),
color: chat.chat.value.colorDiscriminant(chat.me).sum(),
radius: radius,
opacity: opacity,
onForbidden: onForbidden,
shape: shape,
);
});
}