diff --git a/packages/flet/lib/src/controls/textfield.dart b/packages/flet/lib/src/controls/textfield.dart index ecd59d522..7e8e2764d 100644 --- a/packages/flet/lib/src/controls/textfield.dart +++ b/packages/flet/lib/src/controls/textfield.dart @@ -208,6 +208,8 @@ class _TextFieldControlState extends State } var fitParentSize = widget.control.attrBool("fitParentSize", false)!; + var maxLength = widget.control.attrInt("maxLength"); + Widget textField = TextFormField( style: textStyle, autofocus: autofocus, @@ -234,6 +236,8 @@ class _TextFieldControlState extends State helper: helperCtrl.isNotEmpty ? helperCtrl.first : null, label: labelCtrl.isNotEmpty ? labelCtrl.first : null, customSuffix: revealPasswordIcon, + valueLength: _value.length, + maxLength: maxLength, focused: _focused, disabled: disabled, adaptive: adaptive), @@ -261,7 +265,7 @@ class _TextFieldControlState extends State widget.control.attrString("textAlign"), TextAlign.start)!, minLines: fitParentSize ? null : minLines, maxLines: fitParentSize ? null : maxLines, - maxLength: widget.control.attrInt("maxLength"), + maxLength: maxLength, readOnly: widget.control.attrBool("readOnly", false)!, inputFormatters: inputFormatters.isNotEmpty ? inputFormatters : null, obscureText: password && !_revealPassword, diff --git a/packages/flet/lib/src/utils/form_field.dart b/packages/flet/lib/src/utils/form_field.dart index f29d5a8e6..720dc5816 100644 --- a/packages/flet/lib/src/utils/form_field.dart +++ b/packages/flet/lib/src/utils/form_field.dart @@ -66,6 +66,8 @@ InputDecoration buildInputDecoration(BuildContext context, Control control, Control? helper, Control? label, Widget? customSuffix, + int? valueLength, + int? maxLength, bool focused = false, bool disabled = false, bool? adaptive}) { @@ -98,6 +100,13 @@ InputDecoration buildInputDecoration(BuildContext context, Control control, var borderWidth = control.attrDouble("borderWidth"); var focusedBorderWidth = control.attrDouble("focusedBorderWidth"); + var counterText = control + .attrString("counterText", "") + ?.replaceAll("{value_length}", valueLength.toString()) + .replaceAll("{max_length}", maxLength?.toString() ?? "None") + .replaceAll("{symbols_left}", + "${maxLength == null ? 'None' : (maxLength - (valueLength ?? 0))}"); + InputBorder? border; if (inputBorder == FormFieldInputBorder.underline) { border = const UnderlineInputBorder(); @@ -163,7 +172,7 @@ InputDecoration buildInputDecoration(BuildContext context, Control control, hintStyle: parseTextStyle(Theme.of(context), control, "hintStyle"), helperText: control.attrString("helperText"), helperStyle: parseTextStyle(Theme.of(context), control, "helperStyle"), - counterText: control.attrString("counterText"), + counterText: counterText, counterStyle: parseTextStyle(Theme.of(context), control, "counterStyle"), counter: counter != null ? createControl(control, counter.id, control.isDisabled, diff --git a/sdk/python/packages/flet/src/flet/core/dropdown.py b/sdk/python/packages/flet/src/flet/core/dropdown.py index 42fff77ad..ac75ae363 100644 --- a/sdk/python/packages/flet/src/flet/core/dropdown.py +++ b/sdk/python/packages/flet/src/flet/core/dropdown.py @@ -362,6 +362,7 @@ def __init__( self.max_menu_height = max_menu_height self.select_icon_size = select_icon_size or icon_size self.select_icon_enabled_color = select_icon_enabled_color or icon_enabled_color + self.icon_disabled_color = icon_disabled_color self.select_icon_disabled_color = ( select_icon_disabled_color or icon_disabled_color )