getx icon indicating copy to clipboard operation
getx copied to clipboard

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

Open ddxl123 opened this issue 5 months ago • 0 comments

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.

ddxl123 avatar Sep 05 '24 13:09 ddxl123