import 'package:flutter/material.dart';

import 'package:zhiying_comm/zhiying_comm.dart';

typedef Widget CreatePage(Map<String, dynamic> model);

/* 页面生成工厂, 用于生成flutter端公共跳转页面，native端页面生成PlatforView等等 */
class PageFactory {
  static Map<String, CreatePage> pageCreater = Map();

  /** 
   * @description: 注册路由 
   * @param {name} SkipUIIdentifier
   * @return: 
   */
  static void regist(String name, CreatePage creater) {
    if (pageCreater.containsKey(name)) {
      return;
    }

    pageCreater[name] = creater;
  }

  /**
   * @description: 创建页面
   * @param {String} name注册的SkipUIIdentifier
   * @return: 
   */
  static Widget create(String name, Map<String, dynamic> model) {
    if (pageCreater.containsKey(name)) {
      return pageCreater[name](model);
    }
    return EmptyPage();
  }

  /** 
   * @description: 是否注册页面
   * @param {bool} 
   * @return: 
   */
  static bool hasRegisted(String name) {
    return pageCreater.containsKey(name);
  }
}
