fromRxUser static method

Widget fromRxUser(
  1. RxUser? user, {
  2. Key? key,
  3. AvatarRadius? radius,
  4. double opacity = 1,
  5. bool badge = true,
  6. AvatarShape shape = AvatarShape.circle,
  7. BoxConstraints? constraints,
})

Creates an AvatarWidget from the specified reactive user.

Implementation

static Widget fromRxUser(
  RxUser? user, {
  Key? key,
  AvatarRadius? radius,
  double opacity = 1,
  bool badge = true,
  AvatarShape shape = AvatarShape.circle,
  BoxConstraints? constraints,
}) {
  if (user == null) {
    return AvatarWidget.fromUser(
      user?.user.value,
      key: key,
      radius: radius,
      opacity: opacity,
      shape: shape,
      constraints: constraints,
    );
  }

  return Obx(() {
    final bool isOnline = badge && user.user.value.online == true;
    final bool isAway =
        badge && user.user.value.presence == UserPresence.away;

    if (user.id.isSupport == true) {
      return AvatarWidget.support(
        isOnline: isOnline,
        isAway: isAway,
        radius: radius,
        opacity: opacity,
        shape: shape,
        constraints: constraints,
      );
    }

    return AvatarWidget(
      key: key,
      isOnline: isOnline,
      isAway: isAway,
      avatar: user.user.value.avatar,
      title: user.title(withDeletedLabel: false),
      color: user.user.value.num.val.sum(),
      radius: radius,
      opacity: opacity,
      shape: shape,
      constraints: constraints,
    );
  });
}