getx icon indicating copy to clipboard operation
getx copied to clipboard

No action from WillPopScope with GetRouterOutlet

Open victordsgamorim opened this issue 2 years ago • 1 comments

Describe the bug Have been trying GetRouterOutlet to work with the routing, and did simple pages to test it. However, using WillPopScope seems to be affected when tapped. Follow the code below.

class RootPage extends GetView<AuthController> {
  const RootPage ({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetRouterOutlet.builder(
      builder: (context, delegate, currentRoute) {
        return WillPopScope(
          onWillPop: () async {
            return false;  **<-- theoretically  should not pop, but it is.**
          },
          child: Scaffold(
              resizeToAvoidBottomInset: false,
              body: controller.obx(
                  (state) => GetRouterOutlet(
                        delegate: delegate,
                        initialRoute: Routes.dashboard,
                      ),
                  onError: (_) => GetRouterOutlet(initialRoute: Routes.login))),
        );
      },
    );
  }
}

/***MATERIAL APP ****/

class AppWidget extends StatelessWidget {
  const AppWidget({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp.router(
      debugShowCheckedModeBanner: false,
      theme: AppTheme.appTheme,
      getPages: AppRoute.routes,
      initialBinding: GlobalBindings(),
      defaultTransition: Transition.noTransition,
    );
  }
}

The behaviour expected, according to the code above is to not get back, as you could see it's false. However, is getting back to the previous page.

Flutter Version: Flutter 2.10.4 Engine • revision 57d3bac3dd Tools • Dart 2.16.2 • DevTools 2.9.2

Getx Version: get: ^4.6.5

Describe on which device you found the bug: ex: Android Mobile Phone

victordsgamorim avatar May 24 '22 18:05 victordsgamorim

Did you find anty solution?

pradeep14598 avatar Sep 16 '22 08:09 pradeep14598

@pradeep14598

you can try this

class MyBackButtonDispatcher extends RootBackButtonDispatcher {
  @override
  Future<bool> didPopRoute() async {
    var currentPageName = Get.rootDelegate.currentConfiguration?.currentPage!.name;
    if (currentPageName!.startsWith("/user")) {
      // cant back
      return true;
    }
    // back
    return super.didPopRoute();
  }
}

return GetMaterialApp.router(
    title: "Application",
    initialBinding: BindingsBuilder(
      () {
        Get.put(HomeService());
        Get.put(AuthService());
        Get.put(AuthServiceTest());
      },
    ),
    getPages: AppPages.routes,
    theme: themeData,
    backButtonDispatcher: MyBackButtonDispatcher(),

m-mine avatar Oct 05 '23 05:10 m-mine