From 6311df08756d919cf50fd9707e83133b7db5492b Mon Sep 17 00:00:00 2001 From: ggurdin Date: Thu, 25 Jul 2024 11:25:59 -0400 Subject: [PATCH] moved stateful variable from text controller to input bar wrapper widget --- lib/pages/chat/input_bar.dart | 3 --- lib/pangea/widgets/chat/input_bar_wrapper.dart | 13 +++++++++++-- lib/pangea/widgets/igc/pangea_text_controller.dart | 3 +-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index 54dba8674..84a802e54 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -401,9 +401,6 @@ class InputBar extends StatelessWidget { @override Widget build(BuildContext context) { final useShortCuts = (AppConfig.sendOnEnter ?? !PlatformInfos.isMobile); - // #Pangea - controller?.currentlyMaxLength = controller?.isMaxLength ?? false; - // Pangea# return Shortcuts( shortcuts: !useShortCuts ? {} diff --git a/lib/pangea/widgets/chat/input_bar_wrapper.dart b/lib/pangea/widgets/chat/input_bar_wrapper.dart index 1e8cd4727..9441312bd 100644 --- a/lib/pangea/widgets/chat/input_bar_wrapper.dart +++ b/lib/pangea/widgets/chat/input_bar_wrapper.dart @@ -44,6 +44,7 @@ class InputBarWrapper extends StatefulWidget { class InputBarWrapperState extends State { StreamSubscription? _choreoSub; + String _currentText = ''; @override void initState() { @@ -65,10 +66,18 @@ class InputBarWrapperState extends State { if (widget.onChanged != null) { widget.onChanged!(text); } - if (widget.controller?.currentlyMaxLength != - widget.controller?.isMaxLength) { + + final bool decreasedFromMaxLength = + _currentText.length >= PangeaTextController.maxLength && + text.length < PangeaTextController.maxLength; + final bool reachedMaxLength = + _currentText.length < PangeaTextController.maxLength && + text.length < PangeaTextController.maxLength; + + if (decreasedFromMaxLength || reachedMaxLength) { setState(() {}); } + _currentText = text; } @override diff --git a/lib/pangea/widgets/igc/pangea_text_controller.dart b/lib/pangea/widgets/igc/pangea_text_controller.dart index d7f24a7e2..8fc136edd 100644 --- a/lib/pangea/widgets/igc/pangea_text_controller.dart +++ b/lib/pangea/widgets/igc/pangea_text_controller.dart @@ -26,10 +26,9 @@ class PangeaTextController extends TextEditingController { this.text = text; } + static const int maxLength = 1000; bool get isMaxLength => text.length == 1000; - bool currentlyMaxLength = false; - bool forceKeepOpen = false; setSystemText(String text, EditType type) {