Handle stateful widgets in layout builders. (#5752)

Previously, if a StatefulWidget was marked dirty, then removed from the
build, then reinserted using the exact same widget under a widget under
a LayoutBuilder, it wouldn't rebuild.

This fixes that.

It also introduces an assert that's supposed to catch SizeObserver-like
behaviour. Rather than make this patch even bigger, I papered over two
pre-existing bugs which this assert uncovered (and fixed the other
problems it found):

   https://github.com/flutter/flutter/issues/5751
   https://github.com/flutter/flutter/issues/5749

We should fix those before 1.0 though.
This commit is contained in:
Ian Hickson
2016-09-07 14:45:19 -07:00
committed by GitHub
parent 691c25faca
commit 1f15e06e45
14 changed files with 353 additions and 132 deletions

View File

@@ -22,9 +22,12 @@ import 'stack_manipulation.dart';
/// Phases that can be reached by [WidgetTester.pumpWidget] and
/// [TestWidgetsFlutterBinding.pump].
///
/// See [WidgetsBinding.beginFrame] for a more detailed description of some of
/// these phases.
// TODO(ianh): Merge with near-identical code in the rendering test code.
enum EnginePhase {
/// The build phase in the widgets library. See [BuildOwner.buildDirtyElements].
/// The build phase in the widgets library. See [BuildOwner.buildScope].
build,
/// The layout phase in the rendering library. See [PipelineOwner.flushLayout].
@@ -396,6 +399,9 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
///
/// This binding controls time, allowing tests to verify long
/// animation sequences without having to execute them in real time.
///
/// This class assumes it is always run in checked mode (since tests are always
/// run in checked mode).
class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
@override
void initInstances() {
@@ -447,26 +453,31 @@ class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding {
@override
void beginFrame() {
assert(inTest);
buildOwner.buildDirtyElements();
if (_phase == EnginePhase.build)
return;
assert(renderView != null);
pipelineOwner.flushLayout();
if (_phase == EnginePhase.layout)
return;
pipelineOwner.flushCompositingBits();
if (_phase == EnginePhase.compositingBits)
return;
pipelineOwner.flushPaint();
if (_phase == EnginePhase.paint)
return;
renderView.compositeFrame(); // this sends the bits to the GPU
if (_phase == EnginePhase.composite)
return;
pipelineOwner.flushSemantics();
if (_phase == EnginePhase.flushSemantics)
return;
buildOwner.finalizeTree();
try {
debugBuildingDirtyElements = true;
buildOwner.buildScope(renderViewElement);
if (_phase == EnginePhase.build)
return;
assert(renderView != null);
pipelineOwner.flushLayout();
if (_phase == EnginePhase.layout)
return;
pipelineOwner.flushCompositingBits();
if (_phase == EnginePhase.compositingBits)
return;
pipelineOwner.flushPaint();
if (_phase == EnginePhase.paint)
return;
renderView.compositeFrame(); // this sends the bits to the GPU
if (_phase == EnginePhase.composite)
return;
pipelineOwner.flushSemantics();
if (_phase == EnginePhase.flushSemantics)
return;
} finally {
buildOwner.finalizeTree();
debugBuildingDirtyElements = false;
}
}
@override