Skip to content

Commit

Permalink
Quick Reply functionality added
Browse files Browse the repository at this point in the history
  • Loading branch information
fayeed committed Jul 27, 2019
1 parent a705405 commit 8fd0ed2
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 13 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.3]

- Quick Reply functionality added.

## [0.1.2]

- Chat Bubble are more customizable now.
Expand Down
58 changes: 49 additions & 9 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class MyApp extends StatelessWidget {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
primarySwatch: Colors.purple,
),
home: MyHomePage(),
);
Expand All @@ -31,12 +31,16 @@ class _MyHomePageState extends State<MyHomePage> {
name: "Fayeed",
uid: "123456789",
avatar: "https://www.wrappixel.com/ampleadmin/assets/images/users/4.jpg",
color: Colors.white,
containerColor: Colors.pinkAccent,
);

final ChatUser otherUser = ChatUser(
name: "Mrfatty",
uid: "25649654",
avatar: "https://www.wrappixel.com/ampleadmin/assets/images/users/1.jpg",
avatar: "",
color: Colors.white,
containerColor: Colors.green,
);

List<ChatMessage> messages = List<ChatMessage>();
Expand All @@ -59,10 +63,33 @@ class _MyHomePageState extends State<MyHomePage> {
text: "When do you want to meet tommorrow?",
user: user,
createdAt: d3));
messages.add(ChatMessage(
messages.add(
ChatMessage(
text: "Ok, great meet you there [email protected]",
user: otherUser,
createdAt: d3));
createdAt: d3,
quickReplies: QuickReplies(
values: <Reply>[
Reply(
title: "I will Message you later",
value: "I will Message you later",
),
Reply(
title: "Maybe not.",
value: "Maybe not.",
),
Reply(
title: "Meet me at my place",
value: "Meet me at my place",
),
Reply(
title: "What!!",
value: "What!!",
),
],
),
),
);

super.initState();
}
Expand Down Expand Up @@ -101,14 +128,27 @@ class _MyHomePageState extends State<MyHomePage> {
onLongPressAvatar: (ChatUser user) {
print("OnLongPressAvatar: ${user.name}");
},
messageContainerDecoration: BoxDecoration(
color: Colors.green,
),
/* messageContainerDecoration: BoxDecoration(
color: Colors.green,
), */
inputMaxLines: 2,
messageContainerPadding: EdgeInsets.all(20.0),
messageContainerPadding: EdgeInsets.all(5.0),
alwaysShowSend: true,
inputTextStyle: TextStyle(fontSize: 24.0),
inputTextStyle: TextStyle(fontSize: 16.0),
inputContainerStyle: BoxDecoration(border: Border.all(width: 0.0)),
onQuickReply: (Reply reply) {
setState(() {
messages.add(ChatMessage(
text: reply.value, createdAt: DateTime.now(), user: user));

messages = [...messages];
});
},
quickReplyStyle: BoxDecoration(),
quickReplyTextStyle: TextStyle(),
quickReplyBuilder: (Reply reply) {
return Text(reply.value);
},
),
);
}
Expand Down
1 change: 1 addition & 0 deletions lib/dash_chat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ part 'src/chat_input_toolbar.dart';
part 'src/message_listview.dart';
part 'src/widgets/avatar_container.dart';
part 'src/widgets/message_container.dart';
part 'src/widgets/quick_reply.dart';
42 changes: 42 additions & 0 deletions lib/src/chat_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,25 @@ class DashChat extends StatefulWidget {
/// Padding for the [MessageListView].
final EdgeInsetsGeometry messageContainerPadding;

/// Callback method when the quickReply was tapped on
/// will pass [Reply] as a paramter to function.
final Function(Reply) onQuickReply;

/// Container style for the QuickReply Container [BoxDecoration].
final BoxDecoration quickReplyStyle;

/// [TextStyle] for QuickReply textstyle.
final TextStyle quickReplyTextStyle;

/// quickReplyBuilder will override the the default QuickReply Widget.
final Widget Function(Reply) quickReplyBuilder;

DashChat({
Key key,
this.onQuickReply,
this.quickReplyStyle,
this.quickReplyTextStyle,
this.quickReplyBuilder,
this.messageContainerPadding =
const EdgeInsets.only(top: 10.0, left: 2.0, right: 2.0),
this.scrollController,
Expand Down Expand Up @@ -261,6 +278,31 @@ class DashChatState extends State<DashChat> {
messageContainerDecoration: widget.messageContainerDecoration,
parsePatterns: widget.parsePatterns,
),
if (widget.messages[widget.messages.length - 1].user.uid !=
widget.user.uid)
Container(
constraints: BoxConstraints(maxHeight: 100.0),
width: MediaQuery.of(context).size.width,
child: Wrap(
children: <Widget>[
if (widget.messages[widget.messages.length - 1]
.quickReplies !=
null)
...widget.messages[widget.messages.length - 1]
.quickReplies.values
.sublist(0, 3)
.map(
(reply) => QuickReply(
reply: reply,
onReply: widget.onQuickReply,
quickReplyBuilder: widget.quickReplyBuilder,
quickReplyStyle: widget.quickReplyStyle,
quickReplyTextStyle: widget.quickReplyTextStyle,
),
)
.toList(),
],
)),
if (widget.chatFooterBuilder != null) widget.chatFooterBuilder(),
ChatInputToolbar(
inputMaxLines: widget.inputMaxLines,
Expand Down
3 changes: 0 additions & 3 deletions lib/src/widgets/message_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ class MessageContainer extends StatelessWidget {

@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,
Expand Down
55 changes: 55 additions & 0 deletions lib/src/widgets/quick_reply.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
part of dash_chat;

class QuickReply extends StatelessWidget {
final Reply reply;

final Function(Reply) onReply;

final BoxDecoration quickReplyStyle;

final TextStyle quickReplyTextStyle;

final Widget Function(Reply) quickReplyBuilder;

const QuickReply({
this.quickReplyBuilder,
this.quickReplyStyle,
this.quickReplyTextStyle,
this.onReply,
this.reply,
});

@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () {
onReply(reply);
},
child: quickReplyBuilder != null
? quickReplyBuilder(reply)
: Container(
margin: EdgeInsets.only(
left: 5.0, right: 5.0, top: 5.0, bottom: 10.0),
padding: EdgeInsets.symmetric(horizontal: 5.0, vertical: 5.0),
decoration: quickReplyStyle != null
? quickReplyStyle
: BoxDecoration(
border: Border.all(
width: 1.0, color: Theme.of(context).accentColor),
borderRadius: BorderRadius.circular(5.0),
),
constraints: BoxConstraints(
maxWidth: MediaQuery.of(context).size.width / 3),
child: Text(
reply.title,
style: quickReplyTextStyle != null
? quickReplyTextStyle
: TextStyle(
color: Theme.of(context).accentColor,
fontSize: 12.0,
),
),
),
);
}
}
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.2
version: 0.1.3
author:
homepage:

Expand Down

0 comments on commit 8fd0ed2

Please sign in to comment.