feat: Control and listen to selection/caret changes in TextField#5725
Merged
FeodorFitsner merged 9 commits intomainfrom Oct 24, 2025
Merged
feat: Control and listen to selection/caret changes in TextField#5725FeodorFitsner merged 9 commits intomainfrom
TextField#5725FeodorFitsner merged 9 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds text selection control and monitoring capabilities to TextField and CupertinoTextField components. Users can now programmatically control text selection/caret position and listen to selection change events through a new on_selection_change callback.
Key Changes
- Introduced
TextSelectionclass withbase_offset/extent_offsetproperties to represent text selections - Added
on_selection_changeevent handler to TextField/CupertinoTextField for monitoring selection changes - Added
selectionproperty to TextField for programmatic control of text selection and caret position
Reviewed Changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/python/packages/flet/src/flet/controls/material/textfield.py | Added selection property and on_selection_change event handler to TextField |
| sdk/python/packages/flet/src/flet/controls/material/form_field_control.py | Added documentation for the focus() method |
| sdk/python/packages/flet/src/flet/controls/core/text.py | Refactored TextSelection to use base_offset/extent_offset as required fields with computed properties; updated TextSelectionChangeEvent structure |
| sdk/python/packages/flet/mkdocs.yml | Enabled show_labels in documentation configuration |
| sdk/python/packages/flet/docs/controls/textfield.md | Added example demonstrating selection change handling |
| sdk/python/packages/flet/docs/controls/cupertinotextfield.md | Added selection change and background image examples |
| sdk/python/packages/flet-map/src/flet_map/marker_layer.py | Fixed broken reference link in documentation |
| sdk/python/examples/controls/text_field/selection_change.py | New example demonstrating selection monitoring and control |
| sdk/python/examples/controls/cupertino_text_field/selection_change.py | New example for CupertinoTextField selection handling |
| sdk/python/examples/controls/cupertino_text_field/label_focus.py | Removed obsolete example file |
| packages/flet/lib/src/utils/text.dart | Added TextSelection parsing utilities and refactored switch statements to map lookups |
| packages/flet/lib/src/controls/textfield.dart | Implemented selection change tracking and programmatic selection control |
| packages/flet/lib/src/controls/text.dart | Updated event field name from "text" to "selected_text" |
| packages/flet/lib/src/controls/cupertino_textfield.dart | Implemented selection change tracking for CupertinoTextField |
| packages/flet/lib/src/controls/base_controls.dart | Refactored _sizedControl to properly handle AnimatedContainer with dimensions |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
sdk/python/packages/flet/src/flet/controls/material/textfield.py
Outdated
Show resolved
Hide resolved
sdk/python/examples/controls/cupertino_text_field/selection_change.py
Outdated
Show resolved
Hide resolved
Deploying flet-docs with
|
| Latest commit: |
fbdb83f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e0a3286e.flet-docs.pages.dev |
| Branch Preview URL: | https://textfield-text-selection.flet-docs.pages.dev |
This comment was marked as resolved.
This comment was marked as resolved.
FeodorFitsner
approved these changes
Oct 24, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #1005
Fix #1742
Fix #2916
Fix #5467
Fix #3335
Fix #5708
Example
Summary by Sourcery
Implement text selection and caret control in text fields across Dart and Python SDK, including new event triggers, property parsing, and updated utilities, plus docs and examples.
New Features:
selectionproperty andon_selection_changeevent to TextField and CupertinoTextField for programmatic control and listening to selection/caret changesEnhancements:
start,end,is_valid,is_collapsed,is_normalized, etc.) and implement parsing/serialization in DartgetTextStyle,getFontWeight) to use lookup mapsDocumentation:
show_labelsin mkdocs configuration