Merge pull request #493 from pangeachat/red-text-on-max-length
Red text on max length
This commit is contained in:
commit
e8bce1289e
3 changed files with 27 additions and 1 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue