Open SchabanBo opened 3 years ago
@SchabanBo Although I see the same behavior as you mentioned, but since you are using Navigator 2.0 concept in your code, I'd like you to go through this issue that discussed challenges faced using Navigator 2.0, https://github.com/flutter/flutter/issues/69315.
If you go through that link, it was closed in favor of providing your feedback using navigator 2.0 usability api here, https://github.com/flutter/uxr/wiki/Navigator-2.0-API-Usability-Research and https://github.com/flutter/uxr/issues/6
You are welcome to share this behavior in linked issue to get more attention to it.
But I'll label this issue here in case if it's needed here.
I really tried to understand what is happing here. and it seems this problem is related to the Drawer
.
if you change the Index screen to this
class IndexScreen extends StatelessWidget {
final int index;
final AppState state;
IndexScreen({
required this.state,
required this.index,
});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
drawer: Drawer(
child: ListView(
children: [
for (var i = 0; i < state.indexs.length; i++)
ListTile(
title: Text("$i"),
onTap: () => state.selectedIndex = i,
)
],
),
),
body: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Column(
children: [
Text('$index', style: Theme.of(context).textTheme.headline6),
for (var i = 0; i < state.indexs.length; i++)
ListTile(
title: Text("$i"),
onTap: () => state.selectedIndex = i,
)
],
)),
),
);
}
}
and navigate from the ListTile in the column, it works fine. but if you navigate from the drawer you will get this weird behavior.
/cc @goderbauer this looks like a framework-side issue
/cc @chunhtai
The page update attempt to pop the page but it popped the open drawer instead. You will need to manually close it. See the code
onTap: () {
// Close the drawer.
Navigator.of(context).pop();
state.selectedIndex = i;
},
We should add an error message says the page update failed to pop the page, and warn the developer that it can't be popped automatically.
Alternatively we can add a new API to force pop a route. I am not sure if this is a sane thing to do. @goderbauer Do you have any suggestion?
Tested on current stable and master version, issue still persists. Platforms tested are:
flutter doctor -v
Steps to Reproduce
flutter create bug
.Navigato 2 Code
Follow these steps
Expected results: Page 0 or 1 is shown
Actual results: Page 2 is shown (although it is not in Navigator.page) Check the logs when you are navigating, the pages.length will be logged
Logs
## flutter doctor -v [√] Flutter (Channel dev, 2.3.0-1.0.pre, on Microsoft Windows [Version 10.0.19042.928], locale en-US) • Flutter version 2.3.0-1.0.pre at C:\Tools\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision d97f41caed (13 days ago), 2021-04-30 12:35:21 -0700 • Engine revision e7939e091e • Dart version 2.14.0 (build 2.14.0-48.0.dev) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.3) • Android SDK at C:\Users\Schab\AppData\Local\Android\sdk • Platform android-30, build-tools 30.0.3 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) • All Android licenses accepted. [√] Chrome - develop for the web • CHROME_EXECUTABLE = C:\Users\Schab\xmlhttperror.cmd [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.9.4) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community • Visual Studio Community 2019 version 16.9.31205.134 • Windows 10 SDK version 10.0.19041.0 [√] Android Studio (version 4.1.0) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) [√] VS Code (version 1.56.1) • VS Code at C:\Users\Schab\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.22.0 [√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19042.928] • Chrome (web) • chrome • web-javascript • Google Chrome 90.0.4430.212 • Edge (web) • edge • web-javascript • Microsoft Edge 90.0.818.49 • No issues found!https://user-images.githubusercontent.com/49782771/118126030-0447ae80-b3f8-11eb-8f2b-f0219b2b6f78.mp4