Move calculations to state
This commit is contained in:
parent
b63e383802
commit
8c1df0eb88
3 changed files with 18 additions and 13 deletions
|
|
@ -21,7 +21,6 @@ class InputBar extends StatelessWidget {
|
|||
final ValueChanged<Uint8List?>? onSubmitImage;
|
||||
final FocusNode? focusNode;
|
||||
// #Pangea
|
||||
final Function? updateBar;
|
||||
// final TextEditingController? controller;
|
||||
final PangeaTextController? controller;
|
||||
// Pangea#
|
||||
|
|
@ -39,7 +38,6 @@ class InputBar extends StatelessWidget {
|
|||
this.onSubmitImage,
|
||||
this.focusNode,
|
||||
this.controller,
|
||||
this.updateBar,
|
||||
this.decoration,
|
||||
this.onChanged,
|
||||
this.autofocus,
|
||||
|
|
@ -404,7 +402,7 @@ class InputBar extends StatelessWidget {
|
|||
Widget build(BuildContext context) {
|
||||
final useShortCuts = (AppConfig.sendOnEnter ?? !PlatformInfos.isMobile);
|
||||
// #Pangea
|
||||
final bool maxLength = controller?.text.length == 1000;
|
||||
controller?.currentlyMaxLength = controller?.isMaxLength ?? false;
|
||||
// Pangea#
|
||||
return Shortcuts(
|
||||
shortcuts: !useShortCuts
|
||||
|
|
@ -509,7 +507,9 @@ class InputBar extends StatelessWidget {
|
|||
onSubmitted!(text);
|
||||
},
|
||||
// #Pangea
|
||||
style: maxLength ? const TextStyle(color: Colors.red) : null,
|
||||
style: controller?.isMaxLength ?? false
|
||||
? const TextStyle(color: Colors.red)
|
||||
: null,
|
||||
onTap: () {
|
||||
controller!.onInputTap(
|
||||
context,
|
||||
|
|
@ -522,11 +522,6 @@ 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,14 @@ class InputBarWrapperState extends State<InputBarWrapper> {
|
|||
super.dispose();
|
||||
}
|
||||
|
||||
void refreshOnChange() {
|
||||
setState(() {});
|
||||
void refreshOnChange(String text) {
|
||||
if (widget.onChanged != null) {
|
||||
widget.onChanged!(text);
|
||||
}
|
||||
if (widget.controller?.currentlyMaxLength !=
|
||||
widget.controller?.isMaxLength) {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -77,8 +83,7 @@ class InputBarWrapperState extends State<InputBarWrapper> {
|
|||
focusNode: widget.focusNode,
|
||||
controller: widget.controller,
|
||||
decoration: widget.decoration,
|
||||
updateBar: refreshOnChange,
|
||||
onChanged: widget.onChanged,
|
||||
onChanged: refreshOnChange,
|
||||
autofocus: widget.autofocus,
|
||||
textInputAction: widget.textInputAction,
|
||||
readOnly: widget.readOnly,
|
||||
|
|
|
|||
|
|
@ -25,6 +25,11 @@ class PangeaTextController extends TextEditingController {
|
|||
text ??= '';
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
bool get isMaxLength => text.length == 1000;
|
||||
|
||||
bool currentlyMaxLength = false;
|
||||
|
||||
bool forceKeepOpen = false;
|
||||
|
||||
setSystemText(String text, EditType type) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue