Flutter - 发送者和接收者的不同聊天气泡颜色
Flutter - different chatBubble colors for sender and reciever
如果我们想知道发送者和接收者之间的区别,他们每个人都应该有一个颜色,例如:发送者的气泡应该是绿色的,接收者的应该是白色的,我们如何实现这样的事情?
首先,使用包 chat_bubble
https://pub.dev/packages/chat_bubble
ChatBubble(
shadows: <Shadow>[
Shadow(
color: Colors.grey,
offset: Offset(-1.0, -1.0),
blurRadius: 0.1,
),
Shadow(
color: Colors.grey,
offset: Offset(1.0, 1.0),
blurRadius: 0.4,
)
],
direction: reverse ? ChatBubbleNipDirection.RIGHT: ChatBubbleNipDirection.LEFT,
child: Container(
color: isReceiver ? Colors.white : Colors.green,
child: img,
),
其中 isReceiver
是一个 bool
变量,表示它是接收者还是发送者。
如果我们想知道发送者和接收者之间的区别,他们每个人都应该有一个颜色,例如:发送者的气泡应该是绿色的,接收者的应该是白色的,我们如何实现这样的事情?
首先,使用包 chat_bubble
https://pub.dev/packages/chat_bubble
ChatBubble(
shadows: <Shadow>[
Shadow(
color: Colors.grey,
offset: Offset(-1.0, -1.0),
blurRadius: 0.1,
),
Shadow(
color: Colors.grey,
offset: Offset(1.0, 1.0),
blurRadius: 0.4,
)
],
direction: reverse ? ChatBubbleNipDirection.RIGHT: ChatBubbleNipDirection.LEFT,
child: Container(
color: isReceiver ? Colors.white : Colors.green,
child: img,
),
其中 isReceiver
是一个 bool
变量,表示它是接收者还是发送者。