From 828b406286926f622cac999e70d345687d24c95c Mon Sep 17 00:00:00 2001 From: Kelrap Date: Mon, 22 Jul 2024 10:04:18 -0400 Subject: [PATCH] Only rebuild when maxLength changes --- lib/pages/chat/input_bar.dart | 14 +++++++++++--- lib/pangea/widgets/chat/input_bar_wrapper.dart | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/pages/chat/input_bar.dart b/lib/pages/chat/input_bar.dart index 0d2251203..4ffde1f42 100644 --- a/lib/pages/chat/input_bar.dart +++ b/lib/pages/chat/input_bar.dart @@ -21,6 +21,7 @@ class InputBar extends StatelessWidget { final ValueChanged? onSubmitImage; final FocusNode? focusNode; // #Pangea + final Function? updateBar; // final TextEditingController? controller; final PangeaTextController? controller; // Pangea# @@ -38,6 +39,7 @@ class InputBar extends StatelessWidget { this.onSubmitImage, this.focusNode, this.controller, + this.updateBar, this.decoration, this.onChanged, this.autofocus, @@ -401,6 +403,9 @@ class InputBar extends StatelessWidget { @override Widget build(BuildContext context) { final useShortCuts = (AppConfig.sendOnEnter ?? !PlatformInfos.isMobile); + // #Pangea + final bool maxLength = controller?.text.length == 1000; + // Pangea# return Shortcuts( shortcuts: !useShortCuts ? {} @@ -504,9 +509,7 @@ class InputBar extends StatelessWidget { onSubmitted!(text); }, // #Pangea - style: controller?.text.length == 1000 - ? const TextStyle(color: Colors.red) - : null, + style: maxLength ? const TextStyle(color: Colors.red) : null, onTap: () { controller!.onInputTap( context, @@ -519,6 +522,11 @@ class InputBar extends StatelessWidget { // fix for the library for now // it sets the types for the callback incorrectly onChanged!(text); + // #Pangea + if (maxLength != (controller?.text.length == 1000)) { + updateBar!(); + } + // Pangea# }, textCapitalization: TextCapitalization.sentences, ), diff --git a/lib/pangea/widgets/chat/input_bar_wrapper.dart b/lib/pangea/widgets/chat/input_bar_wrapper.dart index 5f6c1b49b..5aa813bbe 100644 --- a/lib/pangea/widgets/chat/input_bar_wrapper.dart +++ b/lib/pangea/widgets/chat/input_bar_wrapper.dart @@ -61,8 +61,7 @@ class InputBarWrapperState extends State { super.dispose(); } - void refreshOnChange(String text) { - widget.onChanged!(text); + void refreshOnChange() { setState(() {}); } @@ -78,7 +77,8 @@ class InputBarWrapperState extends State { focusNode: widget.focusNode, controller: widget.controller, decoration: widget.decoration, - onChanged: widget.onChanged != null ? refreshOnChange : null, + updateBar: refreshOnChange, + onChanged: widget.onChanged, autofocus: widget.autofocus, textInputAction: widget.textInputAction, readOnly: widget.readOnly,