【问题标题】:How to make a chat bubble like WhatsApp's chat bubble in Flutter?如何在 Flutter 中制作像 WhatsApp 的聊天气泡一样的聊天气泡?
【发布时间】:2022-11-17 16:05:05
【问题描述】:

我要制作一个聊天气泡,就像 WhatsApp 的聊天气泡一样。然而,事情还没有完成。我需要做的是从包含 URL 的消息中读取图像。

预期成绩:

实际结果:

我的代码:

Row(
  crossAxisAlignment: CrossAxisAlignment.end,
  mainAxisSize: MainAxisSize.max,
  mainAxisAlignment: MainAxisAlignment.start,
  children: [
    Container(
      width: MediaQuery.of(context).size.width * 0.75,
      padding: const EdgeInsets.all(5.0),
      decoration: const BoxDecoration(
        color: Colors.amber,
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(15.0),
          topRight: Radius.circular(15.0),
          bottomLeft: Radius.circular(0.0),
          bottomRight: Radius.circular(15.0),
        ),
      ),
      child: Column(
        children: [
          Align(
            alignment: Alignment.centerLeft,
            child: Text(
              name,
              style: const TextStyle(
                color: Color.fromARGB(255, 50, 150, 150),
                fontSize: 12.5,
              ),
            ),
          ),
          Align(
            alignment: Alignment.centerLeft,
            child: Linkify(
              onOpen: (link) async {
                if (await canLaunchUrl(
                  Uri.parse(link.url),
                )) {
                  await launchUrl(
                      Uri.parse(link.url));
                } else {
                  throw "Could not launch $link";
                }
              },
              text: message,
              style: const TextStyle(
                color: Color.fromARGB(255, 50, 150, 150),
                fontSize: 20.0,
              ),
              linkStyle: const TextStyle(
                fontSize: 20.0,
                color: Colors.blue,
                decoration: TextDecoration.underline,
              ),
            ),
          ),
          Align(
            alignment: Alignment.centerRight,
            child: Text(
              timeago.format(sentAt.toDate()),
              style: const TextStyle(
                color: Color.fromARGB(255, 50, 150, 150),
                fontSize: 15.0,
              ),
            ),
          ),
        ],
      ),
    ),
  ],
),

如果您需要更多信息,请随时发表评论!

如何在Flutter中制作一个像WhatsApp的聊天气泡一样的聊天气泡?我将不胜感激任何帮助。先感谢您!

【问题讨论】:

  • 你也可以添加新闻网址吗?我认为它将从它的 html 标签中获取这些信息。

标签: flutter dart user-interface flutter-layout whatsapp


【解决方案1】:

您只需要检测文本中是否有 URL 并预览 URL。您可以使用 any_link_preview 包进行 URL 预览。

【讨论】:

    猜你喜欢
    • 2020-01-29
    • 2021-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多