diff --git a/packages/flutter/lib/src/cupertino/text_field.dart b/packages/flutter/lib/src/cupertino/text_field.dart index ab51638b01..25164e48e8 100644 --- a/packages/flutter/lib/src/cupertino/text_field.dart +++ b/packages/flutter/lib/src/cupertino/text_field.dart @@ -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('cursorColor', cursorColor, defaultValue: null)); + properties.add(DiagnosticsProperty('scrollPhysics', scrollPhysics, defaultValue: null)); } } @@ -751,6 +756,7 @@ class _CupertinoTextFieldState extends State with AutomaticK scrollPadding: widget.scrollPadding, keyboardAppearance: keyboardAppearance, dragStartBehavior: widget.dragStartBehavior, + scrollPhysics: widget.scrollPhysics, ), ), ); diff --git a/packages/flutter/lib/src/material/text_field.dart b/packages/flutter/lib/src/material/text_field.dart index 23999dc88b..0eed7c86d0 100644 --- a/packages/flutter/lib/src/material/text_field.dart +++ b/packages/flutter/lib/src/material/text_field.dart @@ -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('keyboardAppearance', keyboardAppearance, defaultValue: null)); properties.add(DiagnosticsProperty('scrollPadding', scrollPadding, defaultValue: const EdgeInsets.all(20.0))); properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); + properties.add(DiagnosticsProperty('scrollPhysics', scrollPhysics, defaultValue: null)); } } @@ -892,6 +897,7 @@ class _TextFieldState extends State with AutomaticKeepAliveClientMixi keyboardAppearance: keyboardAppearance, enableInteractiveSelection: widget.enableInteractiveSelection, dragStartBehavior: widget.dragStartBehavior, + scrollPhysics: widget.scrollPhysics, ), ); diff --git a/packages/flutter/lib/src/widgets/editable_text.dart b/packages/flutter/lib/src/widgets/editable_text.dart index 3b98b0ebca..5f932b1a93 100644 --- a/packages/flutter/lib/src/widgets/editable_text.dart +++ b/packages/flutter/lib/src/widgets/editable_text.dart @@ -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('expands', expands, defaultValue: false)); properties.add(DiagnosticsProperty('autofocus', autofocus, defaultValue: false)); properties.add(DiagnosticsProperty('keyboardType', keyboardType, defaultValue: null)); + properties.add(DiagnosticsProperty('scrollPhysics', scrollPhysics, defaultValue: null)); } } @@ -1397,7 +1408,7 @@ class EditableTextState extends State 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( diff --git a/packages/flutter/test/material/text_field_test.dart b/packages/flutter/test/material/text_field_test.dart index a8811bfe2a..7366e69302 100644 --- a/packages/flutter/test/material/text_field_test.dart +++ b/packages/flutter/test/material/text_field_test.dart @@ -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', ]); });