Text field scroll physics (#31088)
TextField and CupertinoTextField can now specify scrollPhysics. Cupertino defaults to bouncing now.
This commit is contained in:
committed by
GitHub
parent
0545c63b9b
commit
6e1b143fed
@@ -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',
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user