Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement TextField.counter property #3676

Merged
merged 2 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .github/ISSUE_TEMPLATE/01_bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ body:
attributes:
label: "Describe the bug"
description: "A clear and concise description of the bug."
placeholder: Tell us what you see.
placeholder: Tell us in details what you see.
validations:
required: true
- type: textarea
Expand All @@ -41,7 +41,7 @@ body:
Note: Please do not upload screenshots of text. Instead, use code blocks
or the above mentioned ways to upload your code sample.
value: |
<details open><summary>Logs</summary>
<details open><summary>Code</summary>

```python
[Paste your code here]
Expand Down Expand Up @@ -73,7 +73,7 @@ body:
description: "One image is worth a thousand words. If you can, please provide screenshots or videos to help visually explain your issue."
value: |
<details open>
<summary>Screenshots / Video demonstration</summary>
<summary>Captures</summary>

[Upload media here]

Expand Down Expand Up @@ -155,5 +155,3 @@ body:
description: "Add any other detail about the issue here. Ex: happens only on specific conditions, etc."
validations:
required: false


23 changes: 14 additions & 9 deletions packages/flet/lib/src/controls/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class _DropdownControlState extends State<DropdownControl> with FletStoreMixin {
.where((c) => c.control.name == "prefix" && c.control.isVisible);
var suffixControls = itemsView.controlViews
.where((c) => c.control.name == "suffix" && c.control.isVisible);
var counterControls = itemsView.controlViews
.where((c) => c.control.name == "counter" && c.control.isVisible);

var focusValue = widget.control.attrString("focus");
if (focusValue != null && focusValue != _lastFocusValue) {
Expand Down Expand Up @@ -179,15 +181,18 @@ class _DropdownControlState extends State<DropdownControl> with FletStoreMixin {
hint: iconCtrl.isNotEmpty
? createControl(widget.control, hintCtrl.first.id, disabled)
: null,
decoration: buildInputDecoration(
context,
widget.control,
prefixControls.isNotEmpty ? prefixControls.first.control : null,
suffixControls.isNotEmpty ? suffixControls.first.control : null,
null,
_focused,
disabled,
widget.parentAdaptive),
decoration: buildInputDecoration(context, widget.control,
prefix:
prefixControls.isNotEmpty ? prefixControls.first.control : null,
suffix:
suffixControls.isNotEmpty ? suffixControls.first.control : null,
counter: counterControls.isNotEmpty
? counterControls.first.control
: null,
customSuffix: null,
focused: _focused,
disabled: disabled,
adaptive: widget.parentAdaptive),
onTap: !disabled
? () {
widget.backend.triggerControlEvent(widget.control.id, "click");
Expand Down
20 changes: 11 additions & 9 deletions packages/flet/lib/src/controls/textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ class _TextFieldControlState extends State<TextFieldControl>
widget.children.where((c) => c.name == "prefix" && c.isVisible);
var suffixControls =
widget.children.where((c) => c.name == "suffix" && c.isVisible);
var counterControls =
widget.children.where((c) => c.name == "counter" && c.isVisible);

bool shiftEnter = widget.control.attrBool("shiftEnter", false)!;
bool multiline =
Expand Down Expand Up @@ -220,15 +222,15 @@ class _TextFieldControlState extends State<TextFieldControl>
.triggerControlEvent(widget.control.id, "submit", value);
}
: null,
decoration: buildInputDecoration(
context,
widget.control,
prefixControls.isNotEmpty ? prefixControls.first : null,
suffixControls.isNotEmpty ? suffixControls.first : null,
revealPasswordIcon,
_focused,
disabled,
adaptive),
decoration: buildInputDecoration(context, widget.control,
prefix: prefixControls.isNotEmpty ? prefixControls.first : null,
suffix: suffixControls.isNotEmpty ? suffixControls.first : null,
counter:
counterControls.isNotEmpty ? counterControls.first : null,
customSuffix: revealPasswordIcon,
focused: _focused,
disabled: disabled,
adaptive: adaptive),
showCursor: widget.control.attrBool("showCursor"),
textAlignVertical: textVerticalAlign != null
? TextAlignVertical(y: textVerticalAlign)
Expand Down
13 changes: 9 additions & 4 deletions packages/flet/lib/src/utils/form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ TextInputType? parseTextInputType(String? value, [TextInputType? defValue]) {
InputDecoration buildInputDecoration(
BuildContext context,
Control control,
Control? prefix,
{Control? prefix,
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
Control? suffix,
Control? counter,
Widget? customSuffix,
bool focused,
bool disabled,
bool? adaptive) {
bool focused = false,
bool disabled = false,
bool? adaptive}) {
String? label = control.attrString("label", "")!;
FormFieldInputBorder inputBorder = parseFormFieldInputBorder(
control.attrString("border"),
Expand Down Expand Up @@ -141,6 +142,10 @@ InputDecoration buildInputDecoration(
helperStyle: parseTextStyle(Theme.of(context), control, "helperStyle"),
counterText: control.attrString("counterText"),
counterStyle: parseTextStyle(Theme.of(context), control, "counterStyle"),
counter: counter != null
? createControl(control, counter.id, control.isDisabled,
parentAdaptive: adaptive)
: null,
errorText: control.attrString("errorText"),
errorStyle: parseTextStyle(Theme.of(context), control, "errorStyle"),
prefixIcon: prefixIcon != null ? Icon(prefixIcon) : null,
Expand Down
2 changes: 2 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/dropdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def __init__(
hint_style: Optional[TextStyle] = None,
helper_text: Optional[str] = None,
helper_style: Optional[TextStyle] = None,
counter: Optional[Control] = None,
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
counter_text: Optional[str] = None,
counter_style: Optional[TextStyle] = None,
error_text: Optional[str] = None,
Expand Down Expand Up @@ -287,6 +288,7 @@ def __init__(
hint_style=hint_style,
helper_text=helper_text,
helper_style=helper_style,
counter=counter,
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
counter_text=counter_text,
counter_style=counter_style,
error_text=error_text,
Expand Down
14 changes: 14 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/form_field_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(
hint_style: Optional[TextStyle] = None,
helper_text: Optional[str] = None,
helper_style: Optional[TextStyle] = None,
counter: Optional[Control] = None,
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
counter_text: Optional[str] = None,
counter_style: Optional[TextStyle] = None,
error_text: Optional[str] = None,
Expand Down Expand Up @@ -156,6 +157,7 @@ def __init__(
self.hint_style = hint_style
self.helper_text = helper_text
self.helper_style = helper_style
self.counter = counter
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
self.counter_text = counter_text
self.counter_style = counter_style
self.error_text = error_text
Expand Down Expand Up @@ -192,6 +194,9 @@ def _get_children(self):
if isinstance(self.__suffix, Control):
self.__suffix._set_attr_internal("n", "suffix")
children.append(self.__suffix)
if isinstance(self.__counter, Control):
self.__counter._set_attr_internal("n", "counter")
children.append(self.__counter)
return children

# text_size
Expand Down Expand Up @@ -450,6 +455,15 @@ def prefix(self) -> Optional[Control]:
def prefix(self, value: Optional[Control]):
self.__prefix = value

# counter
@property
def counter(self) -> Optional[Control]:
return self.__counter

@counter.setter
def counter(self, value: Optional[Control]):
self.__counter = value

# prefix_icon
@property
def prefix_icon(self) -> Optional[str]:
Expand Down
2 changes: 2 additions & 0 deletions sdk/python/packages/flet-core/src/flet_core/textfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def __init__(
hint_style: Optional[TextStyle] = None,
helper_text: Optional[str] = None,
helper_style: Optional[TextStyle] = None,
counter: Optional[Control] = None,
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
counter_text: Optional[str] = None,
counter_style: Optional[TextStyle] = None,
error_text: Optional[str] = None,
Expand Down Expand Up @@ -251,6 +252,7 @@ def __init__(
hint_style=hint_style,
helper_text=helper_text,
helper_style=helper_style,
counter=counter,
ndonkoHenri marked this conversation as resolved.
Show resolved Hide resolved
counter_text=counter_text,
counter_style=counter_style,
error_text=error_text,
Expand Down