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

When using GetMaterialApp with PopScope(canPop: false), pressing the physical back button still results in being navigated back. #3206

Open
ddxl123 opened this issue Sep 5, 2024 · 0 comments
Assignees

Comments

@ddxl123
Copy link

ddxl123 commented Sep 5, 2024

class FlutterTest extends StatefulWidget {
  const FlutterTest({super.key});

  @override
  State<FlutterTest> createState() => _FlutterTestState();
}

class _FlutterTestState extends State<FlutterTest> {
  @override
  Widget build(BuildContext context) {
    return const GetMaterialApp(home: A());
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: Center(
        child: TextButton(
          child: const Text('to B'),
          onPressed: () {
            Get.to(() => const B());
          },
        ),
      ),
    );
  }
}

class B extends StatefulWidget {
  const B({super.key});

  @override
  State<B> createState() => _BState();
}

class _BState extends State<B> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(),
      body: const PopScope(
        canPop: false,
        child: Text("B Page"),
      ),
    );
  }
}

If you use MaterialApp with Navigator.push, you can prevent going back.

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