-
- import 'package:flutter/scheduler.dart';
- import 'package:get/get.dart';
- import 'package:get_storage/get_storage.dart';
-
- void routingCallback (routing) {
- GetStorage box = GetStorage();
- bool isLogin = box.hasData('token');
- bool isSplashScreen = routing?.current == '/splash';
- bool isLoginPage = routing?.current == '/login';
- if (!isLogin && !isSplashScreen && !isLoginPage) {
- // addPostFrameCallback 作用是等当前帧绘制完成之后再加载
- // https://github.com/jonataslaw/getx/issues/262
- SchedulerBinding.instance?.addPostFrameCallback((_) => Get.offNamed('/login'));
- }
- }
|