feat: Added message reply

This commit is contained in:
Deven Joshi
2021-01-20 16:21:03 +05:30
parent ded8b37e61
commit d48ccf15df
8 changed files with 84 additions and 26 deletions
@@ -10,6 +10,8 @@ import 'stream_channel.dart';
import '../stream_chat_flutter.dart'; import '../stream_chat_flutter.dart';
enum ReturnActionType { none, reply }
typedef ShowMessageCallback = void Function(Message message, Channel channel); typedef ShowMessageCallback = void Function(Message message, Channel channel);
/// A full screen image widget /// A full screen image widget
@@ -13,6 +13,7 @@ class GiphyAttachment extends StatelessWidget {
final Message message; final Message message;
final Size size; final Size size;
final ShowMessageCallback onShowMessage; final ShowMessageCallback onShowMessage;
final ValueChanged<ReturnActionType> onReturnAction;
const GiphyAttachment({ const GiphyAttachment({
Key key, Key key,
@@ -21,6 +22,7 @@ class GiphyAttachment extends StatelessWidget {
this.message, this.message,
this.size, this.size,
this.onShowMessage, this.onShowMessage,
this.onReturnAction,
}) : super(key: key); }) : super(key: key);
@override @override
@@ -65,8 +67,9 @@ class GiphyAttachment extends StatelessWidget {
Padding( Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () async {
Navigator.push(context, MaterialPageRoute(builder: (_) { var res = await Navigator.push(context,
MaterialPageRoute(builder: (_) {
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
return StreamChannel( return StreamChannel(
@@ -82,6 +85,10 @@ class GiphyAttachment extends StatelessWidget {
), ),
); );
})); }));
if (res != null) {
onReturnAction(res);
}
}, },
child: ClipRRect( child: ClipRRect(
borderRadius: BorderRadius.only( borderRadius: BorderRadius.only(
@@ -320,8 +327,9 @@ class GiphyAttachment extends StatelessWidget {
Widget _buildSentAttachment(context) { Widget _buildSentAttachment(context) {
return Container( return Container(
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () async {
Navigator.push(context, MaterialPageRoute(builder: (_) { var res =
await Navigator.push(context, MaterialPageRoute(builder: (_) {
var channel = StreamChannel.of(context).channel; var channel = StreamChannel.of(context).channel;
return StreamChannel( return StreamChannel(
@@ -337,6 +345,10 @@ class GiphyAttachment extends StatelessWidget {
), ),
); );
})); }));
if (res != null) {
onReturnAction(res);
}
}, },
child: Stack( child: Stack(
children: [ children: [
@@ -60,7 +60,9 @@ class ImageActionsModal extends StatelessWidget {
size: 24.0, size: 24.0,
color: StreamChatTheme.of(context).colorTheme.grey, color: StreamChatTheme.of(context).colorTheme.grey,
), ),
() {}, () {
Navigator.pop(context, ReturnActionType.reply);
},
), ),
_buildButton( _buildButton(
context, context,
@@ -14,6 +14,7 @@ class ImageAttachment extends StatelessWidget {
final Size size; final Size size;
final bool showTitle; final bool showTitle;
final ShowMessageCallback onShowMessage; final ShowMessageCallback onShowMessage;
final ValueChanged<ReturnActionType> onReturnAction;
const ImageAttachment({ const ImageAttachment({
Key key, Key key,
@@ -23,6 +24,7 @@ class ImageAttachment extends StatelessWidget {
this.messageTheme, this.messageTheme,
this.showTitle = true, this.showTitle = true,
this.onShowMessage, this.onShowMessage,
this.onReturnAction,
}) : super(key: key); }) : super(key: key);
@override @override
@@ -42,8 +44,8 @@ class ImageAttachment extends StatelessWidget {
children: <Widget>[ children: <Widget>[
Expanded( Expanded(
child: GestureDetector( child: GestureDetector(
onTap: () { onTap: () async {
Navigator.push( var result = await Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (_) { builder: (_) {
@@ -64,6 +66,10 @@ class ImageAttachment extends StatelessWidget {
}, },
), ),
); );
if (result != null) {
onReturnAction(result);
}
}, },
child: CachedNetworkImage( child: CachedNetworkImage(
height: size?.height, height: size?.height,
@@ -101,24 +101,29 @@ class ImageHeader extends StatelessWidget implements PreferredSizeWidget {
@override @override
final Size preferredSize; final Size preferredSize;
void _showMessageActionModalBottomSheet(BuildContext context) { void _showMessageActionModalBottomSheet(BuildContext context) async {
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
showDialog( var result = await showDialog(
context: context, context: context,
barrierColor: StreamChatTheme.of(context).colorTheme.overlay, barrierColor: StreamChatTheme.of(context).colorTheme.overlay,
builder: (context) { builder: (context) {
return StreamChannel( return StreamChannel(
channel: channel, channel: channel,
child: ImageActionsModal( child: ImageActionsModal(
userName: userName, userName: userName,
sentAt: sentAt, sentAt: sentAt,
message: message, message: message,
urls: urls, urls: urls,
currentIndex: currentIndex, currentIndex: currentIndex,
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
), ),
); );
}); },
);
if (result != null) {
Navigator.pop(context, result);
}
} }
} }
@@ -780,6 +780,16 @@ class _MessageListViewState extends State<MessageListView> {
? StreamChatTheme.of(context).ownMessageTheme ? StreamChatTheme.of(context).ownMessageTheme
: StreamChatTheme.of(context).otherMessageTheme, : StreamChatTheme.of(context).otherMessageTheme,
onShowMessage: widget.onShowMessage, onShowMessage: widget.onShowMessage,
onReturnAction: (action) {
switch (action) {
case ReturnActionType.none:
break;
case ReturnActionType.reply:
FocusScope.of(context).unfocus();
widget.onMessageSwiped(message);
break;
}
},
); );
} }
@@ -930,6 +940,16 @@ class _MessageListViewState extends State<MessageListView> {
readList: readList, readList: readList,
allRead: allRead, allRead: allRead,
onShowMessage: widget.onShowMessage, onShowMessage: widget.onShowMessage,
onReturnAction: (action) {
switch (action) {
case ReturnActionType.none:
break;
case ReturnActionType.reply:
FocusScope.of(context).unfocus();
widget.onMessageSwiped(message);
break;
}
},
); );
if (!message.isDeleted && !message.isSystem && !message.isEphemeral) { if (!message.isDeleted && !message.isSystem && !message.isEphemeral) {
@@ -120,6 +120,7 @@ class MessageWidget extends StatefulWidget {
final List<Read> readList; final List<Read> readList;
final ShowMessageCallback onShowMessage; final ShowMessageCallback onShowMessage;
final ValueChanged<ReturnActionType> onReturnAction;
/// If true show the users username next to the timestamp of the message /// If true show the users username next to the timestamp of the message
final bool showUsername; final bool showUsername;
@@ -178,6 +179,7 @@ class MessageWidget extends StatefulWidget {
this.onShowMessage, this.onShowMessage,
this.editMessageInputBuilder, this.editMessageInputBuilder,
this.textBuilder, this.textBuilder,
this.onReturnAction,
Map<String, AttachmentBuilder> customAttachmentBuilders, Map<String, AttachmentBuilder> customAttachmentBuilders,
this.readList, this.readList,
this.padding, this.padding,
@@ -199,6 +201,7 @@ class MessageWidget extends StatefulWidget {
MediaQuery.of(context).size.height * 0.3, MediaQuery.of(context).size.height * 0.3,
), ),
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
onReturnAction: onReturnAction,
); );
}, },
'video': (context, message, attachment) { 'video': (context, message, attachment) {
@@ -211,6 +214,7 @@ class MessageWidget extends StatefulWidget {
), ),
message: message, message: message,
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
onReturnAction: onReturnAction,
); );
}, },
'giphy': (context, message, attachment) { 'giphy': (context, message, attachment) {
@@ -223,6 +227,7 @@ class MessageWidget extends StatefulWidget {
MediaQuery.of(context).size.height * 0.3, MediaQuery.of(context).size.height * 0.3,
), ),
onShowMessage: onShowMessage, onShowMessage: onShowMessage,
onReturnAction: onReturnAction,
); );
}, },
'file': (context, message, attachment) { 'file': (context, message, attachment) {
@@ -15,6 +15,7 @@ class VideoAttachment extends StatefulWidget {
final Size size; final Size size;
final Message message; final Message message;
final ShowMessageCallback onShowMessage; final ShowMessageCallback onShowMessage;
final ValueChanged<ReturnActionType> onReturnAction;
VideoAttachment({ VideoAttachment({
Key key, Key key,
@@ -23,6 +24,7 @@ class VideoAttachment extends StatefulWidget {
this.message, this.message,
this.size, this.size,
this.onShowMessage, this.onShowMessage,
this.onReturnAction,
}) : super(key: key); }) : super(key: key);
@override @override
@@ -84,10 +86,10 @@ class _VideoAttachmentState extends State<VideoAttachment> {
}); });
return GestureDetector( return GestureDetector(
onTap: () { onTap: () async {
final channel = StreamChannel.of(context).channel; final channel = StreamChannel.of(context).channel;
Navigator.push( var res = await Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (_) => StreamChannel( builder: (_) => StreamChannel(
@@ -102,6 +104,10 @@ class _VideoAttachmentState extends State<VideoAttachment> {
), ),
), ),
); );
if (res != null) {
widget.onReturnAction(res);
}
}, },
child: Container( child: Container(
height: widget.size?.height, height: widget.size?.height,