Commit 0ec73510 authored by 神楽坂花火's avatar 神楽坂花火 Committed by Flutter GitHub Bot

Add textScaleFactor to SelectableText (#44682)

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