【问题标题】:Flutter Navigation Re-Render All Page in Histories Stack PageFlutter Navigation 重新渲染历史堆栈页面中的所有页面
【发布时间】:2020-04-28 15:35:56
【问题描述】:

我刚刚意识到,当导航发生变化时,颤振会重新渲染历史堆栈中的所有页面。就我而言,我不想在所有堆栈页面历史记录下方呈现页面。我只想渲染当前页面。

首页

Widget build(BuildContext context){
  print("1st page");
  return RaisedButton(onPressed: goToSecondPage())
}

第二页

Widget build(BuildContext context){
  print("2nd page");
  return RaisedButton(onPressed: goToThirdPage())
}

第三页

Widget build(BuildContext context){
  print("3rd page");
  return Text("I am Third Page, The Last");
}

在我的实现中,我使用Navigator.push(context, MaterialPageRoute(builder: (_) => SecondPage()) 进行导航。

日志 场景:启动

1st page

转到第二页

2nd page
1st page

转到第三页

3rd page
2nd page
1st page

返回第二页

2nd page
1st page

【问题讨论】:

    标签: flutter dart navigation


    【解决方案1】:

    这是 Flutter 当前的预期行为,请参阅此处的对话:https://github.com/flutter/flutter/issues/11655

    这是另一个关于同一件事的 SO 问题:How to deal with unwanted widget build?

    还有一个当前打开的拉取请求以更改此行为: https://github.com/flutter/flutter/pull/44731

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-21
      • 2021-02-12
      • 2020-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-20
      • 1970-01-01
      相关资源
      最近更新 更多