基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
1.3 KiB

  1. import 'package:flutter/material.dart';
  2. import 'package:zhiying_comm/zhiying_comm.dart';
  3. typedef Widget CreateWidget(Map<String, dynamic> model);
  4. /* Widget生成工厂, 用于生成flutter端组件 */
  5. class WidgetFactory {
  6. static Map<String, CreateWidget> widgetCreater = Map();
  7. /**
  8. * @description: 注册组件
  9. * @param {name} 组件名,唯一
  10. * @return:
  11. */
  12. static void regist(String name, CreateWidget creater) {
  13. if (widgetCreater.containsKey(name)) {
  14. return;
  15. }
  16. widgetCreater[name] = creater;
  17. }
  18. /**
  19. * @description: 创建组件
  20. * @param {String} 组件注册的名字
  21. * @return:
  22. */
  23. static Widget create(String name, Map<String, dynamic> model) {
  24. if (widgetCreater.containsKey(name)) {
  25. return widgetCreater[name](model);
  26. }
  27. const bool inProduction = const bool.fromEnvironment("dart.vm.product");
  28. if (!inProduction) {
  29. return Container();
  30. } else {
  31. return Container(
  32. width: double.infinity,
  33. height: 100,
  34. color: Colors.redAccent,
  35. child: Center(
  36. child: Text('当前组件尚未注册'),
  37. ),
  38. );
  39. }
  40. }
  41. /**
  42. * @description: 是否注册组件
  43. * @param {bool}
  44. * @return:
  45. */
  46. static bool hasRegisted(String name) {
  47. return widgetCreater.containsKey(name);
  48. }
  49. }