flutter / gallery

Flutter Gallery was a resource to help developers evaluate and use Flutter
BSD 3-Clause "New" or "Revised" License
6.39k stars 1.55k forks source link

Gallery shrine demo WillPopScope in ExpandingBottomSheet doesn't work! #644

Open songtao542 opened 5 years ago

HansMuller commented 5 years ago

I'd like to track this down. Can you provide a description of what's going wrong: how you're interacting with the demo, what you're seeing, what you expect to see, etc?

songtao542 commented 5 years ago

Step:

  1. Open Gallery -> click "Studies" -> click "Shrine" -> click "NEXT" ;
  2. Add some product into the cart;
  3. Click the cart (at bottom) to expand the cart;
  4. Click "Back" key(the "back" at Android Navigation bar)

result: the app back to the Studies page

expect: the app just collapse the cart, not leave the product page.

HansMuller commented 5 years ago

Thanks for explaining the problem. You're right: in this case the system back button should do the same thing as the app's back button (the down-arrow in the upper left-hand corner).

michdud commented 4 years ago

I took a look at this, and it seems the problem might be coming from the fact that the Shrine app is nested inside the Gallery app. Both the gallery and Shrine have their own Navigators. As a result, WillPopScope in Shrine is inside an inner navigator and is ignored.

I got the cart to close properly again by wrapping the MaterialApp in Shrine with a WillPopScope and adding a GlobalKey for the ExpandingBottomSheetState (see here). Does this look like a reasonable solution, or is there a way to do this without wrapping the MaterialApp with a WillPopScope?

HansMuller commented 4 years ago

Is the problem that the WillPopScope widget's callback unconditionally pops the outermost navigator? Maybe _onWillPop() in expanding_bottom_sheet.dart needs to be changed?

michdud commented 4 years ago

As far as I can tell, the callback isn't called at all. I tried moving the WillPopScope widget up the tree, and the only time the callback was called was when it wrapped the Shrine MaterialApp.

markusaksli-nc commented 4 years ago

Still the case in the latest version of gallery b5e9c40 built with latest master 1.23.0-8.0.pre.164.

flutter doctor -v ``` [√] Flutter (Channel master, 1.23.0-8.0.pre.164, on Microsoft Windows [Version 10.0.19041.508], locale en-US) • Flutter version 1.23.0-8.0.pre.164 at C:\Development\flutter_master • Framework revision b3bd9e6924 (3 hours ago), 2020-10-05 19:52:03 -0700 • Engine revision 284ef2217d • Dart version 2.11.0 (build 2.11.0-186.0.dev) [√] Android toolchain - develop for Android devices (Android SDK version 30.0.1) • Android SDK at C:\Users\marku\AppData\Local\Android\sdk • Platform android-30, build-tools 30.0.1 • Java binary at: C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\193.6626763\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 at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.6.5) • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community • Visual Studio Community 2019 version 16.6.30320.27 • Windows 10 SDK version 10.0.18362.0 [√] Android Studio (version 4.0) • Android Studio at C:\Users\marku\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-0\193.6626763 • Flutter plugin version 47.1.2 • Dart plugin version 193.7361 • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) [√] Connected device (6 available) • SM G950F (mobile) • ce12171c51cc001c03 • android-arm64 • Android 9 (API 28) • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19041.508] • Web Server (web) • web-server • web-javascript • Flutter Tools • Chrome (web) • chrome • web-javascript • Google Chrome 85.0.4183.121 • Edge (web) • edge • web-javascript • Microsoft Edge 85.0.564.68 • No issues found! ```