Unverified Commit 8769f94c authored by Gary Qian's avatar Gary Qian Committed by GitHub

Add textHeightBehavior and textWidthBasis to AnimatedDefaultTextStyle (#50748)

parent f4177a6d
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' as ui show TextHeightBehavior;
import 'package:flutter/animation.dart'; import 'package:flutter/animation.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:vector_math/vector_math_64.dart'; import 'package:vector_math/vector_math_64.dart';
...@@ -1502,8 +1505,9 @@ class _SliverAnimatedOpacityState extends ImplicitlyAnimatedWidgetState<SliverAn ...@@ -1502,8 +1505,9 @@ class _SliverAnimatedOpacityState extends ImplicitlyAnimatedWidgetState<SliverAn
/// without explicit style) over a given duration whenever the given style /// without explicit style) over a given duration whenever the given style
/// changes. /// changes.
/// ///
/// The [textAlign], [softWrap], [textOverflow], and [maxLines] properties are /// The [textAlign], [softWrap], [textOverflow], [maxLines], [textWidthBasis]
/// not animated and take effect immediately when changed. /// and [textHeightBehavior] properties are not animated and take effect
/// immediately when changed.
/// ///
/// Here's an illustration of what using this widget looks like, using a [curve] /// Here's an illustration of what using this widget looks like, using a [curve]
/// of [Curves.elasticInOut]. /// of [Curves.elasticInOut].
...@@ -1529,6 +1533,8 @@ class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget { ...@@ -1529,6 +1533,8 @@ class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget {
this.softWrap = true, this.softWrap = true,
this.overflow = TextOverflow.clip, this.overflow = TextOverflow.clip,
this.maxLines, this.maxLines,
this.textWidthBasis = TextWidthBasis.parent,
this.textHeightBehavior,
Curve curve = Curves.linear, Curve curve = Curves.linear,
@required Duration duration, @required Duration duration,
VoidCallback onEnd, VoidCallback onEnd,
...@@ -1537,6 +1543,7 @@ class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget { ...@@ -1537,6 +1543,7 @@ class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget {
assert(softWrap != null), assert(softWrap != null),
assert(overflow != null), assert(overflow != null),
assert(maxLines == null || maxLines > 0), assert(maxLines == null || maxLines > 0),
assert(textWidthBasis != null),
super(key: key, curve: curve, duration: duration, onEnd: onEnd); super(key: key, curve: curve, duration: duration, onEnd: onEnd);
/// The widget below this widget in the tree. /// The widget below this widget in the tree.
...@@ -1575,6 +1582,14 @@ class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget { ...@@ -1575,6 +1582,14 @@ class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget {
/// See [DefaultTextStyle.maxLines] for more details. /// See [DefaultTextStyle.maxLines] for more details.
final int maxLines; final int maxLines;
/// The strategy to use when calculating the width of the Text.
///
/// See [TextWidthBasis] for possible values and their implications.
final TextWidthBasis textWidthBasis;
/// {@macro flutter.dart:ui.textHeightBehavior}
final ui.TextHeightBehavior textHeightBehavior;
@override @override
_AnimatedDefaultTextStyleState createState() => _AnimatedDefaultTextStyleState(); _AnimatedDefaultTextStyleState createState() => _AnimatedDefaultTextStyleState();
...@@ -1586,6 +1601,8 @@ class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget { ...@@ -1586,6 +1601,8 @@ class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget {
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, defaultValue: null)); properties.add(EnumProperty<TextOverflow>('overflow', overflow, defaultValue: null));
properties.add(IntProperty('maxLines', maxLines, defaultValue: null)); properties.add(IntProperty('maxLines', maxLines, defaultValue: null));
properties.add(EnumProperty<TextWidthBasis>('textWidthBasis', textWidthBasis, defaultValue: TextWidthBasis.parent));
properties.add(DiagnosticsProperty<ui.TextHeightBehavior>('textHeightBehavior', textHeightBehavior, defaultValue: null));
} }
} }
...@@ -1605,6 +1622,8 @@ class _AnimatedDefaultTextStyleState extends AnimatedWidgetBaseState<AnimatedDef ...@@ -1605,6 +1622,8 @@ class _AnimatedDefaultTextStyleState extends AnimatedWidgetBaseState<AnimatedDef
softWrap: widget.softWrap, softWrap: widget.softWrap,
overflow: widget.overflow, overflow: widget.overflow,
maxLines: widget.maxLines, maxLines: widget.maxLines,
textWidthBasis: widget.textWidthBasis,
textHeightBehavior: widget.textHeightBehavior,
child: widget.child, child: widget.child,
); );
} }
......
...@@ -2,8 +2,11 @@ ...@@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:ui' as ui show TextHeightBehavior;
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter/painting.dart';
void main() { void main() {
testWidgets('DefaultTextStyle changes propagate to Text', (WidgetTester tester) async { testWidgets('DefaultTextStyle changes propagate to Text', (WidgetTester tester) async {
...@@ -67,6 +70,8 @@ void main() { ...@@ -67,6 +70,8 @@ void main() {
expect(text1.softWrap, isTrue); expect(text1.softWrap, isTrue);
expect(text1.overflow, TextOverflow.clip); expect(text1.overflow, TextOverflow.clip);
expect(text1.maxLines, isNull); expect(text1.maxLines, isNull);
expect(text1.textWidthBasis, TextWidthBasis.parent);
expect(text1.textHeightBehavior, isNull);
await tester.pumpWidget(const AnimatedDefaultTextStyle( await tester.pumpWidget(const AnimatedDefaultTextStyle(
style: s2, style: s2,
...@@ -74,6 +79,8 @@ void main() { ...@@ -74,6 +79,8 @@ void main() {
softWrap: false, softWrap: false,
overflow: TextOverflow.fade, overflow: TextOverflow.fade,
maxLines: 3, maxLines: 3,
textWidthBasis: TextWidthBasis.longestLine,
textHeightBehavior: ui.TextHeightBehavior(applyHeightToFirstAscent: false),
child: textWidget, child: textWidget,
duration: Duration(milliseconds: 1000), duration: Duration(milliseconds: 1000),
)); ));
...@@ -85,6 +92,8 @@ void main() { ...@@ -85,6 +92,8 @@ void main() {
expect(text2.softWrap, false); expect(text2.softWrap, false);
expect(text2.overflow, TextOverflow.fade); expect(text2.overflow, TextOverflow.fade);
expect(text2.maxLines, 3); expect(text2.maxLines, 3);
expect(text2.textWidthBasis, TextWidthBasis.longestLine);
expect(text2.textHeightBehavior, const ui.TextHeightBehavior(applyHeightToFirstAscent: false));
await tester.pump(const Duration(milliseconds: 1000)); await tester.pump(const Duration(milliseconds: 1000));
...@@ -95,5 +104,7 @@ void main() { ...@@ -95,5 +104,7 @@ void main() {
expect(text3.softWrap, false); expect(text3.softWrap, false);
expect(text3.overflow, TextOverflow.fade); expect(text3.overflow, TextOverflow.fade);
expect(text3.maxLines, 3); expect(text3.maxLines, 3);
expect(text2.textWidthBasis, TextWidthBasis.longestLine);
expect(text2.textHeightBehavior, const ui.TextHeightBehavior(applyHeightToFirstAscent: false));
}); });
} }
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