首页 > 解决方案 > 无法启动 Alice HTTP Inspector。请将 NavigatorKey 添加到您的应用程序

问题描述

navigatorKey 已经添加到代码中,但在 navigatorKey 下仍然显示错误(红线)。

@override
Widget build(BuildContext context) {
return WillPopScope(
navigatorKey: _alice.getNavigatorKey(),
child: Theme(
data: ThemeData(
brightness: Brightness.light,
primarySwatch: AppColor.appColor,
primaryColor: AppColor.white,
buttonTheme: ButtonThemeData().copyWith(
buttonColor: AppColor.appColor,
textTheme: ButtonTextTheme.primary),
fontFamily: "EncodeSans",
),
child: layout()),

onWillPop: () {
return handleBackPress();
});
}

标签: httpflutterdartinspectoralice

解决方案


将 navigatorKey 更改为键:

您的代码必须如下所示:

@override
Widget build(BuildContext context) {
return WillPopScope(
key: _alice.getNavigatorKey(), // here i replace key with navigatorKey
child: Theme(
data: ThemeData(
brightness: Brightness.light,
primarySwatch: AppColor.appColor,
primaryColor: AppColor.white,
buttonTheme: ButtonThemeData().copyWith(
buttonColor: AppColor.appColor,
textTheme: ButtonTextTheme.primary),
fontFamily: "EncodeSans",
),
child: layout()),

onWillPop: () {
return handleBackPress();
});
}

推荐阅读