Files
flutter-go/lib/model/widget.dart
ryan d48942b55d refactor(many files): 页面部分的文件结构调整
1.views 文件夹里面分类,页面相关文件;2.公共组件全部放在components里;3.创建resources文件夹放置资源dart文件4.修改二级菜单文字大小

BREAKING CHANGE: 重构,建议删除本地db,再编译
2019-01-28 17:45:18 +08:00

143 lines
2.7 KiB
Dart

import 'dart:async';
import 'package:flutter_go/utils/sql.dart';
import "package:flutter/material.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;
}
}