jonataslaw / getx

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

No action from WillPopScope with GetRouterOutlet #2381

Open victordsgamorim opened 2 years ago

victordsgamorim commented 2 years ago

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

pradeep14598 commented 2 years ago

Did you find anty solution?

m-mine commented 1 year ago

@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(),