forked from alibaba/flutter-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollection_general.dart
69 lines (57 loc) · 1.5 KB
/
collection_general.dart
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
/**
* Created with Android Studio.
* User: 一晟
* Date: 2019/1/12
* Time: 下午9:19
* email: [email protected]
*/
import 'dart:async';
import '../common/sql.dart';
abstract class CollectionInterface {
String get key;
String get values;
}
class CollectionGeneral implements CollectionInterface {
String key;
String values;
CollectionGeneral({this.key, this.values});
factory CollectionGeneral.fromJSON(Map json){
return CollectionGeneral(key: json['name'],values: json['values']);
}
Object toMap() {
return {'key': key, 'values': values};
}
}
class CollectionControlModel {
final String table = 'collectionGeneral';
Sql sql;
CollectionControlModel() {
sql = Sql.setTable(table);
}
// 获取所有的收藏
// 插入新收藏
Future insert(CollectionGeneral collection) {
var result =
sql.insert({'key': collection.key, 'values': collection.values});
return result;
}
// 获取全部的收藏
Future<List<CollectionGeneral>> getAllCollection() async {
List list = await sql.getByCondition();
List<CollectionGeneral> resultList = [];
list.forEach((item){
print(item);
resultList.add(CollectionGeneral.fromJSON(item));
});
return resultList;
}
// 通过收藏名获取router
Future getRouterByName(String key) async {
List list = await sql.getByCondition(conditions: {'key': key});
return list;
}
// 删除
Future deleteByName(String key) async{
return await sql.delete(key,'key');
}
}