Navigation 颤振通过每隔一个屏幕的路由更新导航到其他屏幕

Navigation 颤振通过每隔一个屏幕的路由更新导航到其他屏幕,navigation,flutter,Navigation,Flutter,我一直试图找出导致以下行为的原因: 我有一个有很多屏幕的颤振应用程序 使用路由和一个抽屉实现对各种屏幕的导航,该抽屉将Navigator.pushNamed(context,“/XX”)指定给它们 以下是如下所示的路由: Routes() { runApp( new StateContainer(child: new MaterialApp( title: "My App", debugShowCheckedModeBanner: false,

我一直试图找出导致以下行为的原因:

  • 我有一个有很多屏幕的颤振应用程序
  • 使用路由和一个抽屉实现对各种屏幕的导航,该抽屉将Navigator.pushNamed(context,“/XX”)指定给它们
  • 以下是如下所示的路由:

    Routes() {
       runApp( new StateContainer(child:
          new MaterialApp(
          title: "My App",
          debugShowCheckedModeBanner: false,
          theme: new ThemeData(
            primaryColor: defaultTargetPlatform == TargetPlatform.iOS
            ? Colors.blueGrey[900] : Colors.blueGrey[900],
            accentColor: defaultTargetPlatform == TargetPlatform.iOS
            ? Colors.grey[900] : Colors.grey[900],
            ),
          home: new LoginScreen(),
    
          routes: <String, WidgetBuilder> { //5
            '/login': (BuildContext context) => new LoginScreen(), //LoginScreen
            '/signup' : (BuildContext context) => new SignupScreen(), // SignupScreen
            '/home': (BuildContext context) => new HomeScreen(), //HomeScreen
    
    
          },
    
        )));
      }
    
    }
    
    Routes(){
    runApp(新状态容器(子:
    新材料聚丙烯(
    标题:“我的应用程序”,
    debugShowCheckedModeBanner:false,
    主题:新主题数据(
    primaryColor:defaultTargetPlatform==TargetPlatform.iOS
    ?颜色.蓝灰色[900]:颜色.蓝灰色[900],
    accentColor:defaultTargetPlatform==TargetPlatform.iOS
    ?颜色.灰色[900]:颜色.灰色[900],
    ),
    主页:新登录屏幕(),
    路线:{//5
    “/login”:(BuildContext context)=>new LoginScreen(),//LoginScreen
    “/signup”:(BuildContext上下文)=>new SignupScreen(),//SignupScreen
    “/home”:(BuildContext上下文)=>new HomeScreen(),//HomeScreen
    },
    )));
    }
    }
    
    问题是,;每次我导航到一个屏幕时,所有其他屏幕都会在后台更新。我知道,因为我设置了控制台打印(“我在这里”);在每个屏幕中

    这是正常的行为吗?我确实想要这个,因为这是在浪费CPU资源

    我希望我能找到一些关于我做错了什么的线索

    这是正常的行为吗

    是,默认情况下,路线添加在先前路线的顶部, 通常,您应该期望在任何时候调用
    build()
    方法

    我确实想要这个,因为这是在浪费CPU资源


    不是真的。构建方法除了创建小部件实例之外,不应该做太多的工作,昂贵的工作是布局和渲染到GPU,如果视图没有改变,这将不会完成。

    我在另一个屏幕中获取数据,我注意到每次我导航到另一个屏幕,正在执行数据提取…如果将数据保存在变量中,则可以轻松检查数据是否已提取,并在数据已可用时跳过提取。