基础库
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

62 satır
1.7 KiB

  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. // ⚠️ 由于使用了跳转标志带有后缀,所以需要判断是否带有后缀,如果带有并且是数字,则清除后缀获取page
  28. String tempName;
  29. try{
  30. String suffixStr = name.substring(name.lastIndexOf('.') + 1, name.length);
  31. tempName = name.substring(0, name.lastIndexOf('.'));
  32. Logger.log('sufix = $suffixStr , prefix = $tempName');
  33. int suffixNum = int.parse(suffixStr);
  34. Logger.log('suffixNum = $suffixNum}');
  35. }catch(e){
  36. tempName = null;
  37. Logger.debug(e);
  38. }
  39. if(!EmptyUtil.isEmpty(tempName) && pageCreater.containsKey(tempName)){
  40. return pageCreater[tempName](model);
  41. }
  42. return EmptyPage();
  43. }
  44. /**
  45. * @description: 是否注册页面
  46. * @param {bool}
  47. * @return:
  48. */
  49. static bool hasRegisted(String name) {
  50. return pageCreater.containsKey(name);
  51. }
  52. }