Commit 73dbca41 authored by Mattia Crovero's avatar Mattia Crovero Committed by Justin McCandless

Added ScrollController to TextField (#32620)

scrollController param on TextField and CupertinoTextField
parent 27d3c2fc
...@@ -187,6 +187,7 @@ class CupertinoTextField extends StatefulWidget { ...@@ -187,6 +187,7 @@ class CupertinoTextField extends StatefulWidget {
this.scrollPadding = const EdgeInsets.all(20.0), this.scrollPadding = const EdgeInsets.all(20.0),
this.dragStartBehavior = DragStartBehavior.start, this.dragStartBehavior = DragStartBehavior.start,
this.enableInteractiveSelection, this.enableInteractiveSelection,
this.scrollController,
this.scrollPhysics, this.scrollPhysics,
}) : assert(textAlign != null), }) : assert(textAlign != null),
assert(autofocus != null), assert(autofocus != null),
...@@ -430,6 +431,9 @@ class CupertinoTextField extends StatefulWidget { ...@@ -430,6 +431,9 @@ class CupertinoTextField extends StatefulWidget {
/// {@macro flutter.widgets.scrollable.dragStartBehavior} /// {@macro flutter.widgets.scrollable.dragStartBehavior}
final DragStartBehavior dragStartBehavior; final DragStartBehavior dragStartBehavior;
/// {@macro flutter.widgets.editableText.scrollController}
final ScrollController scrollController;
/// {@macro flutter.widgets.edtiableText.scrollPhysics} /// {@macro flutter.widgets.edtiableText.scrollPhysics}
final ScrollPhysics scrollPhysics; final ScrollPhysics scrollPhysics;
...@@ -444,7 +448,6 @@ class CupertinoTextField extends StatefulWidget { ...@@ -444,7 +448,6 @@ class CupertinoTextField extends StatefulWidget {
@override @override
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);
properties.add(DiagnosticsProperty<TextEditingController>('controller', controller, defaultValue: null)); properties.add(DiagnosticsProperty<TextEditingController>('controller', controller, defaultValue: null));
properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null)); properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null));
properties.add(DiagnosticsProperty<BoxDecoration>('decoration', decoration)); properties.add(DiagnosticsProperty<BoxDecoration>('decoration', decoration));
...@@ -466,6 +469,7 @@ class CupertinoTextField extends StatefulWidget { ...@@ -466,6 +469,7 @@ class CupertinoTextField extends StatefulWidget {
properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced')); properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced'));
properties.add(DiagnosticsProperty<Color>('cursorColor', cursorColor, defaultValue: null)); properties.add(DiagnosticsProperty<Color>('cursorColor', cursorColor, defaultValue: null));
properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled'));
properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null));
properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null)); properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
} }
} }
...@@ -820,6 +824,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK ...@@ -820,6 +824,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
scrollPadding: widget.scrollPadding, scrollPadding: widget.scrollPadding,
keyboardAppearance: keyboardAppearance, keyboardAppearance: keyboardAppearance,
dragStartBehavior: widget.dragStartBehavior, dragStartBehavior: widget.dragStartBehavior,
scrollController: widget.scrollController,
scrollPhysics: widget.scrollPhysics, scrollPhysics: widget.scrollPhysics,
enableInteractiveSelection: widget.enableInteractiveSelection, enableInteractiveSelection: widget.enableInteractiveSelection,
), ),
......
...@@ -165,6 +165,7 @@ class TextField extends StatefulWidget { ...@@ -165,6 +165,7 @@ class TextField extends StatefulWidget {
this.enableInteractiveSelection, this.enableInteractiveSelection,
this.onTap, this.onTap,
this.buildCounter, this.buildCounter,
this.scrollController,
this.scrollPhysics, this.scrollPhysics,
}) : assert(textAlign != null), }) : assert(textAlign != null),
assert(autofocus != null), assert(autofocus != null),
...@@ -463,6 +464,9 @@ class TextField extends StatefulWidget { ...@@ -463,6 +464,9 @@ class TextField extends StatefulWidget {
/// {@macro flutter.widgets.edtiableText.scrollPhysics} /// {@macro flutter.widgets.edtiableText.scrollPhysics}
final ScrollPhysics scrollPhysics; final ScrollPhysics scrollPhysics;
/// {@macro flutter.widgets.editableText.scrollController}
final ScrollController scrollController;
@override @override
_TextFieldState createState() => _TextFieldState(); _TextFieldState createState() => _TextFieldState();
...@@ -493,6 +497,7 @@ class TextField extends StatefulWidget { ...@@ -493,6 +497,7 @@ class TextField extends StatefulWidget {
properties.add(DiagnosticsProperty<Brightness>('keyboardAppearance', keyboardAppearance, defaultValue: null)); properties.add(DiagnosticsProperty<Brightness>('keyboardAppearance', keyboardAppearance, defaultValue: null));
properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('scrollPadding', scrollPadding, defaultValue: const EdgeInsets.all(20.0))); properties.add(DiagnosticsProperty<EdgeInsetsGeometry>('scrollPadding', scrollPadding, defaultValue: const EdgeInsets.all(20.0)));
properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled'));
properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null));
properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null)); properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
} }
} }
...@@ -957,6 +962,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -957,6 +962,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
keyboardAppearance: keyboardAppearance, keyboardAppearance: keyboardAppearance,
enableInteractiveSelection: widget.enableInteractiveSelection, enableInteractiveSelection: widget.enableInteractiveSelection,
dragStartBehavior: widget.dragStartBehavior, dragStartBehavior: widget.dragStartBehavior,
scrollController: widget.scrollController,
scrollPhysics: widget.scrollPhysics, scrollPhysics: widget.scrollPhysics,
), ),
); );
......
...@@ -302,6 +302,7 @@ class EditableText extends StatefulWidget { ...@@ -302,6 +302,7 @@ class EditableText extends StatefulWidget {
this.keyboardAppearance = Brightness.light, this.keyboardAppearance = Brightness.light,
this.dragStartBehavior = DragStartBehavior.start, this.dragStartBehavior = DragStartBehavior.start,
this.enableInteractiveSelection, this.enableInteractiveSelection,
this.scrollController,
this.scrollPhysics, this.scrollPhysics,
}) : assert(controller != null), }) : assert(controller != null),
assert(focusNode != null), assert(focusNode != null),
...@@ -738,6 +739,15 @@ class EditableText extends StatefulWidget { ...@@ -738,6 +739,15 @@ class EditableText extends StatefulWidget {
/// {@macro flutter.widgets.scrollable.dragStartBehavior} /// {@macro flutter.widgets.scrollable.dragStartBehavior}
final DragStartBehavior 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} /// {@template flutter.widgets.editableText.scrollPhysics}
/// The [ScrollPhysics] to use when vertically scrolling the input. /// The [ScrollPhysics] to use when vertically scrolling the input.
/// ///
...@@ -772,6 +782,7 @@ class EditableText extends StatefulWidget { ...@@ -772,6 +782,7 @@ class EditableText extends StatefulWidget {
properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false)); properties.add(DiagnosticsProperty<bool>('expands', expands, defaultValue: false));
properties.add(DiagnosticsProperty<bool>('autofocus', autofocus, defaultValue: false)); properties.add(DiagnosticsProperty<bool>('autofocus', autofocus, defaultValue: false));
properties.add(DiagnosticsProperty<TextInputType>('keyboardType', keyboardType, defaultValue: null)); properties.add(DiagnosticsProperty<TextInputType>('keyboardType', keyboardType, defaultValue: null));
properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null));
properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null)); properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
} }
} }
...@@ -786,7 +797,8 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -786,7 +797,8 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
TextInputConnection _textInputConnection; TextInputConnection _textInputConnection;
TextSelectionOverlay _selectionOverlay; TextSelectionOverlay _selectionOverlay;
final ScrollController _scrollController = ScrollController(); ScrollController _scrollController;
AnimationController _cursorBlinkOpacityController; AnimationController _cursorBlinkOpacityController;
final LayerLink _layerLink = LayerLink(); final LayerLink _layerLink = LayerLink();
...@@ -816,6 +828,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -816,6 +828,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
widget.controller.addListener(_didChangeTextEditingValue); widget.controller.addListener(_didChangeTextEditingValue);
_focusAttachment = widget.focusNode.attach(context); _focusAttachment = widget.focusNode.attach(context);
widget.focusNode.addListener(_handleFocusChanged); widget.focusNode.addListener(_handleFocusChanged);
_scrollController = widget.scrollController ?? ScrollController();
_scrollController.addListener(() { _selectionOverlay?.updateForScroll(); }); _scrollController.addListener(() { _selectionOverlay?.updateForScroll(); });
_cursorBlinkOpacityController = AnimationController(vsync: this, duration: _fadeDuration); _cursorBlinkOpacityController = AnimationController(vsync: this, duration: _fadeDuration);
_cursorBlinkOpacityController.addListener(_onCursorColorTick); _cursorBlinkOpacityController.addListener(_onCursorColorTick);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment