Commit e2070ba3 authored by Dragoș Tiselice's avatar Dragoș Tiselice Committed by GitHub

Improved debug validations. (#5822)

This commit renames all debugAssertValid methods to
debugAssertIsValid and assert BoxConstaints validity in
constructors. Fixes #5807.
parent 718a88d0
...@@ -1045,10 +1045,10 @@ class BoxDecoration extends Decoration { ...@@ -1045,10 +1045,10 @@ class BoxDecoration extends Decoration {
}); });
@override @override
bool debugAssertValid() { bool debugAssertIsValid() {
assert(shape != BoxShape.circle || assert(shape != BoxShape.circle ||
borderRadius == null); // Can't have a border radius if you're a 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. /// The color to fill in the background of the box.
......
...@@ -33,9 +33,9 @@ abstract class Decoration { ...@@ -33,9 +33,9 @@ abstract class Decoration {
/// ///
/// This is intended to be used as follows: /// This is intended to be used as follows:
/// ```dart /// ```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 /// Returns the insets to apply when using this decoration on a box
/// that has contents, so that the contents do not overlap the edges /// that has contents, so that the contents do not overlap the edges
......
...@@ -97,7 +97,7 @@ class FlutterLogoDecoration extends Decoration { ...@@ -97,7 +97,7 @@ class FlutterLogoDecoration extends Decoration {
bool get _inTransition => _opacity != 1.0 || (_position != -1.0 && _position != 0.0 && _position != 1.0); bool get _inTransition => _opacity != 1.0 || (_position != -1.0 && _position != 0.0 && _position != 1.0);
@override @override
bool debugAssertValid() { bool debugAssertIsValid() {
assert(swatch != null assert(swatch != null
&& swatch[_lightShade] != null && swatch[_lightShade] != null
&& swatch[_darkShade] != null && swatch[_darkShade] != null
...@@ -121,8 +121,8 @@ class FlutterLogoDecoration extends Decoration { ...@@ -121,8 +121,8 @@ class FlutterLogoDecoration extends Decoration {
/// ///
/// See also [Decoration.lerp]. /// See also [Decoration.lerp].
static FlutterLogoDecoration lerp(FlutterLogoDecoration a, FlutterLogoDecoration b, double t) { static FlutterLogoDecoration lerp(FlutterLogoDecoration a, FlutterLogoDecoration b, double t) {
assert(a == null || a.debugAssertValid()); assert(a == null || a.debugAssertIsValid());
assert(b == null || b.debugAssertValid()); assert(b == null || b.debugAssertIsValid());
if (a == null && b == null) if (a == null && b == null)
return null; return null;
if (a == null) { if (a == null) {
...@@ -166,19 +166,19 @@ class FlutterLogoDecoration extends Decoration { ...@@ -166,19 +166,19 @@ class FlutterLogoDecoration extends Decoration {
@override @override
FlutterLogoDecoration lerpFrom(Decoration a, double t) { FlutterLogoDecoration lerpFrom(Decoration a, double t) {
assert(debugAssertValid()); assert(debugAssertIsValid());
if (a is! FlutterLogoDecoration) if (a is! FlutterLogoDecoration)
return lerp(null, this, t); return lerp(null, this, t);
assert(a.debugAssertValid); assert(a.debugAssertIsValid);
return lerp(a, this, t); return lerp(a, this, t);
} }
@override @override
FlutterLogoDecoration lerpTo(Decoration b, double t) { FlutterLogoDecoration lerpTo(Decoration b, double t) {
assert(debugAssertValid()); assert(debugAssertIsValid());
if (b is! FlutterLogoDecoration) if (b is! FlutterLogoDecoration)
return lerp(this, null, t); return lerp(this, null, t);
assert(b.debugAssertValid()); assert(b.debugAssertIsValid());
return lerp(this, b, t); return lerp(this, b, t);
} }
...@@ -188,13 +188,13 @@ class FlutterLogoDecoration extends Decoration { ...@@ -188,13 +188,13 @@ class FlutterLogoDecoration extends Decoration {
@override @override
BoxPainter createBoxPainter([VoidCallback onChanged]) { BoxPainter createBoxPainter([VoidCallback onChanged]) {
assert(debugAssertValid()); assert(debugAssertIsValid());
return new _FlutterLogoPainter(this); return new _FlutterLogoPainter(this);
} }
@override @override
bool operator ==(dynamic other) { bool operator ==(dynamic other) {
assert(debugAssertValid()); assert(debugAssertIsValid());
if (identical(this, other)) if (identical(this, other))
return true; return true;
if (other is! FlutterLogoDecoration) if (other is! FlutterLogoDecoration)
...@@ -209,7 +209,7 @@ class FlutterLogoDecoration extends Decoration { ...@@ -209,7 +209,7 @@ class FlutterLogoDecoration extends Decoration {
@override @override
int get hashCode { int get hashCode {
assert(debugAssertValid()); assert(debugAssertIsValid());
return hashValues( return hashValues(
swatch[_lightShade], swatch[_lightShade],
swatch[_darkShade], swatch[_darkShade],
...@@ -233,7 +233,7 @@ class FlutterLogoDecoration extends Decoration { ...@@ -233,7 +233,7 @@ class FlutterLogoDecoration extends Decoration {
class _FlutterLogoPainter extends BoxPainter { class _FlutterLogoPainter extends BoxPainter {
_FlutterLogoPainter(this._config) : super(null) { _FlutterLogoPainter(this._config) : super(null) {
assert(_config != null); assert(_config != null);
assert(_config.debugAssertValid()); assert(_config.debugAssertIsValid());
_prepareText(); _prepareText();
} }
......
...@@ -34,7 +34,7 @@ class TextPainter { ...@@ -34,7 +34,7 @@ class TextPainter {
TextSpan text, TextSpan text,
TextAlign textAlign TextAlign textAlign
}) : _text = text, _textAlign = textAlign { }) : _text = text, _textAlign = textAlign {
assert(text == null || text.debugAssertValid()); assert(text == null || text.debugAssertIsValid());
} }
ui.Paragraph _paragraph; ui.Paragraph _paragraph;
...@@ -44,7 +44,7 @@ class TextPainter { ...@@ -44,7 +44,7 @@ class TextPainter {
TextSpan get text => _text; TextSpan get text => _text;
TextSpan _text; TextSpan _text;
set text(TextSpan value) { set text(TextSpan value) {
assert(value == null || value.debugAssertValid()); assert(value == null || value.debugAssertIsValid());
if (_text == value) if (_text == value)
return; return;
_text = value; _text = value;
......
...@@ -94,7 +94,7 @@ class TextSpan { ...@@ -94,7 +94,7 @@ class TextSpan {
/// [TextPainter] class to paint [TextSpan] objects onto [Canvas] /// [TextPainter] class to paint [TextSpan] objects onto [Canvas]
/// objects. /// objects.
void build(ui.ParagraphBuilder builder) { void build(ui.ParagraphBuilder builder) {
assert(debugAssertValid()); assert(debugAssertIsValid());
final bool hasStyle = style != null; final bool hasStyle = style != null;
if (hasStyle) if (hasStyle)
builder.pushStyle(style.textStyle); builder.pushStyle(style.textStyle);
...@@ -127,7 +127,7 @@ class TextSpan { ...@@ -127,7 +127,7 @@ class TextSpan {
/// Returns the text span that contains the given position in the text. /// Returns the text span that contains the given position in the text.
TextSpan getSpanForPosition(TextPosition position) { TextSpan getSpanForPosition(TextPosition position) {
assert(debugAssertValid()); assert(debugAssertIsValid());
TextAffinity affinity = position.affinity; TextAffinity affinity = position.affinity;
int targetOffset = position.offset; int targetOffset = position.offset;
int offset = 0; int offset = 0;
...@@ -151,7 +151,7 @@ class TextSpan { ...@@ -151,7 +151,7 @@ class TextSpan {
/// ///
/// Styles are not honored in this process. /// Styles are not honored in this process.
String toPlainText() { String toPlainText() {
assert(debugAssertValid()); assert(debugAssertIsValid());
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
visitTextSpan((TextSpan span) { visitTextSpan((TextSpan span) {
buffer.write(span.text); buffer.write(span.text);
...@@ -188,9 +188,9 @@ class TextSpan { ...@@ -188,9 +188,9 @@ class TextSpan {
/// ///
/// This is intended to be used as follows: /// This is intended to be used as follows:
/// ```dart /// ```dart
/// assert(myTextSpan.debugAssertValid()); /// assert(myTextSpan.debugAssertIsValid());
/// ``` /// ```
bool debugAssertValid() { bool debugAssertIsValid() {
assert(() { assert(() {
if (!visitTextSpan((TextSpan span) { if (!visitTextSpan((TextSpan span) {
if (span.children != null) { if (span.children != null) {
......
...@@ -35,7 +35,7 @@ class RenderParagraph extends RenderBox { ...@@ -35,7 +35,7 @@ class RenderParagraph extends RenderBox {
_overflow = overflow, _overflow = overflow,
_textPainter = new TextPainter(text: text, textAlign: textAlign) { _textPainter = new TextPainter(text: text, textAlign: textAlign) {
assert(text != null); assert(text != null);
assert(text.debugAssertValid()); assert(text.debugAssertIsValid());
assert(overflow != null); assert(overflow != null);
assert(softWrap != null); assert(softWrap != null);
} }
......
...@@ -794,6 +794,7 @@ class ConstrainedBox extends SingleChildRenderObjectWidget { ...@@ -794,6 +794,7 @@ class ConstrainedBox extends SingleChildRenderObjectWidget {
Widget child Widget child
}) : super(key: key, child: child) { }) : super(key: key, child: child) {
assert(constraints != null); assert(constraints != null);
assert(constraints.debugAssertIsValid());
} }
/// The additional constraints to impose on the child. /// The additional constraints to impose on the child.
......
...@@ -94,7 +94,8 @@ class Container extends StatelessWidget { ...@@ -94,7 +94,8 @@ class Container extends StatelessWidget {
super(key: key) { super(key: key) {
assert(margin == null || margin.isNonNegative); assert(margin == null || margin.isNonNegative);
assert(padding == null || padding.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. /// The child contained by the container.
......
...@@ -235,10 +235,11 @@ class AnimatedContainer extends ImplicitlyAnimatedWidget { ...@@ -235,10 +235,11 @@ class AnimatedContainer extends ImplicitlyAnimatedWidget {
Curve curve: Curves.linear, Curve curve: Curves.linear,
@required Duration duration @required Duration duration
}) : super(key: key, curve: curve, duration: duration) { }) : super(key: key, curve: curve, duration: duration) {
assert(decoration == null || decoration.debugAssertValid()); assert(decoration == null || decoration.debugAssertIsValid());
assert(foregroundDecoration == null || foregroundDecoration.debugAssertValid()); assert(foregroundDecoration == null || foregroundDecoration.debugAssertIsValid());
assert(margin == null || margin.isNonNegative); assert(margin == null || margin.isNonNegative);
assert(padding == null || padding.isNonNegative); assert(padding == null || padding.isNonNegative);
assert(constraints == null || constraints.debugAssertIsValid());
} }
/// The widget below this widget in the tree. /// The widget below this widget in the tree.
......
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