gpt4 book ai didi

dart - 为什么 StatefulWidget 的路由创建失败?

转载 作者:IT老高 更新时间:2023-10-28 12:37:44 25 4
gpt4 key购买 nike

我正在尝试使用 StatefulWidget 创建路由。

错误:

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.

代码:

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();
}

查询:

  • 为什么不允许 StatefulWidget 使用它?

问题:如果小部件的基类更改(StatefulWidget <-> StatelessWidget),则路由热重载失败。

最佳答案

热重载仅用于最小的 UI 更改。

礼貌:“这不是问题,使用热重载对 UI 进行最小的更改。通常你需要在创建新类(class)时完全重启。” – @aziza

关于dart - 为什么 StatefulWidget 的路由创建失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48972312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com