flutter图片聊天泡泡,如何在Flutter中实现聊天气泡状的小部件

I want to design a widget of shape of a chat bubble where one corner is pinned and its height should adjust to the lines of the text? For now I'm using ClipRRect widget with some borderRadius. But I want one corner pinned. Any suggestions ?

7dcab17c0873445e6ecb309967713acb.png

UPDATE

I know this can be done using a stack but I'm looking for a better solution since I have to use it many times in a single view and using many stacks might affect the performs. ( correct me here if I'm wrong )

解决方案

For someone who want this get done with library. You can add bubble: ^1.1.9+1 (Take latest) package from pub.dev and wrap your message with Bubble.

Bubble(

style: right ? styleMe : styleSomebody,

//Your mesasge content child here...

)

Here right is boolean which tells the bubble is at right or left, Write your logic for that and add the style properties styleMe and styleSomebody inside your widget as shown below. Change style according to your theme.

double pixelRatio = MediaQuery.of(context).devicePixelRatio;

double px = 1 / pixelRatio;

BubbleStyle styleSomebody = BubbleStyle(

nip: BubbleNip.leftTop,

color: Colors.white,

elevation: 1 * px,

margin: BubbleEdges.only(top: 8.0, right: 50.0),

alignment: Alignment.topLeft,

);

BubbleStyle styleMe = BubbleStyle(

nip: BubbleNip.rightTop,

color: Colors.grey,

elevation: 1 * px,

margin: BubbleEdges.only(top: 8.0, left: 50.0),

alignment: Alignment.topRight,

);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值