Only rebuild when maxLength changes
This commit is contained in:
parent
08da254bae
commit
828b406286
2 changed files with 14 additions and 6 deletions
|
|
@ -21,6 +21,7 @@ class InputBar extends StatelessWidget {
|
|||
final ValueChanged<Uint8List?>? 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,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -61,8 +61,7 @@ class InputBarWrapperState extends State<InputBarWrapper> {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
void refreshOnChange(String text) {
|
||||
widget.onChanged!(text);
|
||||
void refreshOnChange() {
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +77,8 @@ class InputBarWrapperState extends State<InputBarWrapper> {
|
|||
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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue