diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index 0584c69c9a..69061d40ea 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -187,6 +187,7 @@ class CupertinoTextField extends StatefulWidget { this.scrollPadding = const EdgeInsets.all(20.0), this.dragStartBehavior = DragStartBehavior.start, this.enableInteractiveSelection, + this.scrollController, this.scrollPhysics, }) : assert(textAlign != null), assert(autofocus != null), @@ -430,6 +431,9 @@ class CupertinoTextField extends StatefulWidget { /// {@macro flutter.widgets.scrollable.dragStartBehavior} final DragStartBehavior dragStartBehavior; + /// {@macro flutter.widgets.editableText.scrollController} + final ScrollController scrollController; + /// {@macro flutter.widgets.edtiableText.scrollPhysics} final ScrollPhysics scrollPhysics; @@ -444,7 +448,6 @@ class CupertinoTextField extends StatefulWidget { @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { super.debugFillProperties(properties); - properties.add(DiagnosticsProperty('controller', controller, defaultValue: null)); properties.add(DiagnosticsProperty('focusNode', focusNode, defaultValue: null)); properties.add(DiagnosticsProperty('decoration', decoration)); @@ -466,6 +469,7 @@ class CupertinoTextField extends StatefulWidget { properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced')); properties.add(DiagnosticsProperty('cursorColor', cursorColor, defaultValue: null)); properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); + properties.add(DiagnosticsProperty('scrollController', scrollController, defaultValue: null)); properties.add(DiagnosticsProperty('scrollPhysics', scrollPhysics, defaultValue: null)); } } @@ -820,6 +824,7 @@ class _CupertinoTextFieldState extends State with AutomaticK scrollPadding: widget.scrollPadding, keyboardAppearance: keyboardAppearance, dragStartBehavior: widget.dragStartBehavior, + scrollController: widget.scrollController, scrollPhysics: widget.scrollPhysics, enableInteractiveSelection: widget.enableInteractiveSelection, ), diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index e1f63b9808..b9fbdc5908 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -165,6 +165,7 @@ class TextField extends StatefulWidget { this.enableInteractiveSelection, this.onTap, this.buildCounter, + this.scrollController, this.scrollPhysics, }) : assert(textAlign != null), assert(autofocus != null), @@ -463,6 +464,9 @@ class TextField extends StatefulWidget { /// {@macro flutter.widgets.edtiableText.scrollPhysics} final ScrollPhysics scrollPhysics; + /// {@macro flutter.widgets.editableText.scrollController} + final ScrollController scrollController; + @override _TextFieldState createState() => _TextFieldState(); @@ -493,6 +497,7 @@ class TextField extends StatefulWidget { properties.add(DiagnosticsProperty('keyboardAppearance', keyboardAppearance, defaultValue: null)); properties.add(DiagnosticsProperty('scrollPadding', scrollPadding, defaultValue: const EdgeInsets.all(20.0))); properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); + properties.add(DiagnosticsProperty('scrollController', scrollController, defaultValue: null)); properties.add(DiagnosticsProperty('scrollPhysics', scrollPhysics, defaultValue: null)); } } @@ -957,6 +962,7 @@ class _TextFieldState extends State with AutomaticKeepAliveClientMixi keyboardAppearance: keyboardAppearance, enableInteractiveSelection: widget.enableInteractiveSelection, dragStartBehavior: widget.dragStartBehavior, + scrollController: widget.scrollController, scrollPhysics: widget.scrollPhysics, ), ); diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 72e20219a3..add03f929d 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -302,6 +302,7 @@ class EditableText extends StatefulWidget { this.keyboardAppearance = Brightness.light, this.dragStartBehavior = DragStartBehavior.start, this.enableInteractiveSelection, + this.scrollController, this.scrollPhysics, }) : assert(controller != null), assert(focusNode != null), @@ -738,6 +739,15 @@ class EditableText extends StatefulWidget { /// {@macro flutter.widgets.scrollable.dragStartBehavior} final DragStartBehavior dragStartBehavior; + /// {@template flutter.widgets.editableText.scrollController} + /// The [ScrollController] to use when vertically scrolling the input. + /// + /// If null, it will instantiate a new ScrollController. + /// + /// See [Scrollable.controller]. + /// {@endtemplate} + final ScrollController scrollController; + /// {@template flutter.widgets.editableText.scrollPhysics} /// The [ScrollPhysics] to use when vertically scrolling the input. /// @@ -772,6 +782,7 @@ class EditableText extends StatefulWidget { properties.add(DiagnosticsProperty('expands', expands, defaultValue: false)); properties.add(DiagnosticsProperty('autofocus', autofocus, defaultValue: false)); properties.add(DiagnosticsProperty('keyboardType', keyboardType, defaultValue: null)); + properties.add(DiagnosticsProperty('scrollController', scrollController, defaultValue: null)); properties.add(DiagnosticsProperty('scrollPhysics', scrollPhysics, defaultValue: null)); } } @@ -786,7 +797,8 @@ class EditableTextState extends State with AutomaticKeepAliveClien TextInputConnection _textInputConnection; TextSelectionOverlay _selectionOverlay; - final ScrollController _scrollController = ScrollController(); + ScrollController _scrollController; + AnimationController _cursorBlinkOpacityController; final LayerLink _layerLink = LayerLink(); @@ -816,6 +828,7 @@ class EditableTextState extends State with AutomaticKeepAliveClien widget.controller.addListener(_didChangeTextEditingValue); _focusAttachment = widget.focusNode.attach(context); widget.focusNode.addListener(_handleFocusChanged); + _scrollController = widget.scrollController ?? ScrollController(); _scrollController.addListener(() { _selectionOverlay?.updateForScroll(); }); _cursorBlinkOpacityController = AnimationController(vsync: this, duration: _fadeDuration); _cursorBlinkOpacityController.addListener(_onCursorColorTick);