|
- import 'package:flutter/material.dart';
-
- import 'package:zhiying_comm/zhiying_comm.dart';
-
- typedef Widget CreateWidget(Map<String, dynamic> model);
-
- /* Widget生成工厂, 用于生成flutter端组件 */
- class WidgetFactory {
- static Map<String, CreateWidget> widgetCreater = Map();
-
- /**
- * @description: 注册组件
- * @param {name} 组件名,唯一
- * @return:
- */
- static void regist(String name, CreateWidget creater) {
- if (widgetCreater.containsKey(name)) {
- return;
- }
-
- widgetCreater[name] = creater;
- }
-
- /**
- * @description: 创建组件
- * @param {String} 组件注册的名字
- * @return:
- */
- static Widget create(String name, Map<String, dynamic> model) {
- if (widgetCreater.containsKey(name)) {
- return widgetCreater[name](model);
- }
- const bool inProduction = const bool.fromEnvironment("dart.vm.product");
- if (!inProduction) {
- return Container();
- } else {
- return Container(
- width: double.infinity,
- height: 100,
- color: Colors.redAccent,
- child: Center(
- child: Text('当前组件尚未注册'),
- ),
- );
- }
- }
-
- /**
- * @description: 是否注册组件
- * @param {bool}
- * @return:
- */
- static bool hasRegisted(String name) {
- return widgetCreater.containsKey(name);
- }
- }
|