From 3f70271d9b3ecc0b713687542bbebca02153b80b Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 21 Jul 2015 08:41:58 -0700 Subject: [PATCH] manage listener with on,didMount --- .../widgets/variable_height_scrollable.dart | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/packages/flutter/lib/widgets/variable_height_scrollable.dart b/packages/flutter/lib/widgets/variable_height_scrollable.dart index ebf47564f3..b36c38310f 100644 --- a/packages/flutter/lib/widgets/variable_height_scrollable.dart +++ b/packages/flutter/lib/widgets/variable_height_scrollable.dart @@ -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;