manage listener with on,didMount

This commit is contained in:
Hans Muller
2015-07-21 08:41:58 -07:00
parent b0e0e65c09
commit 3f70271d9b

View File

@@ -28,11 +28,20 @@ class VariableHeightScrollable extends Scrollable {
void initState() {
assert(layoutState != null);
layoutState.removeListener(_handleLayoutChanged);
layoutState.addListener(_handleLayoutChanged);
super.initState();
}
void didMount() {
layoutState.addListener(_handleLayoutChanged);
super.didMount();
}
void didUnmount() {
layoutState.removeListener(_handleLayoutChanged);
super.didUnmount();
}
void syncFields(VariableHeightScrollable source) {
builder = source.builder;
if (token != source.token)
@@ -55,11 +64,6 @@ class VariableHeightScrollable extends Scrollable {
scrollBehavior.containerSize = newSize.height;
}
void didUnmount() {
layoutState.removeListener(_handleLayoutChanged);
super.didUnmount();
}
void _handleLayoutChanged() {
if (layoutState.didReachLastChild) {
scrollBehavior.contentsSize = layoutState.contentsSize;