Improved debug validations. (#5822)
This commit renames all debugAssertValid methods to debugAssertIsValid and assert BoxConstaints validity in constructors. Fixes #5807.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user