From 2eb26f1349864186662d411de1c0ec57c06d03d3 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Wed, 13 Dec 2017 17:13:50 -0800 Subject: [PATCH] Update AnimatedDefaultTextStyle to match DefaultTextStyle (#13531) We've added a bunch of non-animatable properties to DefaultTextStyle. This adds them to AnimatedDefaultTextStyle so that you can use them even when your text style is animating. --- .../lib/src/widgets/implicit_animations.dart | 49 +++++++++++++++- .../test/widgets/default_text_style_test.dart | 58 ++++++++++++++++++- 2 files changed, 104 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index 172e9540bc..a915028ed0 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -945,18 +945,29 @@ class _AnimatedOpacityState extends AnimatedWidgetBaseState { /// default text style (the text style to apply to descendant [Text] widgets /// without explicit style) over a given duration whenever the given style /// changes. +/// +/// The [textAlign], [softWrap], [textOverflow], and [maxLines] properties are +/// not animated and take effect immediately when changed. class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget { /// Creates a widget that animates the default text style implicitly. /// - /// The [child], [style], [curve], and [duration] arguments must not be null. + /// The [child], [style], [softWrap], [overflow], [curve], and [duration] + /// arguments must not be null. const AnimatedDefaultTextStyle({ Key key, @required this.child, @required this.style, + this.textAlign, + this.softWrap: true, + this.overflow: TextOverflow.clip, + this.maxLines, Curve curve: Curves.linear, @required Duration duration, }) : assert(style != null), assert(child != null), + assert(softWrap != null), + assert(overflow != null), + assert(maxLines == null || maxLines > 0), super(key: key, curve: curve, duration: duration); /// The widget below this widget in the tree. @@ -965,8 +976,34 @@ class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget { /// The target text style. /// /// The text style must not be null. + /// + /// When this property is changed, the style will be animated over [duration] time. final TextStyle style; + /// How the text should be aligned horizontally. + /// + /// This property takes effect immediately when changed, it is not animated. + final TextAlign textAlign; + + /// Whether the text should break at soft line breaks. + /// + /// This property takes effect immediately when changed, it is not animated. + /// + /// See [DefaultTextStyle.softWrap] for more details. + final bool softWrap; + + /// How visual overflow should be handled. + /// + /// This property takes effect immediately when changed, it is not animated. + final TextOverflow overflow; + + /// An optional maximum number of lines for the text to span, wrapping if necessary. + /// + /// This property takes effect immediately when changed, it is not animated. + /// + /// See [DefaultTextStyle.maxLines] for more details. + final int maxLines; + @override _AnimatedDefaultTextStyleState createState() => new _AnimatedDefaultTextStyleState(); @@ -974,6 +1011,10 @@ class AnimatedDefaultTextStyle extends ImplicitlyAnimatedWidget { void debugFillProperties(DiagnosticPropertiesBuilder description) { super.debugFillProperties(description); style?.debugFillProperties(description); + description.add(new EnumProperty('textAlign', textAlign, defaultValue: null)); + description.add(new FlagProperty('softWrap', value: softWrap, ifTrue: 'wrapping at box width', ifFalse: 'no wrapping except at line break characters', showName: true)); + description.add(new EnumProperty('overflow', overflow, defaultValue: null)); + description.add(new IntProperty('maxLines', maxLines, defaultValue: null)); } } @@ -989,7 +1030,11 @@ class _AnimatedDefaultTextStyleState extends AnimatedWidgetBaseState