Flutter 断言失败:第5540行位置12:'_children.contains(child)和#x27;:事实并非如此。无法弹出路线并返回上一屏幕
我在一个屏幕a上工作,让用户进入屏幕B,现在在屏幕B上我有一个后退按钮,按下时有导航器,弹出(上下文)。 但这不断抛出这个错误“ 断言失败:第5540行位置12:“_children.contains(child)”是 不是真的 “,每当我按下后退按钮时Flutter 断言失败:第5540行位置12:'_children.contains(child)和#x27;:事实并非如此。无法弹出路线并返回上一屏幕,flutter,dart,Flutter,Dart,我在一个屏幕a上工作,让用户进入屏幕B,现在在屏幕B上我有一个后退按钮,按下时有导航器,弹出(上下文)。 但这不断抛出这个错误“ 断言失败:第5540行位置12:“_children.contains(child)”是 不是真的 “,每当我按下后退按钮时 class CustomAppBarWithoutSliver extends StatelessWidget implements PreferredSizeWidget { var leftIcon; var rightIcon;
class CustomAppBarWithoutSliver extends StatelessWidget
implements PreferredSizeWidget {
var leftIcon;
var rightIcon;
var appBarText;
var rightIconIsCart = false;
var replaceRightIcon = false;
var rightIconOnPressCallbackFunction;
Widget replacedRightWidget;
CustomAppBarWithoutSliver(
{this.leftIcon,
this.rightIcon,
this.appBarText,
this.rightIconIsCart,
this.rightIconOnPressCallbackFunction,
this.replaceRightIcon,
this.replacedRightWidget});
@override
Widget build(BuildContext context) {
// TODO: implement build
if (!rightIconIsCart) {
rightIcon = Icons.search;
}
return AppBar(
elevation: 0,
backgroundColor: Color(appBarColor),
title: (replaceRightIcon != null && replaceRightIcon == true)
? replacedRightWidget
: Text('$appBarText', style: TextStyle(color: Color(textColor))),
centerTitle: true,
leading: IconButton(
icon: Icon(
leftIcon,
color: Color(textColor),
),
onPressed: () => (Navigator.pop(context)),
),
actions: <Widget>[
(replaceRightIcon != null && replaceRightIcon == true)
? IconButton(
icon: Icon(
Icons.cancel,
),
onPressed: () => (rightIconOnPressCallbackFunction()),
color: Colors.redAccent,
)
: IconButton(
icon: Icon(
rightIcon,
color: Color(textColor),
),
onPressed: () => (rightIconIsCart
? Navigator.push(context,
MaterialPageRoute(builder: (context) => MyCartPage()))
: rightIconOnPressCallbackFunction()),
)
],
);
}
@override
// TODO: implement preferredSize
Size get preferredSize => Size.fromHeight(kToolbarHeight);
}
这给了我这个用户界面。现在,如果我按下这个后退按钮,我会得到这个错误失败的断言:第5540行位置12:“_children.contains(child)”:不是真的
原因可能是什么?请发布一些代码。如果没有一些代码,这几乎不可能做出任何明智的猜测。你能删除你的代码吗?是的,对不起!我现在已经添加了代码和相关图片。
return Scaffold(
appBar: CustomAppBarWithoutSliver(
rightIcon: Icons.shopping_cart,
leftIcon: Icons.keyboard_arrow_left,
appBarText: "",
rightIconIsCart: false,
rightIconOnPressCallbackFunction: this.rightIconHandleClick,
replaceRightIcon: replaceRightIcon,
replacedRightWidget: replacedRightWidget,
),
body: CustomPaint( . . . .