diff --git a/packages/flutter/lib/src/material/selectable_text.dart b/packages/flutter/lib/src/material/selectable_text.dart index 068b8e672e..44253c554c 100644 --- a/packages/flutter/lib/src/material/selectable_text.dart +++ b/packages/flutter/lib/src/material/selectable_text.dart @@ -48,7 +48,7 @@ class _SelectableTextSelectionGestureDetectorBuilder extends TextSelectionGestur _SelectableTextSelectionGestureDetectorBuilder({ @required _SelectableTextState state, }) : _state = state, - super(delegate: state); + super(delegate: state); final _SelectableTextState _state; @@ -201,6 +201,7 @@ class SelectableText extends StatefulWidget { this.strutStyle, this.textAlign, this.textDirection, + this.textScaleFactor, this.showCursor = false, this.autofocus = false, ToolbarOptions toolbarOptions, @@ -243,6 +244,7 @@ class SelectableText extends StatefulWidget { this.strutStyle, this.textAlign, this.textDirection, + this.textScaleFactor, this.showCursor = false, this.autofocus = false, ToolbarOptions toolbarOptions, @@ -321,6 +323,9 @@ class SelectableText extends StatefulWidget { /// {@macro flutter.widgets.editableText.textDirection} final TextDirection textDirection; + /// {@macro flutter.widgets.editableText.textScaleFactor} + final double textScaleFactor; + /// {@macro flutter.widgets.editableText.autofocus} final bool autofocus; @@ -396,6 +401,7 @@ class SelectableText extends StatefulWidget { properties.add(IntProperty('maxLines', maxLines, defaultValue: null)); properties.add(EnumProperty('textAlign', textAlign, defaultValue: null)); properties.add(EnumProperty('textDirection', textDirection, defaultValue: null)); + properties.add(DoubleProperty('textScaleFactor', textScaleFactor, defaultValue: null)); properties.add(DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0)); properties.add(DiagnosticsProperty('cursorRadius', cursorRadius, defaultValue: null)); properties.add(DiagnosticsProperty('cursorColor', cursorColor, defaultValue: null)); @@ -572,6 +578,7 @@ class _SelectableTextState extends State with AutomaticKeepAlive strutStyle: widget.strutStyle ?? StrutStyle.disabled, textAlign: widget.textAlign ?? defaultTextStyle.textAlign ?? TextAlign.start, textDirection: widget.textDirection, + textScaleFactor: widget.textScaleFactor, autofocus: widget.autofocus, forceLine: false, toolbarOptions: widget.toolbarOptions, diff --git a/packages/flutter/test/widgets/selectable_text_test.dart b/packages/flutter/test/widgets/selectable_text_test.dart index 1a481d2d3c..20d991cbff 100644 --- a/packages/flutter/test/widgets/selectable_text_test.dart +++ b/packages/flutter/test/widgets/selectable_text_test.dart @@ -177,10 +177,7 @@ void main() { debugResetSemanticsIdCounter(); }); - Widget selectableTextBuilder({ - String text = '', - int maxLines = 1, - }) { + Widget selectableTextBuilder({String text = '', int maxLines = 1}) { return boilerplate( child: SelectableText( text, @@ -192,17 +189,12 @@ void main() { testWidgets('has expected defaults', (WidgetTester tester) async { await tester.pumpWidget( - const MediaQuery( - data: MediaQueryData(devicePixelRatio: 1.0), - child: Directionality( - textDirection: TextDirection.ltr, - child: SelectableText('selectable text'), - ), + boilerplate( + child: const SelectableText('selectable text'), ), ); - final SelectableText selectableText = - tester.firstWidget(find.byType(SelectableText)); + final SelectableText selectableText = tester.firstWidget(find.byType(SelectableText)); expect(selectableText.showCursor, false); expect(selectableText.autofocus, false); expect(selectableText.dragStartBehavior, DragStartBehavior.start); @@ -328,6 +320,29 @@ void main() { expect(longtextBox.size, const Size(199.0, 14.0)); }); + testWidgets('can scale with textScaleFactor', (WidgetTester tester) async { + await tester.pumpWidget( + boilerplate( + child: const SelectableText('selectable text'), + ), + ); + + final RenderBox renderBox = tester.renderObject(find.byType(SelectableText)); + expect(renderBox.size.height, 14.0); + + await tester.pumpWidget( + boilerplate( + child: const SelectableText( + 'selectable text', + textScaleFactor: 1.9, + ), + ), + ); + + final RenderBox scaledBox = tester.renderObject(find.byType(SelectableText)); + expect(scaledBox.size.height, 27.0); + }); + testWidgets('can switch between textWidthBasis', (WidgetTester tester) async { RenderBox findTextBox() => tester.renderObject(find.byType(SelectableText)); const String text = 'I can face roll keyboardkeyboardaszzaaaaszzaaaaszzaaaaszzaaaa'; @@ -3186,25 +3201,13 @@ void main() { testWidgets('SelectableText implements debugFillProperties', (WidgetTester tester) async { final DiagnosticPropertiesBuilder builder = DiagnosticPropertiesBuilder(); -// properties.add(DiagnosticsProperty('data', data, defaultValue: null)); -// properties.add(DiagnosticsProperty('focusNode', focusNode, defaultValue: null)); -// properties.add(DiagnosticsProperty('style', style, defaultValue: null)); -// properties.add(DiagnosticsProperty('autofocus', autofocus, defaultValue: false)); -// properties.add(DiagnosticsProperty('showCursor', showCursor, defaultValue: false)); -// properties.add(IntProperty('maxLines', maxLines, defaultValue: null)); -// properties.add(EnumProperty('textAlign', textAlign, defaultValue: null)); -// properties.add(EnumProperty('textDirection', textDirection, defaultValue: null)); -// properties.add(DoubleProperty('cursorWidth', cursorWidth, defaultValue: 2.0)); -// properties.add(DiagnosticsProperty('cursorRadius', cursorRadius, defaultValue: null)); -// properties.add(DiagnosticsProperty('cursorColor', cursorColor, defaultValue: null)); -// properties.add(FlagProperty('selectionEnabled', value: selectionEnabled, defaultValue: true, ifFalse: 'selection disabled')); -// properties.add(DiagnosticsProperty('scrollPhysics', scrollPhysics, defaultValue: null)); // Not checking controller, inputFormatters, focusNode const SelectableText( 'something', style: TextStyle(color: Color(0xff00ff00)), textAlign: TextAlign.end, textDirection: TextDirection.ltr, + textScaleFactor: 1.0, autofocus: true, showCursor: true, maxLines: 10, @@ -3227,6 +3230,7 @@ void main() { 'maxLines: 10', 'textAlign: end', 'textDirection: ltr', + 'textScaleFactor: 1.0', 'cursorWidth: 1.0', 'cursorRadius: Radius.circular(0.0)', 'cursorColor: Color(0xff00ff00)',