From dc7a436e96730405621e659a70d9ffbd23c2362b Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Tue, 24 Nov 2020 17:59:33 +0100 Subject: [PATCH] align with master --- example/ios/Podfile.lock | 2 +- example/pubspec.yaml | 2 +- lib/src/message_input.dart | 38 ++++++++++++++++++++++++-------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 131e8aec..29b026b2 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -284,4 +284,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: eb001256612a59f8f9e4d083ad8b9671e69dd184 -COCOAPODS: 1.10.0.rc.1 +COCOAPODS: 1.10.0 diff --git a/example/pubspec.yaml b/example/pubspec.yaml index dab13883..43eb867e 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -1,6 +1,6 @@ name: example description: A new Flutter project. -version: 1.0.71+73 +version: 1.0.72+74 environment: sdk: ">=2.2.2 <3.0.0" diff --git a/lib/src/message_input.dart b/lib/src/message_input.dart index 4b634ab7..b4c79033 100644 --- a/lib/src/message_input.dart +++ b/lib/src/message_input.dart @@ -428,26 +428,36 @@ class MessageInputState extends State { ); } + Timer _debounce; void _onChanged(BuildContext context, String s) { - StreamChannel.of(context).channel.keyStroke().catchError((e) {}); + if (_debounce?.isActive == true) _debounce.cancel(); + _debounce = Timer( + const Duration(milliseconds: 350), + () { + if (!mounted) { + return; + } + StreamChannel.of(context).channel.keyStroke().catchError((e) {}); - setState(() { - _messageIsPresent = s.trim().isNotEmpty; - _actionsShrunk = s.trim().isNotEmpty; - }); + setState(() { + _messageIsPresent = s.trim().isNotEmpty; + _actionsShrunk = s.trim().isNotEmpty; + }); - _commandsOverlay?.remove(); - _commandsOverlay = null; - _mentionsOverlay?.remove(); - _mentionsOverlay = null; - _emojiOverlay?.remove(); - _emojiOverlay = null; + _commandsOverlay?.remove(); + _commandsOverlay = null; + _mentionsOverlay?.remove(); + _mentionsOverlay = null; + _emojiOverlay?.remove(); + _emojiOverlay = null; - _checkCommands(s.trim(), context); + _checkCommands(s.trim(), context); - _checkMentions(s, context); + _checkMentions(s, context); - _checkEmoji(s, context); + _checkEmoji(s, context); + }, + ); } String _getHint() {