From 834165448b9bf7b42ddaf0631559fbc23d3ace1d Mon Sep 17 00:00:00 2001 From: Hixie Date: Thu, 1 Oct 2015 13:20:47 -0700 Subject: [PATCH] Assert that the widget is the T in State Mostly because we can, but hopefully it'll catch someone who accidentally copypasted their createState method. --- packages/flutter/lib/src/widgets/framework.dart | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 4514639492..151a21f193 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -293,6 +293,10 @@ abstract class State { /// This is used to verify that State objects move through life in an orderly fashion. _StateLifecycle _debugLifecycleState = _StateLifecycle.created; + /// Verifies that the State that was created is one that expects to be created + /// for that particular Widget. + bool _debugTypesAreRight(widget) => widget is T; + /// Pointer to the owner Element object StatefulComponentElement _element; @@ -825,6 +829,7 @@ class StatelessComponentElement extends BuildableE class StatefulComponentElement extends BuildableElement { StatefulComponentElement(StatefulComponent widget) : _state = widget.createState(), super(widget) { + assert(_state._debugTypesAreRight(widget)); assert(_state._element == null); _state._element = this; assert(_builder == null);