Reputation: 1033
I have been trying to find out what causes the behaviour described below:
Here is the Routing like:
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
},
)));
}
}
The problem is; every time I navigate to a screen, all the other screen updates in the background. I know because I set console print("I am here"); in each screen.
Is this the normal behaviour? I do want this because it is wasting CPU resources.
I hope I have some clues on what I did wrong.
Upvotes: 0
Views: 263
Reputation: 657208
Is this the normal behaviour?
Yes, routes are by default added on top of previous routes,
and you should in general expect the built()
method to be called at any time.
I do want this because it is wasting CPU resources.
Not really. The build method shouldn't do to much work anyway except of creating widget instances and the expensive work is layouting and rendering to the GPU, which won't be done if the view hasn't changed.
Upvotes: 0