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 {
this.keyboardAppearance,
this.scrollPadding = const EdgeInsets.all(20.0),
this.dragStartBehavior = DragStartBehavior.start,
this.scrollPhysics,
}) : assert(textAlign != null),
assert(autofocus != null),
assert(obscureText != null),
......@@ -425,6 +426,9 @@ class CupertinoTextField extends StatefulWidget {
/// {@macro flutter.widgets.scrollable.dragStartBehavior}
final DragStartBehavior dragStartBehavior;
/// {@macro flutter.widgets.edtiableText.scrollPhysics}
final ScrollPhysics scrollPhysics;
@override
_CupertinoTextFieldState createState() => _CupertinoTextFieldState();
......@@ -452,6 +456,7 @@ class CupertinoTextField extends StatefulWidget {
properties.add(IntProperty('maxLength', maxLength, defaultValue: null));
properties.add(FlagProperty('maxLengthEnforced', value: maxLengthEnforced, ifTrue: 'max length enforced'));
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
scrollPadding: widget.scrollPadding,
keyboardAppearance: keyboardAppearance,
dragStartBehavior: widget.dragStartBehavior,
scrollPhysics: widget.scrollPhysics,
),
),
);
......
......@@ -165,6 +165,7 @@ class TextField extends StatefulWidget {
this.enableInteractiveSelection,
this.onTap,
this.buildCounter,
this.scrollPhysics,
}) : assert(textAlign != null),
assert(autofocus != null),
assert(obscureText != null),
......@@ -459,6 +460,9 @@ class TextField extends StatefulWidget {
/// {@end-tool}
final InputCounterWidgetBuilder buildCounter;
/// {@macro flutter.widgets.edtiableText.scrollPhysics}
final ScrollPhysics scrollPhysics;
@override
_TextFieldState createState() => _TextFieldState();
......@@ -489,6 +493,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<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
}
}
......@@ -892,6 +897,7 @@ class _TextFieldState extends State<TextField> with AutomaticKeepAliveClientMixi
keyboardAppearance: keyboardAppearance,
enableInteractiveSelection: widget.enableInteractiveSelection,
dragStartBehavior: widget.dragStartBehavior,
scrollPhysics: widget.scrollPhysics,
),
);
......
......@@ -301,6 +301,7 @@ class EditableText extends StatefulWidget {
this.keyboardAppearance = Brightness.light,
this.dragStartBehavior = DragStartBehavior.start,
this.enableInteractiveSelection,
this.scrollPhysics,
}) : assert(controller != null),
assert(focusNode != null),
assert(obscureText != null),
......@@ -733,6 +734,15 @@ class EditableText extends StatefulWidget {
/// {@macro flutter.widgets.scrollable.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}
bool get selectionEnabled {
return enableInteractiveSelection ?? !obscureText;
......@@ -758,6 +768,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<ScrollPhysics>('scrollPhysics', scrollPhysics, defaultValue: null));
}
}
......@@ -1397,7 +1408,7 @@ class EditableTextState extends State<EditableText> with AutomaticKeepAliveClien
excludeFromSemantics: true,
axisDirection: _isMultiline ? AxisDirection.down : AxisDirection.right,
controller: _scrollController,
physics: const ClampingScrollPhysics(),
physics: widget.scrollPhysics,
dragStartBehavior: widget.dragStartBehavior,
viewportBuilder: (BuildContext context, ViewportOffset offset) {
return CompositedTransformTarget(
......
......@@ -5348,6 +5348,7 @@ void main() {
cursorColor: Color(0xff00ff00),
keyboardAppearance: Brightness.dark,
scrollPadding: EdgeInsets.zero,
scrollPhysics: ClampingScrollPhysics(),
enableInteractiveSelection: false,
).debugFillProperties(builder);
......@@ -5374,6 +5375,7 @@ void main() {
'keyboardAppearance: Brightness.dark',
'scrollPadding: EdgeInsets.zero',
'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