Unverified Commit 67606281 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Typos & Style clean up (#42006)

parent 0917cb00
...@@ -15,17 +15,16 @@ import 'text_style.dart'; ...@@ -15,17 +15,16 @@ import 'text_style.dart';
/// An immutable span of text. /// An immutable span of text.
/// ///
/// A [TextSpan] object can be styled using its [style] property. /// A [TextSpan] object can be styled using its [style] property. The style will
/// The style will be applied to the [text] and the [children]. /// be applied to the [text] and the [children].
/// ///
/// A [TextSpan] object can just have plain text, or it can have /// A [TextSpan] object can just have plain text, or it can have children
/// children [TextSpan] objects with their own styles that (possibly /// [TextSpan] objects with their own styles that (possibly only partially)
/// only partially) override the [style] of this object. If a /// override the [style] of this object. If a [TextSpan] has both [text] and
/// [TextSpan] has both [text] and [children], then the [text] is /// [children], then the [text] is treated as if it was an un-styled [TextSpan]
/// treated as if it was an unstyled [TextSpan] at the start of the /// at the start of the [children] list. Leaving the [TextSpan.text] field null
/// [children] list. Leaving the [TextSpan.text] field null results /// results in the [TextSpan] acting as an empty node in the [InlineSpan] tree
/// in the [TextSpan] acting as an empty node in the [InlineSpan] /// with a list of children.
/// tree with a list of children.
/// ///
/// To paint a [TextSpan] on a [Canvas], use a [TextPainter]. To display a text /// To paint a [TextSpan] on a [Canvas], use a [TextPainter]. To display a text
/// span in a widget, use a [RichText]. For text with a single style, consider /// span in a widget, use a [RichText]. For text with a single style, consider
...@@ -46,17 +45,17 @@ import 'text_style.dart'; ...@@ -46,17 +45,17 @@ import 'text_style.dart';
/// _There is some more detailed sample code in the documentation for the /// _There is some more detailed sample code in the documentation for the
/// [recognizer] property._ /// [recognizer] property._
/// ///
/// The [TextSpan.text] will be used as the semantics label unless overriden /// The [TextSpan.text] will be used as the semantics label unless overridden
/// by the [TextSpan.semanticsLabel] property. Any [PlaceholderSpan]s in the /// by the [TextSpan.semanticsLabel] property. Any [PlaceholderSpan]s in the
/// [TextSpan.children] list will separate the text before and after it into /// [TextSpan.children] list will separate the text before and after it into two
/// two semantics nodes. /// semantics nodes.
/// ///
/// See also: /// See also:
/// ///
/// * [WidgetSpan], a leaf node that represents an embedded inline widget /// * [WidgetSpan], a leaf node that represents an embedded inline widget in an
/// in an [InlineSpan] tree. Specify a widget within the [children] /// [InlineSpan] tree. Specify a widget within the [children] list by
/// list by wrapping the widget with a [WidgetSpan]. The widget will be /// wrapping the widget with a [WidgetSpan]. The widget will be laid out
/// laid out inline within the paragraph. /// inline within the paragraph.
/// * [Text], a widget for showing uniformly-styled text. /// * [Text], a widget for showing uniformly-styled text.
/// * [RichText], a widget for finer control of text rendering. /// * [RichText], a widget for finer control of text rendering.
/// * [TextPainter], a class for painting [TextSpan] objects on a [Canvas]. /// * [TextPainter], a class for painting [TextSpan] objects on a [Canvas].
...@@ -89,8 +88,8 @@ class TextSpan extends InlineSpan { ...@@ -89,8 +88,8 @@ class TextSpan extends InlineSpan {
/// If both [text] and [children] are non-null, the text will precede the /// If both [text] and [children] are non-null, the text will precede the
/// children. /// children.
/// ///
/// Modifying the list after the [TextSpan] has been created is not /// Modifying the list after the [TextSpan] has been created is not supported
/// supported and may have unexpected results. /// and may have unexpected results.
/// ///
/// The list must not contain any nulls. /// The list must not contain any nulls.
@override @override
...@@ -102,19 +101,20 @@ class TextSpan extends InlineSpan { ...@@ -102,19 +101,20 @@ class TextSpan extends InlineSpan {
/// object that manages the [InlineSpan] painting is also responsible for /// object that manages the [InlineSpan] painting is also responsible for
/// dispatching events. In the rendering library, that is the /// dispatching events. In the rendering library, that is the
/// [RenderParagraph] object, which corresponds to the [RichText] widget in /// [RenderParagraph] object, which corresponds to the [RichText] widget in
/// the widgets layer; these objects do not bubble events in [InlineSpan]s, so a /// the widgets layer; these objects do not bubble events in [InlineSpan]s,
/// [recognizer] is only effective for events that directly hit the [text] of /// so a [recognizer] is only effective for events that directly hit the
/// that [InlineSpan], not any of its [children]. /// [text] of that [InlineSpan], not any of its [children].
/// ///
/// [InlineSpan] also does not manage the lifetime of the gesture recognizer. /// [InlineSpan] also does not manage the lifetime of the gesture recognizer.
/// The code that owns the [GestureRecognizer] object must call /// The code that owns the [GestureRecognizer] object must call
/// [GestureRecognizer.dispose] when the [InlineSpan] object is no longer used. /// [GestureRecognizer.dispose] when the [InlineSpan] object is no longer
/// used.
/// ///
/// {@tool sample} /// {@tool sample}
/// ///
/// This example shows how to manage the lifetime of a gesture recognizer /// This example shows how to manage the lifetime of a gesture recognizer
/// provided to an [InlineSpan] object. It defines a `BuzzingText` widget which /// provided to an [InlineSpan] object. It defines a `BuzzingText` widget
/// uses the [HapticFeedback] class to vibrate the device when the user /// which uses the [HapticFeedback] class to vibrate the device when the user
/// long-presses the "find the" span, which is underlined in wavy green. The /// long-presses the "find the" span, which is underlined in wavy green. The
/// hit-testing is handled by the [RichText] widget. /// hit-testing is handled by the [RichText] widget.
/// ///
...@@ -194,7 +194,11 @@ class TextSpan extends InlineSpan { ...@@ -194,7 +194,11 @@ class TextSpan extends InlineSpan {
/// [TextPainter] class to paint [TextSpan] objects onto [Canvas] /// [TextPainter] class to paint [TextSpan] objects onto [Canvas]
/// objects. /// objects.
@override @override
void build(ui.ParagraphBuilder builder, { double textScaleFactor = 1.0, List<PlaceholderDimensions> dimensions }) { void build(
ui.ParagraphBuilder builder, {
double textScaleFactor = 1.0,
List<PlaceholderDimensions> dimensions,
}) {
assert(debugAssertIsValid()); assert(debugAssertIsValid());
final bool hasStyle = style != null; final bool hasStyle = style != null;
if (hasStyle) if (hasStyle)
...@@ -204,7 +208,11 @@ class TextSpan extends InlineSpan { ...@@ -204,7 +208,11 @@ class TextSpan extends InlineSpan {
if (children != null) { if (children != null) {
for (InlineSpan child in children) { for (InlineSpan child in children) {
assert(child != null); assert(child != null);
child.build(builder, textScaleFactor: textScaleFactor, dimensions: dimensions); child.build(
builder,
textScaleFactor: textScaleFactor,
dimensions: dimensions,
);
} }
} }
if (hasStyle) if (hasStyle)
...@@ -214,8 +222,8 @@ class TextSpan extends InlineSpan { ...@@ -214,8 +222,8 @@ class TextSpan extends InlineSpan {
/// Walks this [TextSpan] and its descendants in pre-order and calls [visitor] /// Walks this [TextSpan] and its descendants in pre-order and calls [visitor]
/// for each span that has text. /// for each span that has text.
/// ///
/// When `visitor` returns true, the walk will continue. When `visitor` returns /// When `visitor` returns true, the walk will continue. When `visitor`
/// false, then the walk will end. /// returns false, then the walk will end.
@override @override
bool visitChildren(InlineSpanVisitor visitor) { bool visitChildren(InlineSpanVisitor visitor) {
if (text != null) { if (text != null) {
...@@ -235,8 +243,8 @@ class TextSpan extends InlineSpan { ...@@ -235,8 +243,8 @@ class TextSpan extends InlineSpan {
/// Walks this [TextSpan] and any descendants in pre-order and calls `visitor` /// Walks this [TextSpan] and any descendants in pre-order and calls `visitor`
/// for each span that has content. /// for each span that has content.
/// ///
/// When `visitor` returns true, the walk will continue. When `visitor` returns /// When `visitor` returns true, the walk will continue. When `visitor`
/// false, then the walk will end. /// returns false, then the walk will end.
@override @override
@Deprecated('Use to visitChildren instead') @Deprecated('Use to visitChildren instead')
bool visitTextSpan(bool visitor(TextSpan span)) { bool visitTextSpan(bool visitor(TextSpan span)) {
...@@ -246,7 +254,10 @@ class TextSpan extends InlineSpan { ...@@ -246,7 +254,10 @@ class TextSpan extends InlineSpan {
} }
if (children != null) { if (children != null) {
for (InlineSpan child in children) { for (InlineSpan child in children) {
assert(child is TextSpan, 'visitTextSpan is deprecated. Use visitChildren to support InlineSpans'); assert(
child is TextSpan,
'visitTextSpan is deprecated. Use visitChildren to support InlineSpans',
);
final TextSpan textSpanChild = child; final TextSpan textSpanChild = child;
if (!textSpanChild.visitTextSpan(visitor)) if (!textSpanChild.visitTextSpan(visitor))
return false; return false;
...@@ -274,7 +285,11 @@ class TextSpan extends InlineSpan { ...@@ -274,7 +285,11 @@ class TextSpan extends InlineSpan {
} }
@override @override
void computeToPlainText(StringBuffer buffer, {bool includeSemanticsLabels = true, bool includePlaceholders = true}) { void computeToPlainText(
StringBuffer buffer, {
bool includeSemanticsLabels = true,
bool includePlaceholders = true
}) {
assert(debugAssertIsValid()); assert(debugAssertIsValid());
if (semanticsLabel != null && includeSemanticsLabels) { if (semanticsLabel != null && includeSemanticsLabels) {
buffer.write(semanticsLabel); buffer.write(semanticsLabel);
...@@ -322,7 +337,10 @@ class TextSpan extends InlineSpan { ...@@ -322,7 +337,10 @@ class TextSpan extends InlineSpan {
@override @override
void describeSemantics(Accumulator offset, List<int> semanticsOffsets, List<dynamic> semanticsElements) { void describeSemantics(Accumulator offset, List<int> semanticsOffsets, List<dynamic> semanticsElements) {
if (recognizer != null && (recognizer is TapGestureRecognizer || recognizer is LongPressGestureRecognizer)) { if (
recognizer != null &&
(recognizer is TapGestureRecognizer || recognizer is LongPressGestureRecognizer)
) {
final int length = semanticsLabel?.length ?? text.length; final int length = semanticsLabel?.length ?? text.length;
semanticsOffsets.add(offset.value); semanticsOffsets.add(offset.value);
semanticsOffsets.add(offset.value + length); semanticsOffsets.add(offset.value + length);
...@@ -331,8 +349,8 @@ class TextSpan extends InlineSpan { ...@@ -331,8 +349,8 @@ class TextSpan extends InlineSpan {
offset.increment(text != null ? text.length : 0); offset.increment(text != null ? text.length : 0);
} }
/// In checked mode, throws an exception if the object is not in a /// In checked mode, throws an exception if the object is not in a valid
/// valid configuration. Otherwise, returns true. /// configuration. Otherwise, returns true.
/// ///
/// This is intended to be used as follows: /// This is intended to be used as follows:
/// ///
...@@ -369,7 +387,9 @@ class TextSpan extends InlineSpan { ...@@ -369,7 +387,9 @@ class TextSpan extends InlineSpan {
children?.length != textSpan.children?.length || children?.length != textSpan.children?.length ||
(style == null) != (textSpan.style == null)) (style == null) != (textSpan.style == null))
return RenderComparison.layout; return RenderComparison.layout;
RenderComparison result = recognizer == textSpan.recognizer ? RenderComparison.identical : RenderComparison.metadata; RenderComparison result = recognizer == textSpan.recognizer ?
RenderComparison.identical :
RenderComparison.metadata;
if (style != null) { if (style != null) {
final RenderComparison candidate = style.compareTo(textSpan.style); final RenderComparison candidate = style.compareTo(textSpan.style);
if (candidate.index > result.index) if (candidate.index > result.index)
...@@ -405,7 +425,13 @@ class TextSpan extends InlineSpan { ...@@ -405,7 +425,13 @@ class TextSpan extends InlineSpan {
} }
@override @override
int get hashCode => hashValues(super.hashCode, text, recognizer, semanticsLabel, hashList(children)); int get hashCode => hashValues(
super.hashCode,
text,
recognizer,
semanticsLabel,
hashList(children),
);
@override @override
String toStringShort() => '$runtimeType'; String toStringShort() => '$runtimeType';
...@@ -414,7 +440,14 @@ class TextSpan extends InlineSpan { ...@@ -414,7 +440,14 @@ class TextSpan extends InlineSpan {
void debugFillProperties(DiagnosticPropertiesBuilder properties) { void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties); super.debugFillProperties(properties);
properties.add(StringProperty('text', text, showName: false, defaultValue: null)); properties.add(
StringProperty(
'text',
text,
showName: false,
defaultValue: null,
)
);
if (style == null && text == null && children == null) if (style == null && text == null && children == null)
properties.add(DiagnosticsNode.message('(empty)')); properties.add(DiagnosticsNode.message('(empty)'));
......
...@@ -110,7 +110,7 @@ class RenderParagraph extends RenderBox ...@@ -110,7 +110,7 @@ class RenderParagraph extends RenderBox
final TextPainter _textPainter; final TextPainter _textPainter;
/// The text to display /// The text to display.
InlineSpan get text => _textPainter.text; InlineSpan get text => _textPainter.text;
set text(InlineSpan value) { set text(InlineSpan value) {
assert(value != null); assert(value != null);
...@@ -220,11 +220,12 @@ class RenderParagraph extends RenderBox ...@@ -220,11 +220,12 @@ class RenderParagraph extends RenderBox
markNeedsLayout(); markNeedsLayout();
} }
/// An optional maximum number of lines for the text to span, wrapping if necessary. /// An optional maximum number of lines for the text to span, wrapping if
/// If the text exceeds the given number of lines, it will be truncated according /// necessary. If the text exceeds the given number of lines, it will be
/// to [overflow] and [softWrap]. /// truncated according to [overflow] and [softWrap].
int get maxLines => _textPainter.maxLines; int get maxLines => _textPainter.maxLines;
/// The value may be null. If it is not null, then it must be greater than zero. /// The value may be null. If it is not null, then it must be greater than
/// zero.
set maxLines(int value) { set maxLines(int value) {
assert(value == null || value > 0); assert(value == null || value > 0);
if (_textPainter.maxLines == value) if (_textPainter.maxLines == value)
...@@ -234,10 +235,11 @@ class RenderParagraph extends RenderBox ...@@ -234,10 +235,11 @@ class RenderParagraph extends RenderBox
markNeedsLayout(); markNeedsLayout();
} }
/// Used by this paragraph's internal [TextPainter] to select a locale-specific /// Used by this paragraph's internal [TextPainter] to select a
/// font. /// locale-specific font.
/// ///
/// In some cases the same Unicode character may be rendered differently depending /// In some cases the same Unicode character may be rendered differently
/// depending
/// on the locale. For example the '骨' character is rendered differently in /// on the locale. For example the '骨' character is rendered differently in
/// the Chinese and Japanese locales. In these cases the [locale] may be used /// the Chinese and Japanese locales. In these cases the [locale] may be used
/// to select a locale-specific font. /// to select a locale-specific font.
...@@ -318,11 +320,12 @@ class RenderParagraph extends RenderBox ...@@ -318,11 +320,12 @@ class RenderParagraph extends RenderBox
assert(constraints != null); assert(constraints != null);
assert(constraints.debugAssertIsValid()); assert(constraints.debugAssertIsValid());
_layoutTextWithConstraints(constraints); _layoutTextWithConstraints(constraints);
// TODO(garyq): Since our metric for ideographic baseline is currently inacurrate // TODO(garyq): Since our metric for ideographic baseline is currently
// and the non-alphabetic baselines are based off of the alphabetic baseline, we // inaccurate and the non-alphabetic baselines are based off of the
// use the alphabetic for now to produce correct layouts. We should eventually change // alphabetic baseline, we use the alphabetic for now to produce correct
// this back to pass the `baseline` property when the ideographic baseline is properly // layouts. We should eventually change this back to pass the `baseline`
// implemented (https://github.com/flutter/flutter/issues/22625). // property when the ideographic baseline is properly implemented
// (https://github.com/flutter/flutter/issues/22625).
return _textPainter.computeDistanceToActualBaseline(TextBaseline.alphabetic); return _textPainter.computeDistanceToActualBaseline(TextBaseline.alphabetic);
} }
...@@ -412,8 +415,15 @@ class RenderParagraph extends RenderBox ...@@ -412,8 +415,15 @@ class RenderParagraph extends RenderBox
RenderBox child = firstChild; RenderBox child = firstChild;
while (child != null) { while (child != null) {
final TextParentData textParentData = child.parentData; final TextParentData textParentData = child.parentData;
final Matrix4 transform = Matrix4.translationValues(textParentData.offset.dx, textParentData.offset.dy, 0.0) final Matrix4 transform = Matrix4.translationValues(
..scale(textParentData.scale, textParentData.scale, textParentData.scale); textParentData.offset.dx,
textParentData.offset.dy,
0.0,
)..scale(
textParentData.scale,
textParentData.scale,
textParentData.scale,
);
final bool isHit = result.addWithPaintTransform( final bool isHit = result.addWithPaintTransform(
transform: transform, transform: transform,
position: position, position: position,
...@@ -464,7 +474,12 @@ class RenderParagraph extends RenderBox ...@@ -464,7 +474,12 @@ class RenderParagraph extends RenderBox
void _layoutText({ double minWidth = 0.0, double maxWidth = double.infinity }) { void _layoutText({ double minWidth = 0.0, double maxWidth = double.infinity }) {
final bool widthMatters = softWrap || overflow == TextOverflow.ellipsis; final bool widthMatters = softWrap || overflow == TextOverflow.ellipsis;
_textPainter.layout(minWidth: minWidth, maxWidth: widthMatters ? maxWidth : double.infinity); _textPainter.layout(
minWidth: minWidth,
maxWidth: widthMatters ?
maxWidth :
double.infinity,
);
} }
@override @override
...@@ -500,7 +515,9 @@ class RenderParagraph extends RenderBox ...@@ -500,7 +515,9 @@ class RenderParagraph extends RenderBox
double baselineOffset; double baselineOffset;
switch (_placeholderSpans[childIndex].alignment) { switch (_placeholderSpans[childIndex].alignment) {
case ui.PlaceholderAlignment.baseline: { case ui.PlaceholderAlignment.baseline: {
baselineOffset = child.getDistanceToBaseline(_placeholderSpans[childIndex].baseline); baselineOffset = child.getDistanceToBaseline(
_placeholderSpans[childIndex].baseline
);
break; break;
} }
default: { default: {
...@@ -618,11 +635,11 @@ class RenderParagraph extends RenderBox ...@@ -618,11 +635,11 @@ class RenderParagraph extends RenderBox
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
// Ideally we could compute the min/max intrinsic width/height with a // Ideally we could compute the min/max intrinsic width/height with a
// non-destructive operation. However, currently, computing these values // non-destructive operation. However, currently, computing these values
// will destroy state inside the painter. If that happens, we need to // will destroy state inside the painter. If that happens, we need to get
// get back the correct state by calling _layout again. // back the correct state by calling _layout again.
// //
// TODO(abarth): Make computing the min/max intrinsic width/height // TODO(abarth): Make computing the min/max intrinsic width/height a
// a non-destructive operation. // non-destructive operation.
// //
// If you remove this call, make sure that changing the textAlign still // If you remove this call, make sure that changing the textAlign still
// works properly. // works properly.
...@@ -640,8 +657,8 @@ class RenderParagraph extends RenderBox ...@@ -640,8 +657,8 @@ class RenderParagraph extends RenderBox
if (_needsClipping) { if (_needsClipping) {
final Rect bounds = offset & size; final Rect bounds = offset & size;
if (_overflowShader != null) { if (_overflowShader != null) {
// This layer limits what the shader below blends with to be just the text // This layer limits what the shader below blends with to be just the
// (as opposed to the text and its background). // text (as opposed to the text and its background).
context.canvas.saveLayer(bounds, Paint()); context.canvas.saveLayer(bounds, Paint());
} else { } else {
context.canvas.save(); context.canvas.save();
...@@ -819,7 +836,10 @@ class RenderParagraph extends RenderBox ...@@ -819,7 +836,10 @@ class RenderParagraph extends RenderBox
RenderBox child = firstChild; RenderBox child = firstChild;
for (InlineSpanSemanticsInformation info in _combineSemanticsInfo()) { for (InlineSpanSemanticsInformation info in _combineSemanticsInfo()) {
final TextDirection initialDirection = currentDirection; final TextDirection initialDirection = currentDirection;
final TextSelection selection = TextSelection(baseOffset: start, extentOffset: start + info.text.length); final TextSelection selection = TextSelection(
baseOffset: start,
extentOffset: start + info.text.length,
);
final List<ui.TextBox> rects = getBoxesForSelection(selection); final List<ui.TextBox> rects = getBoxesForSelection(selection);
if (rects.isEmpty) { if (rects.isEmpty) {
continue; continue;
...@@ -887,7 +907,12 @@ class RenderParagraph extends RenderBox ...@@ -887,7 +907,12 @@ class RenderParagraph extends RenderBox
@override @override
List<DiagnosticsNode> debugDescribeChildren() { List<DiagnosticsNode> debugDescribeChildren() {
return <DiagnosticsNode>[text.toDiagnosticsNode(name: 'text', style: DiagnosticsTreeStyle.transition)]; return <DiagnosticsNode>[
text.toDiagnosticsNode(
name: 'text',
style: DiagnosticsTreeStyle.transition,
)
];
} }
@override @override
...@@ -895,10 +920,30 @@ class RenderParagraph extends RenderBox ...@@ -895,10 +920,30 @@ class RenderParagraph extends RenderBox
super.debugFillProperties(properties); super.debugFillProperties(properties);
properties.add(EnumProperty<TextAlign>('textAlign', textAlign)); properties.add(EnumProperty<TextAlign>('textAlign', textAlign));
properties.add(EnumProperty<TextDirection>('textDirection', textDirection)); properties.add(EnumProperty<TextDirection>('textDirection', textDirection));
properties.add(FlagProperty('softWrap', value: softWrap, ifTrue: 'wrapping at box width', ifFalse: 'no wrapping except at line break characters', showName: true)); properties.add(
FlagProperty(
'softWrap',
value: softWrap,
ifTrue: 'wrapping at box width',
ifFalse: 'no wrapping except at line break characters',
showName: true,
)
);
properties.add(EnumProperty<TextOverflow>('overflow', overflow)); properties.add(EnumProperty<TextOverflow>('overflow', overflow));
properties.add(DoubleProperty('textScaleFactor', textScaleFactor, defaultValue: 1.0)); properties.add(
properties.add(DiagnosticsProperty<Locale>('locale', locale, defaultValue: null)); DoubleProperty(
'textScaleFactor',
textScaleFactor,
defaultValue: 1.0,
)
);
properties.add(
DiagnosticsProperty<Locale>(
'locale',
locale,
defaultValue: null,
)
);
properties.add(IntProperty('maxLines', maxLines, ifNull: 'unlimited')); properties.add(IntProperty('maxLines', maxLines, ifNull: 'unlimited'));
} }
} }
...@@ -46,7 +46,11 @@ void main() { ...@@ -46,7 +46,11 @@ void main() {
expect(baseSize.height, equals(14.0)); expect(baseSize.height, equals(14.0));
await tester.pumpWidget(const Center( await tester.pumpWidget(const Center(
child: Text('Hello', textScaleFactor: 1.5, textDirection: TextDirection.ltr), child: Text(
'Hello',
textScaleFactor: 1.5,
textDirection: TextDirection.ltr,
),
)); ));
text = tester.firstWidget(find.byType(RichText)); text = tester.firstWidget(find.byType(RichText));
...@@ -102,8 +106,14 @@ void main() { ...@@ -102,8 +106,14 @@ void main() {
TextSpan( TextSpan(
text: 'Hello', text: 'Hello',
children: <TextSpan>[ children: <TextSpan>[
TextSpan(text: ' beautiful ', style: TextStyle(fontStyle: FontStyle.italic)), TextSpan(
TextSpan(text: 'world', style: TextStyle(fontWeight: FontWeight.bold)), text: ' beautiful ',
style: TextStyle(fontStyle: FontStyle.italic),
),
TextSpan(
text: 'world',
style: TextStyle(fontWeight: FontWeight.bold),
),
], ],
), ),
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
...@@ -123,7 +133,9 @@ void main() { ...@@ -123,7 +133,9 @@ void main() {
Text.rich( Text.rich(
TextSpan( TextSpan(
children: <InlineSpan>[ children: <InlineSpan>[
const TextSpan(text: 'a very very very very very very very very very very long line'), const TextSpan(
text: 'a very very very very very very very very very very long line',
),
WidgetSpan( WidgetSpan(
child: SizedBox( child: SizedBox(
width: 20, width: 20,
...@@ -150,7 +162,11 @@ void main() { ...@@ -150,7 +162,11 @@ void main() {
testWidgets('semanticsLabel can override text label', (WidgetTester tester) async { testWidgets('semanticsLabel can override text label', (WidgetTester tester) async {
final SemanticsTester semantics = SemanticsTester(tester); final SemanticsTester semantics = SemanticsTester(tester);
await tester.pumpWidget( await tester.pumpWidget(
const Text('\$\$', semanticsLabel: 'Double dollars', textDirection: TextDirection.ltr) const Text(
'\$\$',
semanticsLabel: 'Double dollars',
textDirection: TextDirection.ltr,
)
); );
final TestSemantics expectedSemantics = TestSemantics.root( final TestSemantics expectedSemantics = TestSemantics.root(
children: <TestSemantics>[ children: <TestSemantics>[
...@@ -160,7 +176,15 @@ void main() { ...@@ -160,7 +176,15 @@ void main() {
), ),
], ],
); );
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true, ignoreRect: true)); expect(
semantics,
hasSemantics(
expectedSemantics,
ignoreTransform: true,
ignoreId: true,
ignoreRect: true,
),
);
await tester.pumpWidget( await tester.pumpWidget(
const Directionality( const Directionality(
...@@ -168,7 +192,15 @@ void main() { ...@@ -168,7 +192,15 @@ void main() {
child: Text('\$\$', semanticsLabel: 'Double dollars')), child: Text('\$\$', semanticsLabel: 'Double dollars')),
); );
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true, ignoreRect: true)); expect(
semantics,
hasSemantics(
expectedSemantics,
ignoreTransform: true,
ignoreId: true,
ignoreRect: true,
),
);
semantics.dispose(); semantics.dispose();
}); });
...@@ -206,7 +238,15 @@ void main() { ...@@ -206,7 +238,15 @@ void main() {
), ),
], ],
); );
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true, ignoreRect: true)); expect(
semantics,
hasSemantics(
expectedSemantics,
ignoreTransform: true,
ignoreId: true,
ignoreRect: true,
),
);
semantics.dispose(); semantics.dispose();
}); });
...@@ -218,7 +258,10 @@ void main() { ...@@ -218,7 +258,10 @@ void main() {
TextSpan( TextSpan(
children: <TextSpan>[ children: <TextSpan>[
const TextSpan(text: 'hello '), const TextSpan(text: 'hello '),
TextSpan(text: 'world', recognizer: TapGestureRecognizer()..onTap = () { }), TextSpan(
text: 'world',
recognizer: TapGestureRecognizer()..onTap = () { },
),
const TextSpan(text: ' this is a '), const TextSpan(text: ' this is a '),
const TextSpan(text: 'cat-astrophe'), const TextSpan(text: 'cat-astrophe'),
], ],
...@@ -250,7 +293,15 @@ void main() { ...@@ -250,7 +293,15 @@ void main() {
), ),
], ],
); );
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true, ignoreRect: true)); expect(
semantics,
hasSemantics(
expectedSemantics,
ignoreTransform: true,
ignoreId: true,
ignoreRect: true,
),
);
semantics.dispose(); semantics.dispose();
}); });
...@@ -264,7 +315,10 @@ void main() { ...@@ -264,7 +315,10 @@ void main() {
TextSpan( TextSpan(
children: <TextSpan>[ children: <TextSpan>[
const TextSpan(text: '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'), const TextSpan(text: '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n'),
TextSpan(text: 'world', recognizer: TapGestureRecognizer()..onTap = () { }), TextSpan(
text: 'world',
recognizer: TapGestureRecognizer()..onTap = () { },
),
], ],
style: textStyle, style: textStyle,
), ),
...@@ -289,7 +343,15 @@ void main() { ...@@ -289,7 +343,15 @@ void main() {
), ),
], ],
); );
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true, ignoreRect: true)); expect(
semantics,
hasSemantics(
expectedSemantics,
ignoreTransform: true,
ignoreId: true,
ignoreRect: true,
),
);
semantics.dispose(); semantics.dispose();
}); });
...@@ -301,9 +363,15 @@ void main() { ...@@ -301,9 +363,15 @@ void main() {
TextSpan( TextSpan(
children: <TextSpan>[ children: <TextSpan>[
const TextSpan(text: 'hello '), const TextSpan(text: 'hello '),
TextSpan(text: 'world', recognizer: TapGestureRecognizer()..onTap = () { }), TextSpan(
text: 'world',
recognizer: TapGestureRecognizer()..onTap = () { },
),
const TextSpan(text: ' this is a '), const TextSpan(text: ' this is a '),
const TextSpan(text: 'cat-astrophe', semanticsLabel: 'regrettable event'), const TextSpan(
text: 'cat-astrophe',
semanticsLabel: 'regrettable event',
),
], ],
style: textStyle, style: textStyle,
), ),
...@@ -333,7 +401,15 @@ void main() { ...@@ -333,7 +401,15 @@ void main() {
), ),
], ],
); );
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true, ignoreRect: true)); expect(
semantics,
hasSemantics(
expectedSemantics,
ignoreTransform: true,
ignoreId: true,
ignoreRect: true,
),
);
semantics.dispose(); semantics.dispose();
}, skip: isBrowser); }, skip: isBrowser);
...@@ -347,9 +423,15 @@ void main() { ...@@ -347,9 +423,15 @@ void main() {
style: textStyle, style: textStyle,
children: <TextSpan>[ children: <TextSpan>[
const TextSpan(text: 'hello world${Unicode.RLE}${Unicode.RLO} '), const TextSpan(text: 'hello world${Unicode.RLE}${Unicode.RLO} '),
TextSpan(text: 'BOY', recognizer: LongPressGestureRecognizer()..onLongPress = () { }), TextSpan(
text: 'BOY',
recognizer: LongPressGestureRecognizer()..onLongPress = () { },
),
const TextSpan(text: ' HOW DO${Unicode.PDF} you ${Unicode.RLO} DO '), const TextSpan(text: ' HOW DO${Unicode.PDF} you ${Unicode.RLO} DO '),
TextSpan(text: 'SIR', recognizer: TapGestureRecognizer()..onTap = () { }), TextSpan(
text: 'SIR',
recognizer: TapGestureRecognizer()..onTap = () { },
),
const TextSpan(text: '${Unicode.PDF}${Unicode.PDF} good bye'), const TextSpan(text: '${Unicode.PDF}${Unicode.PDF} good bye'),
], ],
), ),
...@@ -398,7 +480,14 @@ void main() { ...@@ -398,7 +480,14 @@ void main() {
), ),
], ],
); );
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true)); expect(
semantics,
hasSemantics(
expectedSemantics,
ignoreTransform: true,
ignoreId: true,
),
);
semantics.dispose(); semantics.dispose();
}, skip: true); // TODO(jonahwilliams): correct once https://github.com/flutter/flutter/issues/20891 is resolved. }, skip: true); // TODO(jonahwilliams): correct once https://github.com/flutter/flutter/issues/20891 is resolved.
...@@ -410,7 +499,10 @@ void main() { ...@@ -410,7 +499,10 @@ void main() {
TextSpan( TextSpan(
children: <InlineSpan>[ children: <InlineSpan>[
const TextSpan(text: 'a '), const TextSpan(text: 'a '),
TextSpan(text: 'pebble', recognizer: TapGestureRecognizer()..onTap = () { }), TextSpan(
text: 'pebble',
recognizer: TapGestureRecognizer()..onTap = () { },
),
const TextSpan(text: ' in the '), const TextSpan(text: ' in the '),
WidgetSpan( WidgetSpan(
child: SizedBox( child: SizedBox(
...@@ -462,7 +554,15 @@ void main() { ...@@ -462,7 +554,15 @@ void main() {
), ),
], ],
); );
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true, ignoreRect: true)); expect(
semantics,
hasSemantics(
expectedSemantics,
ignoreTransform: true,
ignoreId: true,
ignoreRect: true,
),
);
semantics.dispose(); semantics.dispose();
}, skip: isBrowser); }, skip: isBrowser);
...@@ -474,7 +574,10 @@ void main() { ...@@ -474,7 +574,10 @@ void main() {
TextSpan( TextSpan(
children: <InlineSpan>[ children: <InlineSpan>[
const TextSpan(text: 'a '), const TextSpan(text: 'a '),
TextSpan(text: 'pebble', recognizer: TapGestureRecognizer()..onTap = () { }), TextSpan(
text: 'pebble',
recognizer: TapGestureRecognizer()..onTap = () { },
),
const TextSpan(text: ' in the '), const TextSpan(text: ' in the '),
WidgetSpan( WidgetSpan(
child: SizedBox( child: SizedBox(
...@@ -533,7 +636,14 @@ void main() { ...@@ -533,7 +636,14 @@ void main() {
), ),
], ],
); );
expect(semantics, hasSemantics(expectedSemantics, ignoreTransform: true, ignoreId: true,)); expect(
semantics,
hasSemantics(
expectedSemantics,
ignoreTransform: true,
ignoreId: true,
),
);
semantics.dispose(); semantics.dispose();
}, skip: isBrowser); }, skip: isBrowser);
...@@ -554,7 +664,10 @@ void main() { ...@@ -554,7 +664,10 @@ void main() {
text: 'a long long long long text, should be clip', text: 'a long long long long text, should be clip',
); );
expect(find.byType(Text), paints..clipRect(rect: const Rect.fromLTWH(0, 0, 50, 50))); expect(
find.byType(Text),
paints..clipRect(rect: const Rect.fromLTWH(0, 0, 50, 50)),
);
}, skip: isBrowser); }, skip: isBrowser);
testWidgets('Overflow is clipping correctly - short text with overflow: ellipsis', (WidgetTester tester) async { testWidgets('Overflow is clipping correctly - short text with overflow: ellipsis', (WidgetTester tester) async {
...@@ -574,7 +687,10 @@ void main() { ...@@ -574,7 +687,10 @@ void main() {
text: 'a long long long long text, should be clip', text: 'a long long long long text, should be clip',
); );
expect(find.byType(Text), paints..clipRect(rect: const Rect.fromLTWH(0, 0, 50, 50))); expect(
find.byType(Text),
paints..clipRect(rect: const Rect.fromLTWH(0, 0, 50, 50)),
);
}); });
testWidgets('Overflow is clipping correctly - short text with overflow: fade', (WidgetTester tester) async { testWidgets('Overflow is clipping correctly - short text with overflow: fade', (WidgetTester tester) async {
...@@ -616,7 +732,9 @@ void main() { ...@@ -616,7 +732,9 @@ void main() {
child: Container( child: Container(
// Each word takes up more than a half of a line. Together they // Each word takes up more than a half of a line. Together they
// wrap onto two lines, but leave a lot of extra space. // wrap onto two lines, but leave a lot of extra space.
child: Text('twowordsthateachtakeupmorethanhalfof alineoftextsothattheywrapwithlotsofextraspace', child: Text(
'twowordsthateachtakeupmorethanhalfof alineoftextsothattheywr'
'apwithlotsofextraspace',
textDirection: TextDirection.ltr, textDirection: TextDirection.ltr,
textWidthBasis: textWidthBasis, textWidthBasis: textWidthBasis,
), ),
......
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