代码之家  ›  专栏  ›  技术社区  ›  Ruslan Leshchenko

Flutter Navigator.replace()示例

  •  3
  • Ruslan Leshchenko  · 技术社区  · 7 年前

    我需要更换当前屏幕并找到 replace 方法。但我没有找到任何例子。也许有人知道如何使用它。 谢谢。

    2 回复  |  直到 7 年前
        1
  •  20
  •   songoku1610    6 年前

    我通常用

    Route route = MaterialPageRoute(builder: (context) => NextPage());
    Navigator.pushReplacement(context, route);
    

    希望有帮助

        2
  •  5
  •   goops17    7 年前

    我从未使用过Navigator.replace(),但是名为的Navigator.pushreplacement可能会帮助您。

    Navigator.pushReplacementNamed(context, '/thread_list');
    
        3
  •  0
  •   AlexPad    5 年前

    如果已在路由中包含该页,则建议的解决方案不好。。 你会在现有的页面上创建另一个页面。解决方案应该被替换

     Navigator.of(context).replace(
       oldRoute: '/UserPage'->actual root,
       newRoute: MaterialPageRoute(
                 builder: (context) =>
                 NavigationHomeController()));