Vilokan Labs
Vilokan Labs

Reputation: 2005

Why does route creation fail for StatefulWidget?

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).

Upvotes: 10

Views: 3529

Answers (1)

Vilokan Labs
Vilokan Labs

Reputation: 2005

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

Upvotes: 24

Related Questions