基础库
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

50 lines
1.7 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 =
  20. await Provider.of<UserInfoNotifier>(context, listen: false)
  21. .getUserInfoModel();
  22. print(user.toString());
  23. if (user?.token == null || user.token == '') {
  24. print('need login...');
  25. return Navigator.of(context)
  26. .push(MaterialPageRoute(builder: (BuildContext context) {
  27. return LoginPage(model);
  28. }));
  29. }
  30. }
  31. Widget page = EmptyPage();
  32. if (PageFactory.hasRegisted(skipIdentifier)) {
  33. page = PageFactory.create(skipIdentifier, model);
  34. } else {
  35. Api api = Api('/api/v1/mod/${skipIdentifier.toString()}',
  36. method: NetMethod.GET);
  37. var result = await api.onRequest();
  38. page = PageFactory.create('index', Map<String, dynamic>.from(result));
  39. }
  40. return Navigator.of(context)
  41. .push(MaterialPageRoute(builder: (BuildContext context) {
  42. return page;
  43. }));
  44. }
  45. }