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
+32 -14
View File
@@ -290,8 +290,24 @@ class MessageInputState extends State<MessageInput> {
_mentionsOverlay = null; _mentionsOverlay = null;
if (s.startsWith('/')) { if (s.startsWith('/')) {
_commandsOverlay = _buildCommandsOverlayEntry(); var matchedCommandsList = StreamChannel.of(context)
Overlay.of(context).insert(_commandsOverlay); .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();
Overlay.of(context).insert(_commandsOverlay);
}
} }
if (textEditingController.selection.isCollapsed && if (textEditingController.selection.isCollapsed &&
@@ -440,19 +456,21 @@ class MessageInputState extends State<MessageInput> {
padding: const EdgeInsets.all(0), padding: const EdgeInsets.all(0),
shrinkWrap: true, shrinkWrap: true,
children: [ children: [
Padding( if (commands.isNotEmpty)
padding: const EdgeInsets.only(left: 8.0, top: 8.0), Padding(
child: Row( padding: const EdgeInsets.only(left: 8.0, top: 8.0),
children: [ child: Row(
Padding( children: [
padding: const EdgeInsets.symmetric(horizontal: 8.0), Padding(
child: Icon(StreamIcons.lightning, padding:
color: StreamChatTheme.of(context).accentColor), const EdgeInsets.symmetric(horizontal: 8.0),
), child: Icon(StreamIcons.lightning,
Text('Instant Commands') color: StreamChatTheme.of(context).accentColor),
], ),
Text('Instant Commands')
],
),
), ),
),
...commands ...commands
.map( .map(
(c) => ListTile( (c) => ListTile(