-
Notifications
You must be signed in to change notification settings - Fork 15
Add missing TextField attributes #87
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,9 @@ class LanguageToolTextField extends StatefulWidget { | |
| final ValueChanged<String>? onTextSubmitted; | ||
| final VoidCallback? onTap; | ||
| final TapRegionCallback? onTapOutside; | ||
| final TextCapitalization? textCapitalization; | ||
| final int? maxLength; | ||
| final Object? groupId; | ||
| final TextInputAction? textInputAction; | ||
| final TextInputType? keyboardType; | ||
| final Color? cursorColor; | ||
|
|
@@ -53,6 +56,9 @@ class LanguageToolTextField extends StatefulWidget { | |
| final bool readOnly; | ||
| final MouseCursor? mouseCursor; | ||
| final bool alignCenter; | ||
| final ScrollController? scrollController; | ||
| final bool? enabled; | ||
| final Widget? Function(BuildContext, { required int currentLength, required bool isFocused, required int? maxLength})? buildCounter; | ||
|
|
||
| /// Creates a widget that checks grammar errors. | ||
| const LanguageToolTextField({ | ||
|
|
@@ -63,6 +69,7 @@ class LanguageToolTextField extends StatefulWidget { | |
| this.mistakePopup, | ||
| this.maxLines = 1, | ||
| this.minLines, | ||
| this.maxLength, | ||
| this.expands = false, | ||
| this.textAlign = TextAlign.start, | ||
| this.textDirection, | ||
|
|
@@ -71,6 +78,11 @@ class LanguageToolTextField extends StatefulWidget { | |
| this.autoFocus = false, | ||
| this.readOnly = false, | ||
| this.textInputAction, | ||
| this.groupId, | ||
| this.enabled, | ||
| this.buildCounter, | ||
| this.scrollController, | ||
| this.textCapitalization, | ||
| this.keyboardType, | ||
| this.focusNode, | ||
| this.keyboardAppearance, | ||
|
|
@@ -89,7 +101,7 @@ class LanguageToolTextField extends StatefulWidget { | |
|
|
||
| class _LanguageToolTextFieldState extends State<LanguageToolTextField> { | ||
| FocusNode? _focusNode; | ||
| final _scrollController = ScrollController(); | ||
| final ScrollController _scrollController = ScrollController(); | ||
|
|
||
| @override | ||
| void initState() { | ||
|
|
@@ -148,6 +160,11 @@ class _LanguageToolTextFieldState extends State<LanguageToolTextField> { | |
| onSubmitted: widget.onTextSubmitted, | ||
| onTap: widget.onTap, | ||
| onTapOutside: widget.onTapOutside, | ||
| groupId: widget.groupId ?? EditableText, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of If |
||
| maxLength: widget.maxLength, | ||
| enabled: widget.enabled, | ||
| textCapitalization: widget.textCapitalization ?? TextCapitalization.sentences, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Is this deviation intentional to provide a different default for |
||
| buildCounter: widget.buildCounter, | ||
| ); | ||
|
|
||
| if (widget.alignCenter) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current initialization of
_scrollControllerhere (and its subsequent exclusive use) doesn't correctly incorporate the newwidget.scrollControllerproperty. This meansLanguageToolTextFieldwill always create and use its own internalScrollController, effectively ignoring anyScrollControllerinstance passed by the developer via thewidget.scrollControllerproperty.To correctly implement this, the state needs to manage the
ScrollControllerlifecycle based on whetherwidget.scrollControlleris provided:_internalScrollControlleras suggested below) should be nullable. It should only be initialized with a newScrollController()ininitStateifwidget.scrollControllerisnull.ScrollController(which iswidget.scrollControllerif provided, otherwise the internally created one) should be determined and used throughout the state's lifecycle.ScrollControllermust be passed to theTextField(scrollController: ...)in thebuildmethod._textControllerListenermust read its offset from this effective controller (e.g.,widget.controller.scrollOffset = _effectiveScrollController.offset). It's also good practice to check_effectiveScrollController.hasClientsbefore accessing.offset.disposemethod, the internally created scroll controller (if any) should be disposed._textControllerListeneradded towidget.controllerininitStateis not currently removed indispose. This can lead to memory leaks or errors. Please addwidget.controller.removeListener(_textControllerListener);in thedisposemethod.