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

[Bug]: PopScope inside tab screens is not working and when Android BackButton is pressed app is closed #168

Open
mnawazshah opened this issue Jun 7, 2024 · 1 comment

Comments

@mnawazshah
Copy link

Version

5.2.3

Flutter Doctor Output

[√] Flutter (Channel stable, 3.19.6, on Microsoft Windows [Version 10.0.19045.2251], locale en-PK)
    • Flutter version 3.19.6 on channel stable at E:\Softwares\flutter_windows_2.10.2-stable\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 54e66469a9 (7 weeks ago), 2024-04-17 13:08:03 -0700
    • Engine revision c4cd48e186
    • Dart version 3.3.4
    • DevTools version 2.31.1

[√] Windows Version (Installed version of Windows is version 10 or higher)

[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at E:\AndroidSDk
    • Platform android-34-ext8, build-tools 34.0.0
    • Java binary at: E:\AndroidStudio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.11+9-b60-7590822)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.1.0)
    • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
    • Visual Studio Community 2022 version 17.1.32210.238
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 2021.1)
    • Android Studio at E:\AndroidStudio
    • 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.11+9-b60-7590822)

[√] VS Code (version 1.73.1)
    • VS Code at C:\Users\D E L L\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.60.0

[√] Connected device (4 available)
    • M2102J20SG (mobile) • 64eaa7b7 • android-arm64  • Android 12 (API 31)
    • Windows (desktop)   • windows  • windows-x64    • Microsoft Windows [Version 10.0.19045.2251]
    • Chrome (web)        • chrome   • web-javascript • Google Chrome 125.0.6422.142
    • Edge (web)          • edge     • web-javascript • Microsoft Edge 125.0.2535.79

[√] Network resources
    • All expected network resources are available.

What platforms are you seeing the problem on?

Android

What happened?

I am using PopScope inside one of the screen which is pushed into the stack of one tab (Home tab). But this PopScope has no effect at all even if canPop is set to false. Plus when can pop is set to false and Android back button is pressed, app is closed automatically. I also read issue #149

Steps to reproduce

  1. Go to 'MainPage'
  2. At home tab navigate to another screen
  3. Pressed android back button
  4. See error

Code to reproduce the problem

import 'package:clean_africa/core/utils/size_utils.dart';
import 'package:clean_africa/presentation/gallery_screen/views/gallery_screen.dart';
import 'package:clean_africa/presentation/home_screen/views/home_screen.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
// import 'package:persistent_bottom_nav_bar/persistent_tab_view.dart';

class HomeConatainer2 extends StatelessWidget {
  HomeConatainer2({super.key});

  final PersistentTabController _controller =
      PersistentTabController(initialIndex: 0);

  List<PersistentTabConfig> _navBarsItems() {
    return [
      PersistentTabConfig(
        screen: const HomeScreen(),
        item: ItemConfig(
          icon: const Icon(CupertinoIcons.home),
          title: "Home",
        ),
      ),
      PersistentTabConfig(
        screen: const GalleryScreen(),
        item: ItemConfig(
          icon: const Icon(CupertinoIcons.photo_fill_on_rectangle_fill),
          title: "Gallery",
        ),
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return Sizer(builder: (context, orientation, deviceType) {
      return PopScope(
        child: PersistentTabView(
          controller: _controller,

          tabs: _navBarsItems(),
          // onWillPop: (p0) async {
          //   log("back button pressed");
          //   return true;
          // },
          backgroundColor: Colors.white, // Default is Colors.white.
          // onWillPop: (p0) => globalOnPop(p0!),
          handleAndroidBackButtonPress: false, // Default is true.
          resizeToAvoidBottomInset:
              true, // This needs to be true if you want to move up the screen when keyboard appears. Default is true.
          stateManagement: true, // Default is true.
          // Recommended to set 'resizeToAvoidBottomInset' as true while using this argument. Default is true.

          popAllScreensOnTapOfSelectedTab: true,
          popActionScreens: PopActionScreensType.all,
          navBarBuilder: (p0) => Style6BottomNavBar(navBarConfig: p0),
          // Choose the nav bar style with this property.
        ),
      );
    });
  }
}

Relevant log output

No response

Screenshots

No response

@jb3rndt
Copy link
Owner

jb3rndt commented Jun 9, 2024

Hi, I cannot run your example. Please also share a (stripped down version) of HomeScreen and GalleryScreen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants