forked from alibaba/flutter-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidget.dart
More file actions
144 lines (113 loc) · 2.69 KB
/
widget.dart
File metadata and controls
144 lines (113 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import 'dart:async';
import "package:flutter/material.dart";
import 'package:flutter_go/utils/sql.dart';
abstract class WidgetInterface {
int get id;
//组件英文名
String get name;
//组件中文名
String get cnName;
//组件截图
String get image;
//组件markdown 文档
String get doc;
//类目 id
int get catId;
}
class WidgetPoint implements WidgetInterface {
int id;
//组件英文名
String name;
//组件中文名
String cnName;
//组件截图
String image;
// 路由地址
String routerName;
//组件markdown 文档
String doc;
//组件 demo ,多个以 , 分割
String demo;
//类目 id
int catId;
final WidgetBuilder buildRouter;
WidgetPoint(
{this.id,
this.name,
this.cnName,
this.image,
this.doc,
this.catId,
this.routerName,
this.buildRouter});
WidgetPoint.fromJSON(Map json)
: id = json['id'],
name = json['name'],
image = json['image'],
cnName = json['cnName'],
routerName = json['routerName'],
doc = json['doc'],
catId = json['catId'],
buildRouter = json['buildRouter'];
String toString() {
return '(WidgetPoint $name)';
}
Object toMap() {
return {
'id': id,
'name': name,
'cnName': cnName,
'image': image,
'doc': doc,
'catId': catId
};
}
Map toSqlCondition() {
Map _map = this.toMap();
Map condition = {};
_map.forEach((k, value) {
if (value != null) {
condition[k] = value;
}
});
if (condition.isEmpty) {
return {};
}
return condition;
}
}
class WidgetControlModel {
final String table = 'widget';
Sql sql;
WidgetControlModel() {
sql = Sql.setTable(table);
}
// 获取Widget不同条件的列表
Future<List<WidgetPoint>> getList(WidgetPoint widgetPoint) async {
List listJson =
await sql.getByCondition(conditions: widgetPoint.toSqlCondition());
List<WidgetPoint> widgets = listJson.map((json) {
return new WidgetPoint.fromJSON(json);
}).toList();
// print("widgets $widgets");
return widgets;
}
// 通过name获取Cat对象信息
Future<WidgetPoint> getCatByName(String name) async {
List json = await sql.getByCondition(conditions: {'name': name});
if (json.isEmpty) {
return null;
}
return new WidgetPoint.fromJSON(json.first);
}
Future<List<WidgetPoint>> search(String name) async {
List json = await sql.search(conditions: {'name': name});
if (json.isEmpty) {
return [];
}
List<WidgetPoint> widgets = json.map((json) {
return new WidgetPoint.fromJSON(json);
}).toList();
return widgets;
}
}