jonataslaw / getx

Open screens/snackbars/dialogs/bottomSheets without context, manage states and inject dependencies easily with Get.
MIT License
10.44k stars 1.64k forks source link

canPop in PopScope not working on iOS #3140

Open bkleineibst opened 5 months ago

bkleineibst commented 5 months ago

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.

wubaibin commented 4 months ago

Have you solved the problem? I have the same problem

hugang1102 commented 4 months ago

You can try the old api,WillPopScope

ALI-SAMPSON commented 4 months ago

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

sundong212 commented 4 months ago

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.

Abson commented 3 months ago

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!

WindBise commented 3 months ago

Any update of this issue?

WindBise commented 3 months ago

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

wxd79 commented 2 months ago

I meet the same problem.

It does works at Flutter 3.16.x

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