middleWares.dart 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import 'package:flutter/scheduler.dart';
  2. import 'package:get/get.dart';
  3. import 'package:get_storage/get_storage.dart';
  4. import 'package:farmer_client/utils/tool.dart';
  5. var whiteList = [
  6. '/',
  7. '/splash',
  8. '/login',
  9. '/agreement',
  10. ];
  11. void routingCallback(routing) {
  12. print("---------routingCallback---------");
  13. print(routing?.current);
  14. print(whiteList.contains(routing?.current));
  15. if (!isLogin()) {
  16. if (!whiteList.contains(routing?.current)) {
  17. print('----will be to login page----->');
  18. // addPostFrameCallback 作用是等当前帧绘制完成之后再加载
  19. // https://github.com/jonataslaw/getx/issues/262
  20. SchedulerBinding.instance?.addPostFrameCallback((_) => Get.offNamed('/login'));
  21. }
  22. }
  23. // bool isLogin = box.hasData('token');
  24. // bool isSplashScreen = routing?.current == '/splash';
  25. // bool isLoginPage = routing?.current == '/login';
  26. // bool isAgreementPage = routing?.current == '/agreement';
  27. // if (!isLogin && !isSplashScreen && !isLoginPage&&!isAgreementPage) {
  28. // addPostFrameCallback 作用是等当前帧绘制完成之后再加载
  29. // https://github.com/jonataslaw/getx/issues/262
  30. // SchedulerBinding.instance?.addPostFrameCallback((_) => Get.offNamed('/login'));
  31. // }
  32. }