基础库
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

page_factory.dart 1.9 KiB

4 anni fa
4 anni fa
4 anni fa
4 anni fa
4 anni fa
4 anni fa
4 anni fa
4 anni fa
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import 'package:flutter/material.dart';
  2. import 'package:zhiying_comm/zhiying_comm.dart';
  3. typedef Widget CreatePage(Map<String, dynamic> model);
  4. /* 页面生成工厂, 用于生成flutter端公共跳转页面,native端页面生成PlatforView等等 */
  5. class PageFactory {
  6. static Map<String, CreatePage> pageCreater = Map();
  7. /**
  8. * @description: 注册路由
  9. * @param {name} SkipUIIdentifier
  10. * @return:
  11. */
  12. static void regist(String name, CreatePage creater) {
  13. if (pageCreater.containsKey(name)) {
  14. return;
  15. }
  16. pageCreater[name] = creater;
  17. }
  18. /**
  19. * @description: 创建页面
  20. * @param {String} name注册的SkipUIIdentifier
  21. * @return:
  22. */
  23. static Widget create(String name, Map<String, dynamic> model) {
  24. if (pageCreater.containsKey(name)) {
  25. return pageCreater[name](model);
  26. }
  27. String tempName = _getSkipSuffix(name);
  28. if (!EmptyUtil.isEmpty(tempName) && pageCreater.containsKey(tempName)) {
  29. return pageCreater[tempName](model);
  30. }
  31. return EmptyPage();
  32. }
  33. // ⚠️ 由于使用了跳转标志带有后缀,所以需要判断是否带有后缀,如果带有并且是数字,则清除后缀获取page
  34. static String _getSkipSuffix(String name) {
  35. String tempName;
  36. try {
  37. String suffixStr = name.substring(name.lastIndexOf('.') + 1, name.length);
  38. tempName = name.substring(0, name.lastIndexOf('.'));
  39. Logger.log('sufix = $suffixStr , prefix = $tempName');
  40. int suffixNum = int.parse(suffixStr);
  41. Logger.log('suffixNum = $suffixNum}');
  42. } catch (e) {
  43. tempName = null;
  44. Logger.debug(e);
  45. }
  46. return tempName;
  47. }
  48. /**
  49. * @description: 是否注册页面
  50. * @param {bool}
  51. * @return:
  52. */
  53. static bool hasRegisted(String name) {
  54. if (pageCreater.containsKey(name)) {
  55. return true;
  56. }
  57. String tempName = _getSkipSuffix(name);
  58. if (pageCreater.containsKey(tempName)) {
  59. return true;
  60. }
  61. return false;
  62. }
  63. }