Merge pull request #493 from pangeachat/red-text-on-max-length

Red text on max length
This commit is contained in:
ggurdin 2024-07-25 11:26:48 -04:00 committed by GitHub
commit e8bce1289e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 1 deletions

View file

@ -504,6 +504,9 @@ class InputBar extends StatelessWidget {
onSubmitted!(text);
},
// #Pangea
style: controller?.isMaxLength ?? false
? const TextStyle(color: Colors.red)
: null,
onTap: () {
controller!.onInputTap(
context,

View file

@ -44,6 +44,7 @@ class InputBarWrapper extends StatefulWidget {
class InputBarWrapperState extends State<InputBarWrapper> {
StreamSubscription? _choreoSub;
String _currentText = '';
@override
void initState() {
@ -61,6 +62,24 @@ class InputBarWrapperState extends State<InputBarWrapper> {
super.dispose();
}
void refreshOnChange(String text) {
if (widget.onChanged != null) {
widget.onChanged!(text);
}
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
Widget build(BuildContext context) {
return InputBar(
@ -73,7 +92,7 @@ class InputBarWrapperState extends State<InputBarWrapper> {
focusNode: widget.focusNode,
controller: widget.controller,
decoration: widget.decoration,
onChanged: widget.onChanged,
onChanged: refreshOnChange,
autofocus: widget.autofocus,
textInputAction: widget.textInputAction,
readOnly: widget.readOnly,

View file

@ -25,6 +25,10 @@ class PangeaTextController extends TextEditingController {
text ??= '';
this.text = text;
}
static const int maxLength = 1000;
bool get isMaxLength => text.length == 1000;
bool forceKeepOpen = false;
setSystemText(String text, EditType type) {