Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
924480fc
Commit
924480fc
authored
Mar 23, 2016
by
Ian Hickson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2843 from Hixie/nan-constraints
Handle NaNs in constraints, just in case.
parents
9eb4d15c
9356c19d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
0 deletions
+63
-0
box.dart
packages/flutter/lib/src/rendering/box.dart
+23
-0
constraints_test.dart
packages/flutter/test/rendering/constraints_test.dart
+40
-0
No files found.
packages/flutter/lib/src/rendering/box.dart
View file @
924480fc
...
...
@@ -305,6 +305,29 @@ class BoxConstraints extends Constraints {
@override
bool
get
debugAssertIsNormalized
{
assert
(()
{
if
(
minWidth
.
isNaN
||
maxWidth
.
isNaN
||
minHeight
.
isNaN
||
maxHeight
.
isNaN
)
{
List
<
String
>
affectedFieldsList
=
<
String
>[];
if
(
minWidth
.
isNaN
)
affectedFieldsList
.
add
(
'minWidth'
);
if
(
maxWidth
.
isNaN
)
affectedFieldsList
.
add
(
'maxWidth'
);
if
(
minHeight
.
isNaN
)
affectedFieldsList
.
add
(
'minHeight'
);
if
(
maxHeight
.
isNaN
)
affectedFieldsList
.
add
(
'maxHeight'
);
assert
(
affectedFieldsList
.
length
>
0
);
if
(
affectedFieldsList
.
length
>
1
)
affectedFieldsList
.
add
(
'and
${affectedFieldsList.removeLast()}
'
);
String
whichFields
=
''
;
if
(
affectedFieldsList
.
length
>
2
)
{
whichFields
=
affectedFieldsList
.
join
(
', '
);
}
else
if
(
affectedFieldsList
.
length
==
2
)
{
whichFields
=
affectedFieldsList
.
join
(
' '
);
}
else
{
whichFields
=
affectedFieldsList
.
single
;
}
throw
new
FlutterError
(
'BoxConstraints has
${affectedFieldsList.length == 1 ? 'a NaN value' : 'NaN values' }
in
$whichFields
.
\n
$this
'
);
}
if
(
minWidth
<
0.0
&&
minHeight
<
0.0
)
throw
new
FlutterError
(
'BoxConstraints has both a negative minimum width and a negative minimum height.
\n
$this
'
);
if
(
minWidth
<
0.0
)
...
...
packages/flutter/test/rendering/constraints_test.dart
View file @
924480fc
...
...
@@ -30,4 +30,44 @@ void main() {
expect
(
leaf
.
size
.
width
,
equals
(
400.0
));
expect
(
leaf
.
size
.
height
,
equals
(
100.0
));
});
test
(
"BoxConstraints with NaN"
,
()
{
String
result
;
result
=
'no exception'
;
try
{
BoxConstraints
constraints
=
new
BoxConstraints
(
minWidth:
double
.
NAN
,
maxWidth:
double
.
NAN
,
minHeight:
2.0
,
maxHeight:
double
.
NAN
);
assert
(
constraints
.
debugAssertIsNormalized
);
}
on
FlutterError
catch
(
e
)
{
result
=
'
$e
'
;
}
expect
(
result
,
equals
(
'BoxConstraints has NaN values in minWidth, maxWidth, and maxHeight.
\n
'
'BoxConstraints(NaN<=w<=NaN, 2.0<=h<=NaN; NOT NORMALIZED)'
));
result
=
'no exception'
;
try
{
BoxConstraints
constraints
=
new
BoxConstraints
(
minHeight:
double
.
NAN
);
assert
(
constraints
.
debugAssertIsNormalized
);
}
on
FlutterError
catch
(
e
)
{
result
=
'
$e
'
;
}
expect
(
result
,
equals
(
'BoxConstraints has a NaN value in minHeight.
\n
'
'BoxConstraints(0.0<=w<=Infinity, NaN<=h<=Infinity; NOT NORMALIZED)'
));
result
=
'no exception'
;
try
{
BoxConstraints
constraints
=
new
BoxConstraints
(
minHeight:
double
.
NAN
,
maxWidth:
0.0
/
0.0
);
assert
(
constraints
.
debugAssertIsNormalized
);
}
on
FlutterError
catch
(
e
)
{
result
=
'
$e
'
;
}
expect
(
result
,
equals
(
'BoxConstraints has NaN values in maxWidth and minHeight.
\n
'
'BoxConstraints(0.0<=w<=NaN, NaN<=h<=Infinity; NOT NORMALIZED)'
));
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment