Skip to content

Commit

Permalink
Chat bubbles are more customizable now
Browse files Browse the repository at this point in the history
  • Loading branch information
fayeed committed Jul 27, 2019
1 parent 1f81114 commit a705405
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.1.2]

- Chat Bubble are more customizable now.

## [0.1.1]

- User avatar now show user initials while loading & if not avatar is passed
Expand Down
1 change: 1 addition & 0 deletions lib/src/message_listview.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class MessageListView extends StatelessWidget {
child: messageBuilder != null
? messageBuilder(messages[i])
: MessageContainer(
isUser: messages[i].user.uid == user.uid,
message: messages[i],
timeFormat: timeFormat,
messageImageBuilder: messageImageBuilder,
Expand Down
12 changes: 10 additions & 2 deletions lib/src/models/chat_user.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ class ChatUser {
/// is automatically assigned to the chat user.
String uid;

/// A [optional] parameter to set the user name.
/// An [optional] parameter to set the user name.
String name;

/// A [optional] parameter to set the user avatar.
/// An [optional] parameter to set the user avatar.
String avatar;

/// An [optional] parameter to set Text Color
Color color;

/// An [optional] parameter to set The Message bubble Color
Color containerColor;

ChatUser({
String uid,
this.name,
this.avatar,
this.containerColor,
this.color,
}) {
this.uid = uid != null ? uid : Uuid().v4().toString();
}
Expand Down
40 changes: 28 additions & 12 deletions lib/src/widgets/message_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,40 @@ class MessageContainer extends StatelessWidget {
/// and can also add custom pattersn using regex
final List<MatchText> parsePatterns;

const MessageContainer({
@required this.message,
@required this.timeFormat,
this.messageImageBuilder,
this.messageTextBuilder,
this.messageTimeBuilder,
this.messageContainerDecoration,
this.parsePatterns = const <MatchText>[],
});
/// A flag which is used for assiging styles
final bool isUser;

const MessageContainer(
{@required this.message,
@required this.timeFormat,
this.messageImageBuilder,
this.messageTextBuilder,
this.messageTimeBuilder,
this.messageContainerDecoration,
this.parsePatterns = const <MatchText>[],
this.isUser});

@override
Widget build(BuildContext context) {
/* var containerDecoration = messageContainerDecoration;
containerDecoration.color = message.user.containerColor != null
? message.user.containerColor : messageContainerDecoration.c */
return ConstrainedBox(
constraints: BoxConstraints(
maxWidth: 220.0,
),
child: Container(
decoration: messageContainerDecoration != null
? messageContainerDecoration
? messageContainerDecoration.copyWith(
color: message.user.containerColor != null
? message.user.containerColor
: messageContainerDecoration.color,
)
: BoxDecoration(
color: Colors.blue,
color: message.user.containerColor != null
? message.user.containerColor
: isUser ? Theme.of(context).accentColor : Colors.white70,
borderRadius: BorderRadius.circular(5.0),
),
margin: EdgeInsets.only(
top: 8.0,
Expand All @@ -73,7 +86,10 @@ class MessageContainer extends StatelessWidget {
ParsedText(
parse: parsePatterns,
text: message.text,
style: TextStyle(color: Colors.white),
style: TextStyle(
color: message.user.color != null
? message.user.color
: isUser ? Colors.white70 : Colors.black87),
),
if (message.image != null)
if (messageImageBuilder != null)
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: dash_chat
description: A new Flutter package project.
version: 0.1.1
version: 0.1.2
author:
homepage:

Expand Down

0 comments on commit a705405

Please sign in to comment.