jonataslaw / getx

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

Getx Middleware is not properly working in getx-5 update #3177

Closed anoojkv closed 3 months ago

anoojkv commented 3 months ago

Firstly,Thank you For a Great Package

class LoginMiddleware extends GetMiddleware {
  @override
  int? get priority => 1;

  @override
  @override
  RouteSettings? redirect(String? route) {
    if (StorageManager.instance!.getStringValue(
          StorageManager.xToken,
        ) !=
        null) {
      if (StorageManager.instance!.getBoolValue(
            StorageManager.isFirst,
          ) ==
          null) {
        return RouteSettings(name: AppRoutes.onBoardingPage);
      } else {
        return RouteSettings(name: AppRoutes.mainHomePage);
      }
    }
    return null;
  }
}

Middleware is working well in get: ^4.6.6 but it is not working in the get: ^5.0.0-release-candidate-8. Is any changes in get 5 middleware? Provide a minimum reproduction code for the problem

jonataslaw commented 3 months ago

redirect is being rewritten, because it is a bit rigid. I mean, I want to give superpowers to the devs, who can choose a redirect based on a parameter that was received in another lower priority middleware, or according to the stack size, or whatever they want. The old api was limited, and I'm improving that. Maybe this will work for you out of the box (but redirectDelegate will be renamed to "redirect" in the final version)

class LoginMiddleware extends GetMiddleware {
  @override
  int? get priority => 1;

  @override
  @override
  RouteDecoder? redirectDelegate(RouteDecoder? route) {
    if (StorageManager.instance!.getStringValue(
          StorageManager.xToken,
        ) !=
        null) {
      if (StorageManager.instance!.getBoolValue(
            StorageManager.isFirst,
          ) ==
          null) {
        return RouteDecoder.fromRoute(AppRoutes.onBoardingPage);
      } else {
        return RouteDecoder.fromRoute(AppRoutes.mainHomePage);
      }
    }
    return null;
  }
}