feat: Auto chip when command entered

This commit is contained in:
Deven Joshi
2020-10-27 11:52:11 +05:30
parent 64937ffb37
commit 41e75ca9cd
+19 -1
View File
@@ -290,9 +290,25 @@ class MessageInputState extends State<MessageInput> {
_mentionsOverlay = null; _mentionsOverlay = null;
if (s.startsWith('/')) { if (s.startsWith('/')) {
var matchedCommandsList = StreamChannel.of(context)
.channel
.config
.commands.where((element) => element.name == s.substring(1)).toList();
if(matchedCommandsList.length == 1) {
_chosenCommand = matchedCommandsList[0];
textEditingController.clear();
_typingStarted = false;
setState(() {
_commandEnabled = true;
});
_commandsOverlay.remove();
_commandsOverlay = null;
} else {
_commandsOverlay = _buildCommandsOverlayEntry(); _commandsOverlay = _buildCommandsOverlayEntry();
Overlay.of(context).insert(_commandsOverlay); Overlay.of(context).insert(_commandsOverlay);
} }
}
if (textEditingController.selection.isCollapsed && if (textEditingController.selection.isCollapsed &&
(s[textEditingController.selection.start - 1] == '@' || (s[textEditingController.selection.start - 1] == '@' ||
@@ -440,12 +456,14 @@ class MessageInputState extends State<MessageInput> {
padding: const EdgeInsets.all(0), padding: const EdgeInsets.all(0),
shrinkWrap: true, shrinkWrap: true,
children: [ children: [
if (commands.isNotEmpty)
Padding( Padding(
padding: const EdgeInsets.only(left: 8.0, top: 8.0), padding: const EdgeInsets.only(left: 8.0, top: 8.0),
child: Row( child: Row(
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0), padding:
const EdgeInsets.symmetric(horizontal: 8.0),
child: Icon(StreamIcons.lightning, child: Icon(StreamIcons.lightning,
color: StreamChatTheme.of(context).accentColor), color: StreamChatTheme.of(context).accentColor),
), ),