基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

40 lines
1.5 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:zhiying_comm/pages/login_page/login_page.dart';
  3. import 'package:zhiying_comm/zhiying_comm.dart';
  4. import 'package:provider/provider.dart';
  5. class RouterUtil {
  6. static Future route(Map<String, dynamic> model, BuildContext context) async {
  7. // 唯一跳转标识
  8. String skipIdentifier = model['skip_identifier'].toString();
  9. // 需要登录
  10. String requiredLogin = model['required_login'].toString();
  11. // 需要淘宝授权
  12. String requiredTaobaoAuth = model['required_taobao_auth'].toString();
  13. if (skipIdentifier == null || skipIdentifier == '') {
  14. print('skipIdentifier 参数不存在,无法跳转页面');
  15. return Future.error('skipIdentifier 参数不存在,无法跳转页面');
  16. }
  17. print('skipIdentifier: ${skipIdentifier}');
  18. if (requiredLogin == '1') {
  19. UserInfoModel user = await Provider.of<UserInfoNotifier>(context, listen: false).getUserInfoModel();
  20. print(user.toString());
  21. if (user?.token == null || user.token == '') {
  22. print('need login...');
  23. return Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {
  24. return LoginPage(model);
  25. }));
  26. }
  27. }
  28. return Navigator.of(context).push(MaterialPageRoute(builder: (BuildContext context) {
  29. if (PageFactory.hasRegisted(skipIdentifier)) {
  30. return PageFactory.create(skipIdentifier, model);
  31. }
  32. return EmptyPage();
  33. }));
  34. }
  35. }