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
6baf162a
Commit
6baf162a
authored
Oct 02, 2015
by
Hixie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Default RenderBox.size to null.
parent
e9f27245
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
51 deletions
+96
-51
box.dart
packages/flutter/lib/src/rendering/box.dart
+47
-50
proxy_box.dart
packages/flutter/lib/src/rendering/proxy_box.dart
+1
-1
size_observer_test.dart
packages/unit/test/widget/size_observer_test.dart
+48
-0
No files found.
packages/flutter/lib/src/rendering/box.dart
View file @
6baf162a
...
...
@@ -280,6 +280,53 @@ abstract class RenderBox extends RenderObject {
return
constraints
.
constrainHeight
(
0.0
);
}
/// The size of this render box computed during layout
///
/// This value is stale whenever this object is marked as needing layout.
/// During [performLayout], do not read the size of a child unless you pass
/// true for parentUsesSize when calling the child's [layout] function.
///
/// The size of a box should be set only during the box's [performLayout] or
/// [performResize] functions. If you wish to change the size of a box outside
/// of those functins, call [markNeedsLayout] instead to schedule a layout of
/// the box.
Size
get
size
{
assert
(
hasSize
);
assert
(()
{
if
(
_size
is
_DebugSize
)
{
final
_DebugSize
_size
=
this
.
_size
;
// TODO(ianh): Remove this once the analyzer is cleverer
assert
(
_size
.
_owner
==
this
);
if
(
RenderObject
.
debugActiveLayout
!=
null
)
{
// we are always allowed to access our own size (for print debugging and asserts if nothing else)
// other than us, the only object that's allowed to read our size is our parent, if they're said they will
// if you hit this assert trying to access a child's size, pass parentUsesSize: true in layout()
assert
(
debugDoingThisResize
||
debugDoingThisLayout
||
(
RenderObject
.
debugActiveLayout
==
parent
&&
_size
.
_canBeUsedByParent
));
}
assert
(
_size
==
this
.
_size
);
// TODO(ianh): Remove this once the analyzer is cleverer
}
return
true
;
});
return
_size
;
}
bool
get
hasSize
=>
_size
!=
null
;
Size
_size
;
void
set
size
(
Size
value
)
{
assert
((
sizedByParent
&&
debugDoingThisResize
)
||
(!
sizedByParent
&&
debugDoingThisLayout
));
assert
(()
{
if
(
value
is
_DebugSize
)
return
value
.
_canBeUsedByParent
&&
value
.
_owner
.
parent
==
this
;
return
true
;
});
_size
=
value
;
assert
(()
{
_size
=
new
_DebugSize
(
_size
,
this
,
debugCanParentUseSize
);
return
true
;
});
assert
(
debugDoesMeetConstraints
());
}
Map
<
TextBaseline
,
double
>
_cachedBaselines
;
bool
_ancestorUsesBaseline
=
false
;
static
bool
_debugDoingBaseline
=
false
;
...
...
@@ -427,56 +474,6 @@ abstract class RenderBox extends RenderObject {
/// visually "on top" (i.e., paints later).
void
hitTestChildren
(
HitTestResult
result
,
{
Point
position
})
{
}
// TODO(ianh): move size up to before constraints
// TODO(ianh): In non-debug builds, this should all just be:
// Size size = Size.zero;
// In debug builds, however:
Size
_size
=
Size
.
zero
;
/// The size of this render box computed during layout
///
/// This value is stale whenever this object is marked as needing layout.
/// During [performLayout], do not read the size of a child unless you pass
/// true for parentUsesSize when calling the child's [layout] function.
///
/// The size of a box should be set only during the box's [performLayout] or
/// [performResize] functions. If you wish to change the size of a box outside
/// of those functins, call [markNeedsLayout] instead to schedule a layout of
/// the box.
Size
get
size
{
assert
(()
{
if
(
_size
is
_DebugSize
)
{
final
_DebugSize
_size
=
this
.
_size
;
// TODO(ianh): Remove this once the analyzer is cleverer
assert
(
_size
.
_owner
==
this
);
if
(
RenderObject
.
debugActiveLayout
!=
null
)
{
// we are always allowed to access our own size (for print debugging and asserts if nothing else)
// other than us, the only object that's allowed to read our size is our parent, if they're said they will
// if you hit this assert trying to access a child's size, pass parentUsesSize: true in layout()
assert
(
debugDoingThisResize
||
debugDoingThisLayout
||
(
RenderObject
.
debugActiveLayout
==
parent
&&
_size
.
_canBeUsedByParent
));
}
assert
(
_size
==
this
.
_size
);
// TODO(ianh): Remove this once the analyzer is cleverer
}
return
true
;
});
return
_size
;
}
void
set
size
(
Size
value
)
{
assert
((
sizedByParent
&&
debugDoingThisResize
)
||
(!
sizedByParent
&&
debugDoingThisLayout
));
assert
(()
{
if
(
value
is
_DebugSize
)
return
value
.
_canBeUsedByParent
&&
value
.
_owner
.
parent
==
this
;
return
true
;
});
_size
=
value
;
assert
(()
{
_size
=
new
_DebugSize
(
_size
,
this
,
debugCanParentUseSize
);
return
true
;
});
assert
(
debugDoesMeetConstraints
());
}
/// Multiply the transform from the parent's coordinate system to this box's
/// coordinate system into the given transform
///
...
...
packages/flutter/lib/src/rendering/proxy_box.dart
View file @
6baf162a
...
...
@@ -963,7 +963,7 @@ class RenderSizeObserver extends RenderProxyBox {
SizeChangedCallback
callback
;
void
performLayout
()
{
Size
oldSize
=
size
;
Size
oldSize
=
hasSize
?
size
:
null
;
super
.
performLayout
();
if
(
oldSize
!=
size
)
callback
(
size
);
...
...
packages/unit/test/widget/size_observer_test.dart
0 → 100644
View file @
6baf162a
import
'package:sky/rendering.dart'
;
import
'package:sky/widgets.dart'
;
import
'package:test/test.dart'
;
import
'widget_tester.dart'
;
void
main
(
)
{
test
(
'SizeObserver notices zero size'
,
()
{
testWidgets
((
WidgetTester
tester
)
{
List
results
=
[];
tester
.
pumpWidget
(
new
Center
(
child:
new
SizeObserver
(
callback:
(
size
)
{
results
.
add
(
size
);
},
child:
new
Container
(
width:
0.0
,
height:
0.0
)
)
));
expect
(
results
,
equals
([
Size
.
zero
]));
tester
.
pump
();
expect
(
results
,
equals
([
Size
.
zero
]));
tester
.
pumpWidget
(
new
Center
(
child:
new
SizeObserver
(
callback:
(
size
)
{
results
.
add
(
size
);
},
child:
new
Container
(
width:
100.0
,
height:
0.0
)
)
));
expect
(
results
,
equals
([
Size
.
zero
,
const
Size
(
100.0
,
0.0
)]));
tester
.
pump
();
expect
(
results
,
equals
([
Size
.
zero
,
const
Size
(
100.0
,
0.0
)]));
tester
.
pumpWidget
(
new
Center
(
child:
new
SizeObserver
(
callback:
(
size
)
{
results
.
add
(
size
);
},
child:
new
Container
(
width:
0.0
,
height:
0.0
)
)
));
expect
(
results
,
equals
([
Size
.
zero
,
const
Size
(
100.0
,
0.0
),
Size
.
zero
]));
tester
.
pump
();
expect
(
results
,
equals
([
Size
.
zero
,
const
Size
(
100.0
,
0.0
),
Size
.
zero
]));
tester
.
pumpWidget
(
new
Center
(
child:
new
SizeObserver
(
callback:
(
size
)
{
results
.
add
(
size
);
},
child:
new
Container
(
width:
0.0
,
height:
0.0
)
)
));
expect
(
results
,
equals
([
Size
.
zero
,
const
Size
(
100.0
,
0.0
),
Size
.
zero
]));
});
});
}
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