0

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

1 回答 1

0

将 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();
});
}
于 2020-06-23T09:41:59.240 回答