Skip to content

Issue with PopScope widget  #139800

@hassanrazzaq8

Description

@hassanrazzaq8

Is there an existing issue for this?

Steps to reproduce

I was using WillPopScope widget with flutter version 3.0.5 and then I upgraded to 3.16.0 stable channel Now in latest version WillPopScope is deprecated and the new widget is introduced with the name of PopScope.
I am using CupertinoTabScaffold with tabbar in order to persist the bottomtab I am wrapping my CupertinoTabScaffold with PopScope and set the canPop to false it does not allow to kill the application but it removes the very first screen by tapping back button of android. Let's say I have three tabs tab1,tab2,tab3 and I have started application and I am in tab1 and there is screen 1 when I will tap on android back button it will remove the screen1 and show me the grey screen.
When I was using WillPopScope it was working as expected.

Expected results

I want to register a background task by tapping android back button and after registering i want to exit the application

Actual results

It removes the first screen of tab1 and shows the grey screen.

Code sample

Code sample
class TestTab extends StatefulWidget {
  final int pageIndex;

  const TestTab({
    Key? key,
    required this.pageIndex,
  }) : super(key: key);

  @override
  _TestTabState createState() => _TestTabState();
}

class _TestTabState extends State<TestTab> {
  @override
  Widget build(BuildContext context) {
    Provider.of<BottomTabProvider>(context, listen: true);
    return PopScope(
      canPop: false,
      child: SafeArea(
        top: false,
        child: CupertinoTabScaffold(
          resizeToAvoidBottomInset: true,
          tabBuilder: (context, index) {
            switch (index) {
              case 0:
                return CupertinoTabView(
                  navigatorKey: kidsTabKey,
                  builder: (context) {
                    return const CupertinoPageScaffold(
                        child: Center(
                          child: Text("Screen1"),
                        ));
                  },
                );
              case 1:
                return CupertinoTabView(
                  builder: (context) {
                    return const CupertinoPageScaffold(
                        child: Center(
                          child: Text("Screen2"),
                        ));
                  },
                );
              case 2:
                return CupertinoTabView(
                  builder: (context) {
                    return const CupertinoPageScaffold(
                        child: Center(
                      child: Text("Screen3"),
                    ));
                  },
                );
            }
            return Container();
          },
          tabBar: CupertinoTabBar(
            height: 50,
            backgroundColor: const Color.fromARGB(255, 174, 218, 228),
            activeColor: AppColors.lighPurpleColor,
            inactiveColor: AppColors.blackColor,
            currentIndex: 0,
            onTap: (index) {
            },
            items: [
              BottomNavigationBarItem(
                icon: GestureDetector(
                  child: Container(
                    padding: const EdgeInsets.all(10),
                    decoration: const BoxDecoration(
                      color: Colors.transparent,
                    ),
                    child: Image.asset(
                      Assets.kids,
                      color: Colors.black
                    ),
                  ),
                ),
                label: "screen1",
              ),
              BottomNavigationBarItem(
                icon: GestureDetector(
                  child: Container(
                    padding: EdgeInsets.all(getHeight() * 0.008),
                    decoration: const BoxDecoration(
                      color: Colors.transparent,
                    ),
                    child: Image.asset(
                      Assets.callHistory,
                      color: Colors.black
                    ),
                  ),
                ),
                label: "screen2",
              ),
              BottomNavigationBarItem(
                icon: GestureDetector(
                  child: Container(
                    padding: EdgeInsets.all(getHeight() * 0.008),
                    decoration: const BoxDecoration(
                      color: Colors.transparent,
                    ),
                    child: Image.asset(
                      Assets.profile,
                      color:Colors.black
                    ),
                  ),
                ),
                label: "screen3",
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

[Upload media here]

Logs

verbose_logs.pdf

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.0, on macOS 11.7.9 20G1426 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[!] Xcode - develop for iOS and macOS (Xcode 13.2.1)
    ✗ Flutter requires Xcode 14 or higher.
      Download the latest version or update via the Mac App Store.
[✓] Chrome - develop for the web
[✓] Android Studio (version 2022.2)
[✓] VS Code (version 1.83.1)
[✓] Connected device (3 available)
[✓] Network resources

! Doctor found issues in 1 category.

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: duplicateIssue is closed as a duplicate of an existing issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions