diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4631d3a --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Flutter", + "program": "lib/main.dart", + "request": "launch", + "type": "dart" + } + ] +} \ No newline at end of file diff --git a/example/pubspec.lock b/example/pubspec.lock index f185896..6e86315 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -29,6 +29,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.5" + cached_network_image: + dependency: transitive + description: + name: cached_network_image + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.0+1" charcode: dependency: transitive description: @@ -36,6 +43,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.2" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" collection: dependency: transitive description: @@ -85,11 +99,25 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.0.10" + file: + dependency: transitive + description: + name: file + url: "https://pub.flutter-io.cn" + source: hosted + version: "5.2.1" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + flutter_cache_manager: + dependency: transitive + description: + name: flutter_cache_manager + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.4.1" flutter_native_image: dependency: transitive description: @@ -114,6 +142,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "7.0.4" + http: + dependency: transitive + description: + name: http + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.12.2" http_parser: dependency: transitive description: @@ -128,6 +163,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.4" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.16.1" matcher: dependency: transitive description: @@ -156,6 +198,34 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.6.4" + path_provider: + dependency: transitive + description: + name: path_provider + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.6.14" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.1+2" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.4+3" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.3" pedantic: dependency: transitive description: @@ -170,6 +240,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.4.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.1" plugin_platform_interface: dependency: transitive description: @@ -177,6 +254,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.2" + process: + dependency: transitive + description: + name: process + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.13" quiver: dependency: transitive description: @@ -184,6 +268,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.5" + rxdart: + dependency: transitive + description: + name: rxdart + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.24.1" sky_engine: dependency: transitive description: flutter @@ -196,6 +287,20 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.5.5" + sqflite: + dependency: transitive + description: + name: sqflite + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.3.1+1" + sqflite_common: + dependency: transitive + description: + name: sqflite_common + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.2+1" stack_trace: dependency: transitive description: @@ -217,6 +322,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.5" + synchronized: + dependency: transitive + description: + name: synchronized + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.0" term_glyph: dependency: transitive description: @@ -238,6 +350,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.6" + uuid: + dependency: transitive + description: + name: uuid + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.2" vector_math: dependency: transitive description: @@ -245,6 +364,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.8" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.0" xml: dependency: transitive description: diff --git a/lib/util/widget_creater.dart b/lib/util/widget_creater.dart new file mode 100644 index 0000000..30d2117 --- /dev/null +++ b/lib/util/widget_creater.dart @@ -0,0 +1,11 @@ +import 'package:flutter/material.dart'; + +abstract class WidgetCreater { + List createWidgets(Map model); + + List createSkeleton(Map model); + + bool isSliverChild() { + return false; + } +} diff --git a/lib/util/widget_factory.dart b/lib/util/widget_factory.dart index ff31c1c..96f5c5f 100644 --- a/lib/util/widget_factory.dart +++ b/lib/util/widget_factory.dart @@ -1,24 +1,24 @@ import 'package:flutter/material.dart'; - import 'package:zhiying_comm/zhiying_comm.dart'; -typedef Widget CreateWidget(Map model); +enum WidgetType { + normal, // 正常状态 + skeleton, // 显示骨架 +} /* Widget生成工厂, 用于生成flutter端组件 */ class WidgetFactory { - static Map widgetCreater = Map(); + static Map widgetCreaters = Map(); /** * @description: 注册组件 * @param {name} 组件名,唯一 * @return: */ - static void regist(String name, CreateWidget creater) { - if (widgetCreater.containsKey(name)) { - return; + static void regist(String name, WidgetCreater creater) { + if (!widgetCreaters.containsKey(name)) { + widgetCreaters[name] = creater; } - - widgetCreater[name] = creater; } /** @@ -26,22 +26,46 @@ class WidgetFactory { * @param {String} 组件注册的名字 * @return: */ - static Widget create(String name, Map model) { - if (widgetCreater.containsKey(name)) { - return widgetCreater[name](model); + static List create( + String name, { + // 组件名 + Map model, + WidgetType type, // 组件显示类型,普通/骨架 + bool isSliver, // 是否加载sliver组件 + }) { + WidgetCreater creater; + if (widgetCreaters.containsKey(name)) { + creater = widgetCreaters[name]; + List result = []; + if (type == WidgetType.normal) + result = creater.createWidgets(model); + else + result = creater.createSkeleton(model); + if (isSliver) { + if (creater.isSliverChild()) { + return result; + } else { + return result.map((widget) { + return SliverToBoxAdapter(child: widget); + }).toList(); + } + } else { + if (creater.isSliverChild()) { + return _createEmpty(); + } else { + return result; + } + } } + return _createEmpty(); + } + + static List _createEmpty() { const bool inProduction = const bool.fromEnvironment("dart.vm.product"); if (!inProduction) { - return Container(); + return []; } else { - return Container( - width: double.infinity, - height: 100, - color: Colors.redAccent, - child: Center( - child: Text('当前组件尚未注册'), - ), - ); + return [EmptyPage()]; } } @@ -51,6 +75,6 @@ class WidgetFactory { * @return: */ static bool hasRegisted(String name) { - return widgetCreater.containsKey(name); + return widgetCreaters.containsKey(name); } } diff --git a/lib/zhiying_comm.dart b/lib/zhiying_comm.dart index 1600c0b..a7bb149 100644 --- a/lib/zhiying_comm.dart +++ b/lib/zhiying_comm.dart @@ -3,6 +3,8 @@ library zhiying_comm; // pages export 'pages/empty_page.dart'; +export 'util/widget_creater.dart'; + // utils export 'util/color.dart'; export 'util/native_util.dart'; diff --git a/pubspec.lock b/pubspec.lock index bcd811f..67d39b4 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -29,6 +29,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.5" + cached_network_image: + dependency: "direct main" + description: + name: cached_network_image + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.0+1" charcode: dependency: transitive description: @@ -36,6 +43,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.2" + clock: + dependency: transitive + description: + name: clock + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.1" collection: dependency: transitive description: @@ -78,11 +92,25 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.0.10" + file: + dependency: transitive + description: + name: file + url: "https://pub.flutter-io.cn" + source: hosted + version: "5.2.1" flutter: dependency: "direct main" description: flutter source: sdk version: "0.0.0" + flutter_cache_manager: + dependency: transitive + description: + name: flutter_cache_manager + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.4.1" flutter_native_image: dependency: "direct main" description: @@ -107,6 +135,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "7.0.4" + http: + dependency: transitive + description: + name: http + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.12.2" http_parser: dependency: transitive description: @@ -121,6 +156,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.4" + intl: + dependency: transitive + description: + name: intl + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.16.1" matcher: dependency: transitive description: @@ -149,6 +191,34 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.6.4" + path_provider: + dependency: transitive + description: + name: path_provider + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.6.14" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.1+2" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.4+3" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.3" pedantic: dependency: transitive description: @@ -163,6 +233,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.4.0" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.1" plugin_platform_interface: dependency: transitive description: @@ -170,6 +247,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.2" + process: + dependency: transitive + description: + name: process + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.13" quiver: dependency: transitive description: @@ -177,6 +261,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.5" + rxdart: + dependency: transitive + description: + name: rxdart + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.24.1" sky_engine: dependency: transitive description: flutter @@ -189,6 +280,20 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.5.5" + sqflite: + dependency: transitive + description: + name: sqflite + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.3.1+1" + sqflite_common: + dependency: transitive + description: + name: sqflite_common + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.2+1" stack_trace: dependency: transitive description: @@ -210,6 +315,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.0.5" + synchronized: + dependency: transitive + description: + name: synchronized + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.0" term_glyph: dependency: transitive description: @@ -231,6 +343,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.6" + uuid: + dependency: transitive + description: + name: uuid + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.2" vector_math: dependency: transitive description: @@ -238,6 +357,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.0.8" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.0" xml: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 4be333f..3a4c091 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,6 +16,7 @@ dependencies: device_info: ^0.4.0+1 flutter_native_image: ^0.0.5 fluttertoast: ^7.0.4 + cached_network_image: ^2.2.0+1 dev_dependencies: flutter_test: