getx icon indicating copy to clipboard operation
getx copied to clipboard

canPop in PopScope not working on iOS

Open bkleineibst opened this issue 1 year ago • 11 comments
trafficstars

Describe the bug When setting canPop to false in a page's PopScope, and navigating to that page with Get.to(popGesture: false, Page()), I am still able to swipe to go back on iOS. The back button navigation is blocked, but not the gesture.

I followed the advice in #3071, but it doesn't seem to work. Works if I use standard Flutter navigation (canPop: false).

**Reproduction code example:

import 'package:flutter/material.dart';
import 'package:get/get.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      popGesture: false,
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatelessWidget {
  final String title;

  const MyHomePage({super.key, required this.title});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ElevatedButton(
              onPressed: () => Get.to(popGesture: false, () => const Page2()),
              child: const Text('Go to page 2'),
            ),
          ],
        ),
      ),
    );
  }
}

class Page2 extends StatelessWidget {
  const Page2({super.key});

  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: false,
      child: Scaffold(
        appBar: AppBar(
          backgroundColor: Theme.of(context).colorScheme.inversePrimary,
          title: const Text('Page 2'),
        ),
        body: const Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text('Page 2'),
            ],
          ),
        ),
      ),
    );
  }
}

To Reproduce Steps to reproduce the behavior:

  1. Run above sample on iOS simulator.
  2. Click on 'Go to page 2'
  3. Swipe to go back

Expected behavior Back navigation with gesture should be disabled.

Flutter Version: Tested on master and 3.22.2

Getx Version: 4.6.6

Describe on which device you found the bug: iOS simulator

Minimal reproduce code See above.

bkleineibst avatar Jul 03 '24 22:07 bkleineibst

Have you solved the problem? I have the same problem

wubaibin avatar Jul 08 '24 00:07 wubaibin

You can try the old api,WillPopScope

hugang1102 avatar Jul 22 '24 07:07 hugang1102

Has anyone found a fix for this yet. Still not working on iOS

icodelabs2 avatar Aug 05 '24 20:08 icodelabs2

Has anyone found a fix for this yet. Still not working on iOS

It's not working on flutter 3.22 and GetX 4.6.6.

The workaround is either downgrade flutter, or using native router, Navigator.of(context) to handler this case. And with the native router, you have to handle the GetX lifecycle manually, with initializing and disposing controllers.

sundong212 avatar Aug 05 '24 20:08 sundong212

You can try the old api,WillPopScope

It's work. The Getx has the parameter popGesture in the GetPage class, but it does not work!

Abson avatar Aug 23 '24 10:08 Abson

Any update of this issue?

WindBise avatar Sep 01 '24 14:09 WindBise

You can try the old api,WillPopScope

Not working for me. flutter 3.22.2 and GetX 4.6.6. When i change from PopScope to WillPopScope, cannot pop even return true

WindBise avatar Sep 01 '24 15:09 WindBise

I meet the same problem.

  • Flutter 3.24.2
  • GetX 4.6.6

It does works at Flutter 3.16.x

Btw, Google request all app update with 3.22.x or later for Google Play.

wxd79 avatar Sep 12 '24 09:09 wxd79

CupertinoPageRoute by default prioritizes handling the system back gesture (swipe-to-go-back), which may bypass the logic of WillPopScope or PopScope. (From ChatGPT), so transition of page can't be set to Transition.cupertino.

shixiwen000 avatar Dec 08 '24 18:12 shixiwen000

Same Issue. Anyone fix it?

shanelau avatar Dec 25 '24 04:12 shanelau

Using the latest version 4.7.2, this problem is resolved

KirstenDunst avatar Mar 13 '25 08:03 KirstenDunst

Can I get solution?

here is my code which in working in android but not in ios

From screenA Get.to(() => const ScreenB());

ScreenB willpopscope not working and also not trigerring any functions inside popscope.

lakshydeep-14 avatar Jul 02 '25 09:07 lakshydeep-14

Using the latest version 4.7.2, this problem is resolved

not working

kennenfromchina avatar Sep 01 '25 05:09 kennenfromchina