From e2070ba317c1cbb9183128de9ce06e1ca5e5923c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Drago=C8=99=20Tiselice?= Date: Mon, 12 Sep 2016 12:27:42 -0700 Subject: [PATCH] Improved debug validations. (#5822) This commit renames all debugAssertValid methods to debugAssertIsValid and assert BoxConstaints validity in constructors. Fixes #5807. --- .../flutter/lib/src/painting/box_painter.dart | 4 ++-- .../flutter/lib/src/painting/decoration.dart | 4 ++-- .../lib/src/painting/flutter_logo.dart | 22 +++++++++---------- .../lib/src/painting/text_painter.dart | 4 ++-- .../flutter/lib/src/painting/text_span.dart | 10 ++++----- .../flutter/lib/src/rendering/paragraph.dart | 2 +- packages/flutter/lib/src/widgets/basic.dart | 1 + .../flutter/lib/src/widgets/container.dart | 3 ++- .../lib/src/widgets/implicit_animations.dart | 5 +++-- 9 files changed, 29 insertions(+), 26 deletions(-) diff --git a/packages/flutter/lib/src/painting/box_painter.dart b/packages/flutter/lib/src/painting/box_painter.dart index 500638b4c1..0a6f8f5b02 100644 --- a/packages/flutter/lib/src/painting/box_painter.dart +++ b/packages/flutter/lib/src/painting/box_painter.dart @@ -1045,10 +1045,10 @@ class BoxDecoration extends Decoration { }); @override - bool debugAssertValid() { + bool debugAssertIsValid() { assert(shape != BoxShape.circle || borderRadius == null); // Can't have a border radius if you're a circle. - return super.debugAssertValid(); + return super.debugAssertIsValid(); } /// The color to fill in the background of the box. diff --git a/packages/flutter/lib/src/painting/decoration.dart b/packages/flutter/lib/src/painting/decoration.dart index 3ff75cf8fa..8e99575a61 100644 --- a/packages/flutter/lib/src/painting/decoration.dart +++ b/packages/flutter/lib/src/painting/decoration.dart @@ -33,9 +33,9 @@ abstract class Decoration { /// /// This is intended to be used as follows: /// ```dart - /// assert(myDecoration.debugAssertValid()); + /// assert(myDecoration.debugAssertIsValid()); /// ``` - bool debugAssertValid() => true; + bool debugAssertIsValid() => true; /// Returns the insets to apply when using this decoration on a box /// that has contents, so that the contents do not overlap the edges diff --git a/packages/flutter/lib/src/painting/flutter_logo.dart b/packages/flutter/lib/src/painting/flutter_logo.dart index f848b22310..a9c99bc4db 100644 --- a/packages/flutter/lib/src/painting/flutter_logo.dart +++ b/packages/flutter/lib/src/painting/flutter_logo.dart @@ -97,7 +97,7 @@ class FlutterLogoDecoration extends Decoration { bool get _inTransition => _opacity != 1.0 || (_position != -1.0 && _position != 0.0 && _position != 1.0); @override - bool debugAssertValid() { + bool debugAssertIsValid() { assert(swatch != null && swatch[_lightShade] != null && swatch[_darkShade] != null @@ -121,8 +121,8 @@ class FlutterLogoDecoration extends Decoration { /// /// See also [Decoration.lerp]. static FlutterLogoDecoration lerp(FlutterLogoDecoration a, FlutterLogoDecoration b, double t) { - assert(a == null || a.debugAssertValid()); - assert(b == null || b.debugAssertValid()); + assert(a == null || a.debugAssertIsValid()); + assert(b == null || b.debugAssertIsValid()); if (a == null && b == null) return null; if (a == null) { @@ -166,19 +166,19 @@ class FlutterLogoDecoration extends Decoration { @override FlutterLogoDecoration lerpFrom(Decoration a, double t) { - assert(debugAssertValid()); + assert(debugAssertIsValid()); if (a is! FlutterLogoDecoration) return lerp(null, this, t); - assert(a.debugAssertValid); + assert(a.debugAssertIsValid); return lerp(a, this, t); } @override FlutterLogoDecoration lerpTo(Decoration b, double t) { - assert(debugAssertValid()); + assert(debugAssertIsValid()); if (b is! FlutterLogoDecoration) return lerp(this, null, t); - assert(b.debugAssertValid()); + assert(b.debugAssertIsValid()); return lerp(this, b, t); } @@ -188,13 +188,13 @@ class FlutterLogoDecoration extends Decoration { @override BoxPainter createBoxPainter([VoidCallback onChanged]) { - assert(debugAssertValid()); + assert(debugAssertIsValid()); return new _FlutterLogoPainter(this); } @override bool operator ==(dynamic other) { - assert(debugAssertValid()); + assert(debugAssertIsValid()); if (identical(this, other)) return true; if (other is! FlutterLogoDecoration) @@ -209,7 +209,7 @@ class FlutterLogoDecoration extends Decoration { @override int get hashCode { - assert(debugAssertValid()); + assert(debugAssertIsValid()); return hashValues( swatch[_lightShade], swatch[_darkShade], @@ -233,7 +233,7 @@ class FlutterLogoDecoration extends Decoration { class _FlutterLogoPainter extends BoxPainter { _FlutterLogoPainter(this._config) : super(null) { assert(_config != null); - assert(_config.debugAssertValid()); + assert(_config.debugAssertIsValid()); _prepareText(); } diff --git a/packages/flutter/lib/src/painting/text_painter.dart b/packages/flutter/lib/src/painting/text_painter.dart index cdcaf82fbf..23c7f159ea 100644 --- a/packages/flutter/lib/src/painting/text_painter.dart +++ b/packages/flutter/lib/src/painting/text_painter.dart @@ -34,7 +34,7 @@ class TextPainter { TextSpan text, TextAlign textAlign }) : _text = text, _textAlign = textAlign { - assert(text == null || text.debugAssertValid()); + assert(text == null || text.debugAssertIsValid()); } ui.Paragraph _paragraph; @@ -44,7 +44,7 @@ class TextPainter { TextSpan get text => _text; TextSpan _text; set text(TextSpan value) { - assert(value == null || value.debugAssertValid()); + assert(value == null || value.debugAssertIsValid()); if (_text == value) return; _text = value; diff --git a/packages/flutter/lib/src/painting/text_span.dart b/packages/flutter/lib/src/painting/text_span.dart index 08e229968f..f0d7d79571 100644 --- a/packages/flutter/lib/src/painting/text_span.dart +++ b/packages/flutter/lib/src/painting/text_span.dart @@ -94,7 +94,7 @@ class TextSpan { /// [TextPainter] class to paint [TextSpan] objects onto [Canvas] /// objects. void build(ui.ParagraphBuilder builder) { - assert(debugAssertValid()); + assert(debugAssertIsValid()); final bool hasStyle = style != null; if (hasStyle) builder.pushStyle(style.textStyle); @@ -127,7 +127,7 @@ class TextSpan { /// Returns the text span that contains the given position in the text. TextSpan getSpanForPosition(TextPosition position) { - assert(debugAssertValid()); + assert(debugAssertIsValid()); TextAffinity affinity = position.affinity; int targetOffset = position.offset; int offset = 0; @@ -151,7 +151,7 @@ class TextSpan { /// /// Styles are not honored in this process. String toPlainText() { - assert(debugAssertValid()); + assert(debugAssertIsValid()); StringBuffer buffer = new StringBuffer(); visitTextSpan((TextSpan span) { buffer.write(span.text); @@ -188,9 +188,9 @@ class TextSpan { /// /// This is intended to be used as follows: /// ```dart - /// assert(myTextSpan.debugAssertValid()); + /// assert(myTextSpan.debugAssertIsValid()); /// ``` - bool debugAssertValid() { + bool debugAssertIsValid() { assert(() { if (!visitTextSpan((TextSpan span) { if (span.children != null) { diff --git a/packages/flutter/lib/src/rendering/paragraph.dart b/packages/flutter/lib/src/rendering/paragraph.dart index 243f3d7fc4..9a10a1939f 100644 --- a/packages/flutter/lib/src/rendering/paragraph.dart +++ b/packages/flutter/lib/src/rendering/paragraph.dart @@ -35,7 +35,7 @@ class RenderParagraph extends RenderBox { _overflow = overflow, _textPainter = new TextPainter(text: text, textAlign: textAlign) { assert(text != null); - assert(text.debugAssertValid()); + assert(text.debugAssertIsValid()); assert(overflow != null); assert(softWrap != null); } diff --git a/packages/flutter/lib/src/widgets/basic.dart b/packages/flutter/lib/src/widgets/basic.dart index 22dc53e17f..6b776c438b 100644 --- a/packages/flutter/lib/src/widgets/basic.dart +++ b/packages/flutter/lib/src/widgets/basic.dart @@ -794,6 +794,7 @@ class ConstrainedBox extends SingleChildRenderObjectWidget { Widget child }) : super(key: key, child: child) { assert(constraints != null); + assert(constraints.debugAssertIsValid()); } /// The additional constraints to impose on the child. diff --git a/packages/flutter/lib/src/widgets/container.dart b/packages/flutter/lib/src/widgets/container.dart index b4431b947a..53603843f3 100644 --- a/packages/flutter/lib/src/widgets/container.dart +++ b/packages/flutter/lib/src/widgets/container.dart @@ -94,7 +94,8 @@ class Container extends StatelessWidget { super(key: key) { assert(margin == null || margin.isNonNegative); assert(padding == null || padding.isNonNegative); - assert(decoration == null || decoration.debugAssertValid()); + assert(decoration == null || decoration.debugAssertIsValid()); + assert(constraints == null || constraints.debugAssertIsValid()); } /// The child contained by the container. diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index 6eea492c65..57c13c5a07 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -235,10 +235,11 @@ class AnimatedContainer extends ImplicitlyAnimatedWidget { Curve curve: Curves.linear, @required Duration duration }) : super(key: key, curve: curve, duration: duration) { - assert(decoration == null || decoration.debugAssertValid()); - assert(foregroundDecoration == null || foregroundDecoration.debugAssertValid()); + assert(decoration == null || decoration.debugAssertIsValid()); + assert(foregroundDecoration == null || foregroundDecoration.debugAssertIsValid()); assert(margin == null || margin.isNonNegative); assert(padding == null || padding.isNonNegative); + assert(constraints == null || constraints.debugAssertIsValid()); } /// The widget below this widget in the tree.