Pārlūkot izejas kodu

更新widget生成方式

tags/0.0.1
Weller pirms 4 gadiem
vecāks
revīzija
4155ed417a
7 mainītis faili ar 325 papildinājumiem un 21 dzēšanām
  1. +14
    -0
      .vscode/launch.json
  2. +126
    -0
      example/pubspec.lock
  3. +11
    -0
      lib/util/widget_creater.dart
  4. +45
    -21
      lib/util/widget_factory.dart
  5. +2
    -0
      lib/zhiying_comm.dart
  6. +126
    -0
      pubspec.lock
  7. +1
    -0
      pubspec.yaml

+ 14
- 0
.vscode/launch.json Parādīt failu

@@ -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"
}
]
}

+ 126
- 0
example/pubspec.lock Parādīt failu

@@ -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:


+ 11
- 0
lib/util/widget_creater.dart Parādīt failu

@@ -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;
}
}

+ 45
- 21
lib/util/widget_factory.dart Parādīt failu

@@ -1,24 +1,24 @@
import 'package:flutter/material.dart';

import 'package:zhiying_comm/zhiying_comm.dart';

typedef Widget CreateWidget(Map<String, dynamic> model);
enum WidgetType {
normal, // 正常状态
skeleton, // 显示骨架
}

/* Widget生成工厂, 用于生成flutter端组件 */
class WidgetFactory {
static Map<String, CreateWidget> widgetCreater = Map();
static Map<String, WidgetCreater> 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<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");
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);
}
}

+ 2
- 0
lib/zhiying_comm.dart Parādīt failu

@@ -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';


+ 126
- 0
pubspec.lock Parādīt failu

@@ -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:


+ 1
- 0
pubspec.yaml Parādīt failu

@@ -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:


Notiek ielāde…
Atcelt
Saglabāt