Unverified Commit 6e1b143f authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

Text field scroll physics (#31088)

TextField and CupertinoTextField can now specify scrollPhysics. Cupertino defaults to bouncing now.
parent 0545c63b
...@@ -186,6 +186,7 @@ class CupertinoTextField extends StatefulWidget { ...@@ -186,6 +186,7 @@ class CupertinoTextField extends StatefulWidget {
this.keyboardAppearance, this.keyboardAppearance,
this.scrollPadding = const EdgeInsets.all(20.0), this.scrollPadding = const EdgeInsets.all(20.0),
this.dragStartBehavior = DragStartBehavior.start, this.dragStartBehavior = DragStartBehavior.start,
this.scrollPhysics,
}) : assert(textAlign != null), }) : assert(textAlign != null),
assert(autofocus != null), assert(autofocus != null),
assert(obscureText != null), assert(obscureText != null),
...@@ -425,6 +426,9 @@ class CupertinoTextField extends StatefulWidget { ...@@ -425,6 +426,9 @@ class CupertinoTextField extends StatefulWidget {
/// {@macro flutter.widgets.scrollable.dragStartBehavior} /// {@macro flutter.widgets.scrollable.dragStartBehavior}
final DragStartBehavior dragStartBehavior; final DragStartBehavior dragStartBehavior;
/// {@macro flutter.widgets.edtiableText.scrollPhysics}
final ScrollPhysics scrollPhysics;
@override @override
_CupertinoTextFieldState createState() => _CupertinoTextFieldState(); _CupertinoTextFieldState createState() => _CupertinoTextFieldState();
...@@ -452,6 +456,7 @@ class CupertinoTextField extends StatefulWidget { ...@@ -452,6 +456,7 @@ class CupertinoTextField extends StatefulWidget {
properties.add(IntProperty('maxLength', maxLength, defaultValue: null)); properties.add(IntProperty('maxLength', maxLength, defaultValue: null));
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(DiagnosticsProperty<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
} }
} }
...@@ -751,6 +756,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK ...@@ -751,6 +756,7 @@ class _CupertinoTextFieldState extends State<CupertinoTextField> with AutomaticK
scrollPadding: widget.scrollPadding, scrollPadding: widget.scrollPadding,
keyboardAppearance: keyboardAppearance, keyboardAppearance: keyboardAppearance,
dragStartBehavior: widget.dragStartBehavior, dragStartBehavior: widget.dragStartBehavior,
scrollPhysics: widget.scrollPhysics,
), ),
), ),
); );
......
...@@ -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.scrollPhysics,
}) : assert(textAlign != null), }) : assert(textAlign != null),
assert(autofocus != null), assert(autofocus != null),
assert(obscureText != null), assert(obscureText != null),
...@@ -459,6 +460,9 @@ class TextField extends StatefulWidget { ...@@ -459,6 +460,9 @@ class TextField extends StatefulWidget {
/// {@end-tool} /// {@end-tool}
final InputCounterWidgetBuilder buildCounter; final InputCounterWidgetBuilder buildCounter;
/// {@macro flutter.widgets.edtiableText.scrollPhysics}
final ScrollPhysics scrollPhysics;
@override @override
_TextFieldState createState() => _TextFieldState(); _TextFieldState createState() => _TextFieldState();
...@@ -489,6 +493,7 @@ class TextField extends StatefulWidget { ...@@ -489,6 +493,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<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
} }
} }
...@@ -892,6 +897,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi ...@@ -892,6 +897,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
keyboardAppearance: keyboardAppearance, keyboardAppearance: keyboardAppearance,
enableInteractiveSelection: widget.enableInteractiveSelection, enableInteractiveSelection: widget.enableInteractiveSelection,
dragStartBehavior: widget.dragStartBehavior, dragStartBehavior: widget.dragStartBehavior,
scrollPhysics: widget.scrollPhysics,
), ),
); );
......
...@@ -301,6 +301,7 @@ class EditableText extends StatefulWidget { ...@@ -301,6 +301,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.scrollPhysics,
}) : assert(controller != null), }) : assert(controller != null),
assert(focusNode != null), assert(focusNode != null),
assert(obscureText != null), assert(obscureText != null),
...@@ -733,6 +734,15 @@ class EditableText extends StatefulWidget { ...@@ -733,6 +734,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.scrollPhysics}
/// The [ScrollPhysics] to use when vertically scrolling the input.
///
/// If not specified, it will behave according to the current platform.
///
/// See [Scrollable.physics].
/// {@endtemplate}
final ScrollPhysics scrollPhysics;
/// {@macro flutter.rendering.editable.selectionEnabled} /// {@macro flutter.rendering.editable.selectionEnabled}
bool get selectionEnabled { bool get selectionEnabled {
return enableInteractiveSelection ?? !obscureText; return enableInteractiveSelection ?? !obscureText;
...@@ -758,6 +768,7 @@ class EditableText extends StatefulWidget { ...@@ -758,6 +768,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<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
} }
} }
...@@ -1397,7 +1408,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien ...@@ -1397,7 +1408,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
excludeFromSemantics: true, excludeFromSemantics: true,
axisDirection: _isMultiline ? AxisDirection.down : AxisDirection.right, axisDirection: _isMultiline ? AxisDirection.down : AxisDirection.right,
controller: _scrollController, controller: _scrollController,
physics: const ClampingScrollPhysics(), physics: widget.scrollPhysics,
dragStartBehavior: widget.dragStartBehavior, dragStartBehavior: widget.dragStartBehavior,
viewportBuilder: (BuildContext context, ViewportOffset offset) { viewportBuilder: (BuildContext context, ViewportOffset offset) {
return CompositedTransformTarget( return CompositedTransformTarget(
......
...@@ -5348,6 +5348,7 @@ void main() { ...@@ -5348,6 +5348,7 @@ void main() {
cursorColor: Color(0xff00ff00), cursorColor: Color(0xff00ff00),
keyboardAppearance: Brightness.dark, keyboardAppearance: Brightness.dark,
scrollPadding: EdgeInsets.zero, scrollPadding: EdgeInsets.zero,
scrollPhysics: ClampingScrollPhysics(),
enableInteractiveSelection: false, enableInteractiveSelection: false,
).debugFillProperties(builder); ).debugFillProperties(builder);
...@@ -5374,6 +5375,7 @@ void main() { ...@@ -5374,6 +5375,7 @@ void main() {
'keyboardAppearance: Brightness.dark', 'keyboardAppearance: Brightness.dark',
'scrollPadding: EdgeInsets.zero', 'scrollPadding: EdgeInsets.zero',
'selection disabled', 'selection disabled',
'scrollPhysics: ClampingScrollPhysics',
]); ]);
}); });
......
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