New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Navigator.push cause the front page Scaffold rebuild. #63312
Comments
see #11655 |
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Navigation Basics',
home: FirstRoute(),
));
}
class FirstRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
key: Key('1111'),
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child: RaisedButton(
child: Text('Open route'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
),
),
);
}
}
class SecondRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
key: Key('2222'),
appBar: AppBar(
title: Text("Second Route"),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}
} Not the same problem with #11655 it is the example in flutter.dev. if click the button the Scaffold will build twice, but when we check the performance in devtools, it takes up a very long time in these widgets. |
Hi @love-flutter Thank you |
|
This is the test code. import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Navigation Basics',
debugShowCheckedModeBanner: false,
navigatorKey: GlobalKey(),
home: FirstRoute(),
));
}
class FirstRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
key: Key('1111'),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.people),
title: Text('推荐'),
activeIcon: Icon(Icons.people_outline),
),
BottomNavigationBarItem(
icon: Icon(Icons.favorite),
title: Text('关注'),
activeIcon: Icon(Icons.favorite_border),
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
title: Text('我'),
activeIcon: Icon(Icons.person_outline),
)
],
iconSize: 24,
currentIndex: 0,
/// 选中后,底部BottomNavigationBar内容的颜色(选中时,默认为主题色)
/// (仅当type: BottomNavigationBarType.fixed,时生效)
fixedColor: Colors.lightBlueAccent,
type: BottomNavigationBarType.fixed,
onTap: (int index) {
},
),
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child: RaisedButton(
child: Text('Open route'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
),
),
);
}
}
class SecondRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
key: Key('2222'),
appBar: AppBar(
title: Text("Second Route"),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}
} |
I have checked the source code, it cause by the _EffectiveTickerMode(effective mode: enabled) notifyClients. But I do not know why it must be related with _EffectiveTickerMode. void notifyClients(InheritedWidget oldWidget) {
assert(_debugCheckOwnerBuildTargetExists('notifyClients'));
for (final Element dependent in _dependents.keys) {
assert(() {
// check that it really is our descendant
Element ancestor = dependent._parent;
while (ancestor != this && ancestor != null)
ancestor = ancestor._parent;
return ancestor == this;
}());
// check that it really depends on us
assert(dependent._dependencies.contains(this));
notifyDependent(oldWidget, dependent);
}
} |
Hi @love-flutter
code sampleimport 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: 'Navigation Basics',
debugShowCheckedModeBanner: false,
navigatorKey: GlobalKey(),
showPerformanceOverlay: true,
home: FirstRoute(),
));
}
class FirstRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
print('frist');
return Scaffold(
key: Key('1111'),
bottomNavigationBar: BottomNavigationBar(
items: [
BottomNavigationBarItem(
icon: Icon(Icons.people),
title: Text('推荐'),
activeIcon: Icon(Icons.people_outline),
),
BottomNavigationBarItem(
icon: Icon(Icons.favorite),
title: Text('关注'),
activeIcon: Icon(Icons.favorite_border),
),
BottomNavigationBarItem(
icon: Icon(Icons.person),
title: Text('我'),
activeIcon: Icon(Icons.person_outline),
)
],
iconSize: 24,
currentIndex: 0,
/// 选中后,底部BottomNavigationBar内容的颜色(选中时,默认为主题色)
/// (仅当type: BottomNavigationBarType.fixed,时生效)
fixedColor: Colors.lightBlueAccent,
type: BottomNavigationBarType.fixed,
onTap: (int index) {},
),
appBar: AppBar(
title: Text('First Route'),
),
body: Center(
child: RaisedButton(
child: Text('Open route'),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondRoute()),
);
},
),
),
);
}
}
class SecondRoute extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
key: Key('2222'),
appBar: AppBar(
title: Text("Second Route"),
),
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.pop(context);
},
child: Text('Go back!'),
),
),
);
}
}
flutter doctor -v
|
@TahaTesser ok thanks, will try the latest version. |
@TahaTesser I think it still has this issue, I have used the latest flutter sdk.
add the code in the scaffold build method, and then run the example code above, when you click the button open the second page, you will see the output below @override
Widget build(BuildContext context) {
print(context.widget.key);
assert(debugCheckHasMediaQuery(context));
assert(debugCheckHasDirectionality(context));
final MediaQueryData mediaQuery = MediaQuery.of(context);
final ThemeData themeData = Theme.of(context);
final TextDirection textDirection = Directionality.of(context);
|
When adding modifications to scaffold.art source, it does show scaffold rebuilding on
flutter doctor -v
|
Hi @love-flutter, I tried to reproduce the issue on the latest master channel and this is no longer reproducible. I added the print statement in the build method of Screen.Recording.2022-11-22.at.5.58.40.PM.movflutter doctor -v (mac)
Closing as fixed, Incase you still encounter the issue feel free to write back with more details and we will reopen it. Thank you. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
if you run the code, click the "Test Push", you will see the Scaffold rebuild, if the Scaffold has BottomNavigationBar, I think it will cause some performance problem.
The text was updated successfully, but these errors were encountered: