I am trying to create a route with a StatefulWidget.
Error:
I/flutter (23141): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (23141): The following assertion was thrown building
I/flutter (23141): _OverlayEntry-[LabeledGlobalKey<_OverlayEntryState>#3e9ee](dirty, state: _OverlayEntryState#7b90c):
I/flutter (23141): The builder for route "/" returned null.
I/flutter (23141): Route builders must never return null.
Code:
routes:<String,WidgetBuilder>{
"/":(_)=>new RouteHome(title: 'Flutter Demo Home Page'),
...
class RouteHome extends StatefulWidget {
RouteHome({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
Queries:
Issue: Hot reload fails for routes if the widget's base class is changed (StatefulWidget <-> StatelessWidget).
Subclasses should override this method to return a newly created instance of their associated State subclass: The framework can call this method multiple times over the lifetime of a StatefulWidget. For example, if the widget is inserted into the tree in multiple locations, the framework will create a separate State object for each location.
The framework can call this method multiple times over the lifetime of a StatefulWidget. For example, if the widget is inserted into the tree in multiple locations, the framework will create a separate State object for each location.
StatefulWidget instances themselves are immutable and store their mutable state either in separate State objects that are created by the createState method, or in objects to which that State subscribes, for example Stream or ChangeNotifier objects, to which references are stored in final fields on the StatefulWidget itself.
Similarly, if a StatefulWidget is removed from the tree and later inserted in to the tree again, the framework will call createState again to create a fresh State object, simplifying the lifecycle of State objects.
Hot reload is to be used for minimal UI changes only.
Courtesy: "It is not an issue, use hot reload for minimal changes in the UI. Usually you need to do a full restart when you create new classes." – @aziza
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With