基础库
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

49 linhas
1.7 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:provider/provider.dart';
  3. import 'package:zhiying_comm/pages/login_page/login_page.dart';
  4. import 'package:zhiying_comm/zhiying_comm.dart';
  5. class RouterUtil {
  6. /*公共跳转
  7. * skipModel 跳转参数
  8. * data 额外参数
  9. * */
  10. static Future route(SkipModel skipModel, Map<String, dynamic> data,
  11. BuildContext context) async {
  12. if (skipModel.skipIdentifier == null || skipModel.skipIdentifier == '') {
  13. print('skipIdentifier 参数不存在,无法跳转页面');
  14. return Future.error('skipIdentifier 参数不存在,无法跳转页面');
  15. }
  16. print('skipIdentifier: ${skipModel.skipIdentifier}');
  17. if (skipModel?.requiredLogin == '1') {
  18. UserInfoModel user =
  19. await Provider.of<UserInfoNotifier>(context, listen: false)
  20. .getUserInfoModel();
  21. print(user.toString());
  22. if (user?.token == null || user.token == '') {
  23. print('need login...');
  24. return Navigator.of(context)
  25. .push(MaterialPageRoute(builder: (BuildContext context) {
  26. return LoginPage();
  27. }));
  28. }
  29. }
  30. Widget page = EmptyPage();
  31. if (PageFactory.hasRegisted(skipModel.skipIdentifier)) {
  32. page = PageFactory.create(skipModel.skipIdentifier, data);
  33. } else {
  34. var result = await NetUtil.post(
  35. '/api/v1/mod/${skipModel.skipIdentifier.toString()}',
  36. method: NetMethod.GET);
  37. Logger.debug(result);
  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. }