mirror of
https://github.com/flutter/flutter
synced 2024-10-13 03:32:55 +00:00
Added ScrollController to TextField (#32620)
scrollController param on TextField and CupertinoTextField
This commit is contained in:
parent
27d3c2fcc8
commit
73dbca4142
|
@ -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<TextEditingController>('controller', controller, defaultValue: null));
|
||||
properties.add(DiagnosticsProperty<FocusNode>('focusNode', focusNode, defaultValue: null));
|
||||
properties.add(DiagnosticsProperty<BoxDecoration>('decoration', decoration));
|
||||
|
@ -466,6 +469,7 @@ class CupertinoTextField extends StatefulWidget {
|
|||
properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced'));
|
||||
properties.add(DiagnosticsProperty<Color>('cursorColor', cursorColor, defaultValue: null));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
@ -820,6 +824,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
|
|||
scrollPadding: widget.scrollPadding,
|
||||
keyboardAppearance: keyboardAppearance,
|
||||
dragStartBehavior: widget.dragStartBehavior,
|
||||
scrollController: widget.scrollController,
|
||||
scrollPhysics: widget.scrollPhysics,
|
||||
enableInteractiveSelection: widget.enableInteractiveSelection,
|
||||
),
|
||||
|
|
|
@ -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<Brightness>('keyboardAppearance', keyboardAppearance, defaultValue: null));
|
||||
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(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null));
|
||||
properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
|
||||
}
|
||||
}
|
||||
|
@ -957,6 +962,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
|
|||
keyboardAppearance: keyboardAppearance,
|
||||
enableInteractiveSelection: widget.enableInteractiveSelection,
|
||||
dragStartBehavior: widget.dragStartBehavior,
|
||||
scrollController: widget.scrollController,
|
||||
scrollPhysics: widget.scrollPhysics,
|
||||
),
|
||||
);
|
||||
|
|
|
@ -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<bool>('expands', expands, defaultValue: false));
|
||||
properties.add(DiagnosticsProperty<bool>('autofocus', autofocus, defaultValue: false));
|
||||
properties.add(DiagnosticsProperty<TextInputType>('keyboardType', keyboardType, defaultValue: null));
|
||||
properties.add(DiagnosticsProperty<ScrollController>('scrollController', scrollController, defaultValue: null));
|
||||
properties.add(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
|
||||
}
|
||||
}
|
||||
|
@ -786,7 +797,8 @@ class EditableTextState extends State<EditableText> 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<EditableText> 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);
|
||||
|
|
Loading…
Reference in a new issue