chatClientBoilerPlate function

Widget chatClientBoilerPlate({
  1. required BuildContext ctx,
  2. required ChatTheme theme,
  3. required String time,
  4. required Widget child,
  5. required bool showName,
  6. required bool showAvatar,
  7. required Widget verificationBadge,
  8. required User user,
})

Implementation

Widget chatClientBoilerPlate(
    {required BuildContext ctx,
    required ChatTheme theme,
    required String time,
    required Widget child,
    required bool showName,
    required bool showAvatar,
    required Widget verificationBadge,
    required User user}) {
  return Row(
    children: [
      Padding(
        padding: theme.messageMargin,
        child: ConstrainedBox(
          constraints: BoxConstraints(
            maxWidth: min(
              max(
                  (MediaQuery.of(ctx).size.width -
                      theme.messageMargin.horizontal),
                  350),
              MediaQuery.of(ctx).size.width * (theme.messageWidth),
            ),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                decoration: BoxDecoration(
                  color: theme.inwardMessageBackgroundColor,
                  borderRadius: theme.inwardMessageBorderRadius,
                ),
                child: IntrinsicWidth(child: child),
              ),
              const SizedBox(
                height: 5,
              ),
              Row(
                children: [
                  Row(
                    children: [
                      showAvatar
                          ? UserAvatar(
                              user: user,
                              theme: theme,
                            )
                          : Container(),
                      showName
                          ? Row(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                Text(
                                  user.name ?? "",
                                  maxLines: 1,
                                  overflow: TextOverflow.fade,
                                  style: theme.usernameTextStyle
                                      .copyWith(color: user.color),
                                ),
                                const SizedBox(
                                  width: 5,
                                ),
                                user.isVerified
                                    ? theme.verificationBadge
                                    : Container(),
                              ],
                            )
                          : Container(),
                    ],
                  ),
                  const SizedBox(
                    width: 10,
                  ),
                  Text(
                    time,
                    style: theme.timeTextStyle,
                    textAlign: TextAlign.end,
                  ),
                ],
              )
            ],
          ),
        ),
      ),
      const Spacer(),
    ],
  );
}