init static method

void init({
  1. required Function jump2LoginCallback,
  2. dynamic unAuthCode,
  3. int? maintenanceCode,
  4. Function? jump2UnderMaintenanceCallback,
})

initialize function

The jump2LoginCallback required argument specifies how to jump to login page, depends on what your routing library:

FluroRouter example

String? currentRoute = ModalRoute.of(context)?.settings.name;
if(currentRoute?.split("?").first == "/login") { return ; }
FluroRouter().navigateTo(context, "/login", clearStack: true);

GoRouter example

String? currentRoute = GoRouter.of(context).location;
if(currentRoute?.split("?").first == "/login") { return ; }
GoRouter(routes: []).go("/login");

The unAuthCode optional argument specifies which response (in format {code, message, data}) code (101 in default) should trigger jump2LoginCallback, split by | if multiple code supported.

The maintenanceCode optional argument specifies which response (in format {code, message, data}) code should trigger jump2UnderMaintenanceCallback. NOTE: If no maintenanceCode specified, means do not support maintenance jump for all requests

The jump2UnderMaintenanceCallback optional argument specifies how to jump to under maintenance page, depends on what your routing library, similar to jump2LoginCallback

Implementation

static void init(
    {required Function jump2LoginCallback,
    dynamic unAuthCode,
    int? maintenanceCode,
    Function? jump2UnderMaintenanceCallback}) {
  assert(
      unAuthCode == null ||
          unAuthCode is int ||
          unAuthCode is String ||
          unAuthCode is List<int>,
      "invalid type of unAuthCode !");
  if (unAuthCode is int || unAuthCode is String) {
    _unAuthCode = unAuthCode
        .toString()
        .split("|")
        .map((ele) => int.parse(ele))
        .toList();
  } else if (unAuthCode is List<int>) {
    _unAuthCode = unAuthCode;
  }

  _maintenanceCode = maintenanceCode;

  _onJump2Login = jump2LoginCallback;
  _onJump2UnderMaintenance = jump2UnderMaintenanceCallback;
}