@@ -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" | |||||
} | |||||
] | |||||
} |
@@ -29,6 +29,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.0.5" | 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: | charcode: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -36,6 +43,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.1.2" | version: "1.1.2" | ||||
clock: | |||||
dependency: transitive | |||||
description: | |||||
name: clock | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "1.0.1" | |||||
collection: | collection: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -85,11 +99,25 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "3.0.10" | version: "3.0.10" | ||||
file: | |||||
dependency: transitive | |||||
description: | |||||
name: file | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "5.2.1" | |||||
flutter: | flutter: | ||||
dependency: "direct main" | dependency: "direct main" | ||||
description: flutter | description: flutter | ||||
source: sdk | source: sdk | ||||
version: "0.0.0" | 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: | flutter_native_image: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -114,6 +142,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "7.0.4" | version: "7.0.4" | ||||
http: | |||||
dependency: transitive | |||||
description: | |||||
name: http | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "0.12.2" | |||||
http_parser: | http_parser: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -128,6 +163,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "2.1.4" | version: "2.1.4" | ||||
intl: | |||||
dependency: transitive | |||||
description: | |||||
name: intl | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "0.16.1" | |||||
matcher: | matcher: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -156,6 +198,34 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.6.4" | 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: | pedantic: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -170,6 +240,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "2.4.0" | 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: | plugin_platform_interface: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -177,6 +254,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.0.2" | version: "1.0.2" | ||||
process: | |||||
dependency: transitive | |||||
description: | |||||
name: process | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "3.0.13" | |||||
quiver: | quiver: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -184,6 +268,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "2.0.5" | version: "2.0.5" | ||||
rxdart: | |||||
dependency: transitive | |||||
description: | |||||
name: rxdart | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "0.24.1" | |||||
sky_engine: | sky_engine: | ||||
dependency: transitive | dependency: transitive | ||||
description: flutter | description: flutter | ||||
@@ -196,6 +287,20 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.5.5" | 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: | stack_trace: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -217,6 +322,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.0.5" | version: "1.0.5" | ||||
synchronized: | |||||
dependency: transitive | |||||
description: | |||||
name: synchronized | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "2.2.0" | |||||
term_glyph: | term_glyph: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -238,6 +350,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.1.6" | version: "1.1.6" | ||||
uuid: | |||||
dependency: transitive | |||||
description: | |||||
name: uuid | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "2.2.2" | |||||
vector_math: | vector_math: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -245,6 +364,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "2.0.8" | 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: | xml: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -0,0 +1,11 @@ | |||||
import 'package:flutter/material.dart'; | |||||
abstract class WidgetCreater { | |||||
List<Widget> createWidgets(Map<String, dynamic> model); | |||||
List<Widget> createSkeleton(Map<String, dynamic> model); | |||||
bool isSliverChild() { | |||||
return false; | |||||
} | |||||
} |
@@ -1,24 +1,24 @@ | |||||
import 'package:flutter/material.dart'; | import 'package:flutter/material.dart'; | ||||
import 'package:zhiying_comm/zhiying_comm.dart'; | import 'package:zhiying_comm/zhiying_comm.dart'; | ||||
typedef Widget CreateWidget(Map<String, dynamic> model); | |||||
enum WidgetType { | |||||
normal, // 正常状态 | |||||
skeleton, // 显示骨架 | |||||
} | |||||
/* Widget生成工厂, 用于生成flutter端组件 */ | /* Widget生成工厂, 用于生成flutter端组件 */ | ||||
class WidgetFactory { | class WidgetFactory { | ||||
static Map<String, CreateWidget> widgetCreater = Map(); | |||||
static Map<String, WidgetCreater> widgetCreaters = Map(); | |||||
/** | /** | ||||
* @description: 注册组件 | * @description: 注册组件 | ||||
* @param {name} 组件名,唯一 | * @param {name} 组件名,唯一 | ||||
* @return: | * @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} 组件注册的名字 | * @param {String} 组件注册的名字 | ||||
* @return: | * @return: | ||||
*/ | */ | ||||
static Widget create(String name, Map<String, dynamic> model) { | |||||
if (widgetCreater.containsKey(name)) { | |||||
return widgetCreater[name](model); | |||||
static List<Widget> create( | |||||
String name, { | |||||
// 组件名 | |||||
Map<String, dynamic> model, | |||||
WidgetType type, // 组件显示类型,普通/骨架 | |||||
bool isSliver, // 是否加载sliver组件 | |||||
}) { | |||||
WidgetCreater creater; | |||||
if (widgetCreaters.containsKey(name)) { | |||||
creater = widgetCreaters[name]; | |||||
List<Widget> 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<Widget> _createEmpty() { | |||||
const bool inProduction = const bool.fromEnvironment("dart.vm.product"); | const bool inProduction = const bool.fromEnvironment("dart.vm.product"); | ||||
if (!inProduction) { | if (!inProduction) { | ||||
return Container(); | |||||
return []; | |||||
} else { | } else { | ||||
return Container( | |||||
width: double.infinity, | |||||
height: 100, | |||||
color: Colors.redAccent, | |||||
child: Center( | |||||
child: Text('当前组件尚未注册'), | |||||
), | |||||
); | |||||
return [EmptyPage()]; | |||||
} | } | ||||
} | } | ||||
@@ -51,6 +75,6 @@ class WidgetFactory { | |||||
* @return: | * @return: | ||||
*/ | */ | ||||
static bool hasRegisted(String name) { | static bool hasRegisted(String name) { | ||||
return widgetCreater.containsKey(name); | |||||
return widgetCreaters.containsKey(name); | |||||
} | } | ||||
} | } |
@@ -3,6 +3,8 @@ library zhiying_comm; | |||||
// pages | // pages | ||||
export 'pages/empty_page.dart'; | export 'pages/empty_page.dart'; | ||||
export 'util/widget_creater.dart'; | |||||
// utils | // utils | ||||
export 'util/color.dart'; | export 'util/color.dart'; | ||||
export 'util/native_util.dart'; | export 'util/native_util.dart'; | ||||
@@ -29,6 +29,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.0.5" | 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: | charcode: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -36,6 +43,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.1.2" | version: "1.1.2" | ||||
clock: | |||||
dependency: transitive | |||||
description: | |||||
name: clock | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "1.0.1" | |||||
collection: | collection: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -78,11 +92,25 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "3.0.10" | version: "3.0.10" | ||||
file: | |||||
dependency: transitive | |||||
description: | |||||
name: file | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "5.2.1" | |||||
flutter: | flutter: | ||||
dependency: "direct main" | dependency: "direct main" | ||||
description: flutter | description: flutter | ||||
source: sdk | source: sdk | ||||
version: "0.0.0" | 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: | flutter_native_image: | ||||
dependency: "direct main" | dependency: "direct main" | ||||
description: | description: | ||||
@@ -107,6 +135,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "7.0.4" | version: "7.0.4" | ||||
http: | |||||
dependency: transitive | |||||
description: | |||||
name: http | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "0.12.2" | |||||
http_parser: | http_parser: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -121,6 +156,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "2.1.4" | version: "2.1.4" | ||||
intl: | |||||
dependency: transitive | |||||
description: | |||||
name: intl | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "0.16.1" | |||||
matcher: | matcher: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -149,6 +191,34 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.6.4" | 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: | pedantic: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -163,6 +233,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "2.4.0" | 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: | plugin_platform_interface: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -170,6 +247,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.0.2" | version: "1.0.2" | ||||
process: | |||||
dependency: transitive | |||||
description: | |||||
name: process | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "3.0.13" | |||||
quiver: | quiver: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -177,6 +261,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "2.0.5" | version: "2.0.5" | ||||
rxdart: | |||||
dependency: transitive | |||||
description: | |||||
name: rxdart | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "0.24.1" | |||||
sky_engine: | sky_engine: | ||||
dependency: transitive | dependency: transitive | ||||
description: flutter | description: flutter | ||||
@@ -189,6 +280,20 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.5.5" | 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: | stack_trace: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -210,6 +315,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.0.5" | version: "1.0.5" | ||||
synchronized: | |||||
dependency: transitive | |||||
description: | |||||
name: synchronized | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "2.2.0" | |||||
term_glyph: | term_glyph: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -231,6 +343,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "1.1.6" | version: "1.1.6" | ||||
uuid: | |||||
dependency: transitive | |||||
description: | |||||
name: uuid | |||||
url: "https://pub.flutter-io.cn" | |||||
source: hosted | |||||
version: "2.2.2" | |||||
vector_math: | vector_math: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -238,6 +357,13 @@ packages: | |||||
url: "https://pub.flutter-io.cn" | url: "https://pub.flutter-io.cn" | ||||
source: hosted | source: hosted | ||||
version: "2.0.8" | 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: | xml: | ||||
dependency: transitive | dependency: transitive | ||||
description: | description: | ||||
@@ -16,6 +16,7 @@ dependencies: | |||||
device_info: ^0.4.0+1 | device_info: ^0.4.0+1 | ||||
flutter_native_image: ^0.0.5 | flutter_native_image: ^0.0.5 | ||||
fluttertoast: ^7.0.4 | fluttertoast: ^7.0.4 | ||||
cached_network_image: ^2.2.0+1 | |||||
dev_dependencies: | dev_dependencies: | ||||
flutter_test: | flutter_test: | ||||