buildDisplayAvatar method

Widget buildDisplayAvatar(
  1. BuildContext context
)

Implementation

Widget buildDisplayAvatar(BuildContext context) {
  var list = <Widget>[];
  if ((avatarDisplayList == null || avatarDisplayList!.isEmpty) && (avatarDisplayListAsset == null || avatarDisplayListAsset!.isEmpty)) {
    return Container();
  }

  var length = 0;

  if(avatarDisplayList != null) {
    length = avatarDisplayList!.length;
    for (var i = avatarDisplayList!.length; i >= 0; i--) {
      var left = (_getAvatarWidth() - _getDisplayPadding()) * i;
      if (i == avatarDisplayList!.length) {
        list.add(Positioned(
            left: left,
            child: Container(
                child: Center(
                  child: TDText(
                    displayText,
                    fontWeight: FontWeight.w600,
                    forceVerticalCenter: true,
                    textAlign: TextAlign.center,
                    font: _getTextFont(context),
                    textColor: TDTheme.of(context).brandNormalColor,
                  ),
                ),
                width: _getAvatarWidth(),
                height: _getAvatarWidth(),
                clipBehavior: Clip.hardEdge,
                decoration: ShapeDecoration(
                  color: TDTheme.of(context).brandColor2,
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(
                          _getAvatarWidth() - _getDisplayPadding()),
                      side: BorderSide(
                          color: Colors.white,
                          width: avatarDisplayBorder)),
                ))));
      } else {
        list.add(Positioned(
            left: left,
            child: Container(
                width: _getAvatarWidth(),
                height: _getAvatarWidth(),
                clipBehavior: Clip.antiAlias,
                decoration: ShapeDecoration(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(
                            _getAvatarWidth() - _getDisplayPadding()),
                        side: BorderSide(
                            color: Colors.white,
                            width: avatarDisplayBorder)),
                    image: DecorationImage(
                        image: NetworkImage(avatarDisplayList![i]),
                        fit: BoxFit.cover)))));
      }
    }
  } else if (avatarDisplayListAsset != null) {
    length = avatarDisplayListAsset!.length;
    for (var i = avatarDisplayListAsset!.length; i >= 0; i--) {
      var left = (_getAvatarWidth() - _getDisplayPadding()) * i;
      if (i == avatarDisplayListAsset!.length) {
        list.add(Positioned(
            left: left,
            child: Container(
                child: Center(
                  child: TDText(
                    displayText,
                    fontWeight: FontWeight.w600,
                    forceVerticalCenter: true,
                    textAlign: TextAlign.center,
                    font: _getTextFont(context),
                    textColor: TDTheme.of(context).brandNormalColor,
                  ),
                ),
                width: _getAvatarWidth(),
                height: _getAvatarWidth(),
                clipBehavior: Clip.hardEdge,
                decoration: ShapeDecoration(
                    color: TDTheme.of(context).brandColor2,
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(
                            _getAvatarWidth() - _getDisplayPadding()),
                        side: BorderSide(
                            color: Colors.white,
                            width: avatarDisplayBorder)),
                    ))));
      } else {
        list.add(Positioned(
            left: left,
            child: Container(
                width: _getAvatarWidth(),
                height: _getAvatarWidth(),
                clipBehavior: Clip.antiAlias,
                decoration: ShapeDecoration(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(
                            _getAvatarWidth() - _getDisplayPadding()),
                        side: BorderSide(
                            color: Colors.white,
                            width: avatarDisplayBorder)),
                    image: DecorationImage(
                        image: AssetImage(avatarDisplayListAsset![i]),
                        fit: BoxFit.cover)))));
      }
    }
  }

  return SizedBox(
    height: _getAvatarWidth(),
    width: _getAvatarWidth() * (length + 1) -
        length * _getDisplayPadding(),
    child: Stack(children: list),
  );
}