build method

  1. @override
Widget build(
  1. BuildContext context
)
override

chat bubble builder method

Implementation

@override
Widget build(BuildContext context) {
  bool stateTick = false;
  Icon? stateIcon;
  if (sent) {
    stateTick = true;
    stateIcon = Icon(
      Icons.done,
      size: 18,
      color: Color(0xFF97AD8E),
    );
  }
  if (delivered) {
    stateTick = true;
    stateIcon = Icon(
      Icons.done_all,
      size: 18,
      color: Color(0xFF97AD8E),
    );
  }
  if (seen) {
    stateTick = true;
    stateIcon = Icon(
      Icons.done_all,
      size: 18,
      color: Color(0xFF92DEDA),
    );
  }

  return Row(
    children: <Widget>[
      isSender
          ? Expanded(
              child: SizedBox(
                width: 5,
              ),
            )
          : leading ?? Container(),
      Container(
        color: Colors.transparent,
        constraints: constraints ??
            BoxConstraints(maxWidth: MediaQuery.of(context).size.width * .8),
        margin: margin,
        padding: padding,
        child: GestureDetector(
          onTap: onTap,
          onDoubleTap: onDoubleTap,
          onLongPress: onLongPress,
          child: Container(
            decoration: BoxDecoration(
              color: color,
              borderRadius: BorderRadius.only(
                topLeft: Radius.circular(bubbleRadius),
                topRight: Radius.circular(bubbleRadius),
                bottomLeft: Radius.circular(tail
                    ? isSender
                        ? bubbleRadius
                        : 0
                    : BUBBLE_RADIUS),
                bottomRight: Radius.circular(tail
                    ? isSender
                        ? 0
                        : bubbleRadius
                    : BUBBLE_RADIUS),
              ),
            ),
            child: Stack(
              children: <Widget>[
                Padding(
                  padding: stateTick
                      ? EdgeInsets.fromLTRB(12, 6, 28, 6)
                      : EdgeInsets.symmetric(vertical: 6, horizontal: 12),
                  child: SelectableText(
                    text,
                    style: textStyle,
                    textAlign: TextAlign.left,
                  ),
                ),
                stateIcon != null && stateTick
                    ? Positioned(
                        bottom: 4,
                        right: 6,
                        child: stateIcon,
                      )
                    : SizedBox(
                        width: 1,
                      ),
              ],
            ),
          ),
        ),
      ),
      if (isSender && trailing != null) SizedBox.shrink(),
    ],
  );
}