Disallow negative padding and margins

They're just as crazy in this system as they are in the web.
This commit is contained in:
Adam Barth 2015-09-04 12:25:26 -07:00
parent 4840f80242
commit dfb89fee8c
3 changed files with 7 additions and 1 deletions

View File

@ -45,6 +45,8 @@ class EdgeDims {
/// The offset from the left
final double left;
bool get isNonNegative => top >= 0.0 && right >= 0.0 && bottom >= 0.0 && left >= 0.0;
bool operator ==(other) {
if (identical(this, other))
return true;

View File

@ -79,6 +79,7 @@ class RenderPadding extends RenderShiftedBox {
EdgeDims get padding => _padding;
void set padding (EdgeDims value) {
assert(value != null);
assert(value.isNonNegative);
if (_padding == value)
return;
_padding = value;

View File

@ -393,7 +393,10 @@ class Container extends Component {
this.margin,
this.padding,
this.transform
}) : super(key: key);
}) : super(key: key) {
assert(margin == null || margin.isNonNegative);
assert(padding == null || padding.isNonNegative);
}
final Widget child;
final BoxConstraints constraints;