Commit 1d6fa089 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Improve error message for createState type errors (#6339)

Fixes #6209
parent 8b16c025
......@@ -2728,7 +2728,17 @@ class StatefulElement extends ComponentElement {
/// Creates an element that uses the given widget as its configuration.
StatefulElement(StatefulWidget widget)
: _state = widget.createState(), super(widget) {
assert(_state._debugTypesAreRight(widget));
assert(() {
if (!_state._debugTypesAreRight(widget)) {
throw new FlutterError(
'StatefulWidget.createState must return a subtype of State<${widget.runtimeType}>\n'
'The createState function for ${widget.runtimeType} returned a state '
'of type ${_state.runtimeType}, which is not a subtype of '
'State<${widget.runtimeType}>, violating the contract for createState.'
);
}
return true;
});
assert(_state._element == null);
_state._element = this;
assert(_builder == _buildNothing);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment