Skip to content
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

Physical Back button closes the application #82

Open
francescovallone opened this issue Feb 17, 2022 · 6 comments
Open

Physical Back button closes the application #82

francescovallone opened this issue Feb 17, 2022 · 6 comments
Labels
question Further information is requested triage needed Issue requires triage

Comments

@francescovallone
Copy link

francescovallone commented Feb 17, 2022

Describe the bug
Using the physical back button it closes the application instead of going back to the previous screen.

To Reproduce
Steps to reproduce the behavior:

  1. Follow the flutter_bloc tutorial for firebase login
  2. Create a nested router instead to go to HomePage
  3. Go to whatever page you want and press back
  4. See error

Expected behavior
It should go back to the previous page

Screenshots

**Logs **

[√] Flutter (Channel stable, 2.10.0, on Microsoft Windows [Versione 10.0.19044.1466], locale it-IT)
    • Flutter version 2.10.0 at F:\Flutter\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5f105a6ca7 (2 weeks ago), 2022-02-01 14:15:42 -0800
    • Engine revision 776efd2034
    • Dart version 2.16.0
    • DevTools version 2.9.2

[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at C:\Users\vallo\AppData\Local\Android\sdk
    • Platform android-32, build-tools 32.1.0-rc1
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
    • All Android licenses accepted.

[X] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[√] Visual Studio - develop for Windows (Visual Studio Build Tools 2019 16.11.8)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools
    • Visual Studio Build Tools 2019 version 16.11.32002.261
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2020.3)
    • 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 11.0.10+0-b96-7249189)

[√] Connected device (3 available)
    • Android SDK built for x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)                  • windows       • windows-x64    • Microsoft Windows [Versione 10.0.19044.1466]
    • Edge (web)                         • edge          • web-javascript • Microsoft Edge 97.0.1072.76

[√] HTTP Host Availability
    • All required HTTP hosts are available
@francescovallone francescovallone changed the title Physical Back button close the application Physical Back button closes the application Feb 17, 2022
@Gene-Dana
Copy link

HI there 👋🏼 May you share with us a minimal reproduction sample?

@felangel felangel added question Further information is requested waiting for response Waiting for additional information labels Feb 18, 2022
@francescovallone
Copy link
Author

I pushed a minimal reproduction sample here.

I'm really sorry if i did something wrong and easily fixable but I'm not very proficient with this library yet.

@francescovallone
Copy link
Author

Any update? 🥲

@felangel
Copy link
Owner

Hi @francescovallone 👋
Thanks for providing a reproduction sample! I apologize for not having much time recently to take a look but I'll try to investigate within the next day or two. Thanks!

@felangel felangel added triage needed Issue requires triage and removed waiting for response Waiting for additional information labels Feb 24, 2022
@Gene-Dana
Copy link

HI there @francescovallone ! Forgive us for getting back to you so late ! At first glance, it seems that you are seeking to use flow builder once a user is already logged in, and this example was a simplified use case for it !

Although, because it's oversimplified I believe this caused you problems. I'd highly suggest you model your application like this example here

This practice of using an enum for a status to drive the state is consistent with almost every example we have, and it may resolve the issues here.

https://github.com/fireship-io/flutter-firebase-course/blob/7a3318944b2802614a24c230b6cae7915a897dbf/lib/app/view/app.dart#L12-L23

Give this a try - instead of using a string, use a status with an enum to route.

@francescovallone
Copy link
Author

Hi @Gene-Dana! I actually did some tests in the meantime and I found out that you should return in the onGeneratePages an list of the pages that you want to load up.

In fact I tried to rewrite the function as following. And I used an enum too 😄.

List<Page> onGeneratePages(
    RouterStatus status,
    List<Page<dynamic>> pages,
){
    switch(status){
        case RouterStatus.monster:
            return [MainPage.page(), MonstersListPage.page(), MonsterPage.page()]
        case RouterStatus.monstersList:
            return [MainPage.page(), MonstersListPage.page()]
        default:
            return [MainPage.page()]
    }
}

If you write it this way it actually lets you use the physical button to go back, otherwise it will not have any page in the list and it will close the application.

Sorry if I not kept this issue updated but I also had a lot to do in these days 🤕

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested triage needed Issue requires triage
Projects
None yet
Development

No branches or pull requests

3 participants