简体   繁体   English

AppBar 内的后退按钮在 flutter 中显示黑屏

[英]back button inside AppBar showing black screen in flutter

I have bottom tab navigator that contains of A and B screens, inside B screen I have widget that navigate to C page and inside C page I want to add back arrow to go back to previous screen (B screen), so... I have simple widget that the code looks like this我有包含 A 和 B 屏幕的底部标签导航器,在 B 屏幕内我有导航到 C 页面和 C 页面内的小部件我想将返回箭头添加到 Z34D1F91FB2E514B8576FAB1A7B8 屏幕上有简单的小部件,代码看起来像这样

@override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
            resizeToAvoidBottomPadding: false,
            appBar: AppBar(
              leading: IconButton(
                icon: Icon(Icons.arrow_back),
                onPressed: () => Navigator.of(context).pop(),
              ),
              title: Text("XXX"),
              centerTitle: true,
            ),
            body: detail()));
  }

the problem is whenever I click back arrow.. it turns to black screen... I don't get any idea what the problem is... so is there a way to go to my previous screen?问题是每当我点击后退箭头时..它变成黑屏...我不知道问题是什么...那么有没有办法将 go 转到我以前的屏幕? and this is how I ndo navigate from B screen to C page这就是我从 B 屏幕导航到 C 页面的方式

InkWell(
                      onTap: () {Navigator.of(context).pushReplacement(MaterialPageRoute(
                            builder: (context) => new NextScreen(check: values)));
                      },
                      child: Text(
                        "Next...",
                        style: TextStyle(
                          fontSize: 13.0,
                        ),
                      ),
                    )

The reason why you see a blank screen is because you navigated using pushReplacement .您看到空白屏幕的原因是您使用pushReplacement进行导航。 What pushReplacement does it that it will navigate to the next screen without stacking itself to the route meaning that it will make the app forget that the last screen was your screen B. Try using Navigator.push() instead. pushReplacement的作用是它会导航到下一个屏幕而不会将自身堆叠到路由上,这意味着它会让应用程序忘记最后一个屏幕是您的屏幕 B。尝试使用Navigator.push()代替。
Here is an example:这是一个例子:

onPressed: () {
  Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => ScreenC()),
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM