Skip to content

Commit 5068f67

Browse files
committed
wip: adjust example mock project db
1 parent 7517f09 commit 5068f67

File tree

2 files changed

+133
-66
lines changed

2 files changed

+133
-66
lines changed

example/lib/main.dart

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:flutter_localizations/flutter_localizations.dart';
33
import 'package:smash_import_export_plugins/generated/l10n.dart';
44
import 'package:smash_import_export_plugins/smash_import_export_plugins.dart';
5+
import 'package:smashlibs/smashlibs.dart';
56
import 'mock_project_db.dart';
67

78
void main() {
@@ -45,6 +46,15 @@ class MyHomePage extends StatefulWidget {
4546
class _MyHomePageState extends State<MyHomePage> {
4647
var db = MockProjectDb();
4748

49+
@override
50+
void initState() {
51+
super.initState();
52+
Future(() async {
53+
await GpPreferences().initialize();
54+
setState(() {});
55+
});
56+
}
57+
4858
@override
4959
Widget build(BuildContext context) {
5060
return Scaffold(
@@ -58,27 +68,25 @@ class _MyHomePageState extends State<MyHomePage> {
5868
mainAxisAlignment: MainAxisAlignment.start,
5969
children: <Widget>[
6070
ElevatedButton(
61-
onPressed: () async {
62-
Navigator.push(
63-
context,
64-
MaterialPageRoute(
65-
builder: (context) => ImportWidget(
66-
projectDb: db,
67-
)));
68-
},
69-
child: Text('Import')
70-
),
71+
onPressed: () async {
72+
Navigator.push(
73+
context,
74+
MaterialPageRoute(
75+
builder: (context) => ImportWidget(
76+
projectDb: db,
77+
)));
78+
},
79+
child: Text('Import')),
7180
ElevatedButton(
7281
onPressed: () async {
7382
Navigator.push(
7483
context,
7584
MaterialPageRoute(
7685
builder: (context) => ExportWidget(
77-
projectDb: db,
78-
)));
86+
projectDb: db,
87+
)));
7988
},
80-
child: Text('Export')
81-
),
89+
child: Text('Export')),
8290
],
8391
),
8492
),

example/lib/mock_project_db.dart

Lines changed: 111 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,83 @@ import 'package:flutter/material.dart';
44
import 'package:smashlibs/smashlibs.dart';
55

66
class MockProjectDb implements ProjectDb {
7+
List<Note> notes = [
8+
// SimpleNote (Text)
9+
Note()
10+
..id = 1
11+
..lon = 11.33140
12+
..lat = 46.47781
13+
..altim = -1.0
14+
..timeStamp = DateTime.now().millisecondsSinceEpoch
15+
..description = "POI"
16+
..text = "note"
17+
..form = null
18+
..style = null
19+
..isDirty = 1,
20+
// FormNote (Image)
21+
Note()
22+
..id = 2
23+
..lon = 11.33140
24+
..lat = 46.47781
25+
..altim = -1.0
26+
..timeStamp = DateTime.now().millisecondsSinceEpoch
27+
..description = "POI"
28+
..text = "image note"
29+
..form =
30+
'{"sectionname":"image note","sectiondescription":"note with image","sectionicon":"image","forms":[{"formname":"image note","formitems":[{"key":"description","islabel":"true","value":"test","icon":"infoCircle","type":"string","mandatory":"no"},{"key":"images","value":"2","type":"pictures"}]},{"formname":"image from library","formitems":[{"key":"description","islabel":"true","value":"","icon":"infoCircle","type":"string","mandatory":"no"},{"key":"imagesfromlib","value":"","type":"imagelib"}]}]}'
31+
..style = null
32+
..isDirty = 1,
33+
// FormNote (Text)
34+
Note()
35+
..id = 3
36+
..lon = 11.33140
37+
..lat = 46.47781
38+
..altim = -1.0
39+
..timeStamp = DateTime.now().millisecondsSinceEpoch
40+
..description = "POI"
41+
..text = "text note"
42+
..form =
43+
'{"sectionname":"text note","sectiondescription":"a simple text note","sectionicon":"fileAlt","forms":[{"formname":"text note","formitems":[{"key":"title","value":"title","icon":"font","islabel":"true","type":"string","mandatory":"no"},{"key":"description","value":"test","icon":"infoCircle","type":"string","mandatory":"no"}]}]}'
44+
..style = null
45+
..isDirty = 1,
46+
];
47+
48+
List<DbImage> images = [
49+
// SimpleNote (Image)
50+
DbImage()
51+
..id = 1
52+
..lon = 11.33140
53+
..lat = 46.47781
54+
..altim = -1.0
55+
..azim = -1.0
56+
..imageDataId = 1
57+
..timeStamp = DateTime.now().millisecondsSinceEpoch
58+
..text = "IMG_20221201_000000"
59+
..noteId = null
60+
..isDirty = 1,
61+
// FormNote (Image)
62+
DbImage()
63+
..id = 2
64+
..lon = 11.33140
65+
..lat = 46.47781
66+
..altim = -1.0
67+
..azim = -1.0
68+
..imageDataId = 2
69+
..timeStamp = DateTime.now().millisecondsSinceEpoch
70+
..text = "IMG_20221202_000000"
71+
..noteId = 2
72+
..isDirty = 1,
73+
];
74+
75+
List<Log> logs = [
76+
Log()
77+
..id = 1
78+
..startTime = DateTime.now().millisecondsSinceEpoch - 1000
79+
..endTime = DateTime.now().millisecondsSinceEpoch
80+
..lengthm = 0
81+
..isDirty = 1
82+
..text = "log_20221202_000000"
83+
];
784

885
@override
986
String getPath() {
@@ -12,80 +89,58 @@ class MockProjectDb implements ProjectDb {
1289

1390
@override
1491
int getNotesCount(bool onlyDirty) {
15-
return 1;
92+
return notes
93+
.where((Note n) => (!onlyDirty || (onlyDirty && n.isDirty == 1)))
94+
.length;
1695
}
1796

1897
@override
1998
int getSimpleNotesCount(bool onlyDirty) {
20-
return 1;
99+
return notes
100+
.where((Note n) =>
101+
((!onlyDirty || (onlyDirty && n.isDirty == 1)) && (n.form == null)))
102+
.length;
21103
}
22104

23105
@override
24106
int getFormNotesCount(bool onlyDirty) {
25-
return 1;
107+
return notes
108+
.where((Note n) =>
109+
((!onlyDirty || (onlyDirty && n.isDirty == 1)) && (n.form != null)))
110+
.length;
26111
}
27112

28113
List<Note> getNotes({bool? doSimple, bool onlyDirty: false}) {
29-
Note note = Note()
30-
..id = 1
31-
..lon = 135
32-
..lat = 35
33-
..altim = 0
34-
..timeStamp = 0
35-
..description = "Mock note description"
36-
..text = "Mock note text"
37-
..form = "Mock note form"
38-
..style = "Mock note style"
39-
..isDirty = 1;
40-
return [note];
114+
return notes
115+
.where((Note n) => ((!onlyDirty || (onlyDirty && n.isDirty == 1)) &&
116+
(doSimple == null ||
117+
(doSimple && n.form == null) ||
118+
(!doSimple && n.form != null))))
119+
.toList();
41120
}
42121

43122
Note getNoteById(int id) {
44-
Note note = Note()
45-
..id = 1
46-
..lon = 135
47-
..lat = 35
48-
..altim = 0
49-
..timeStamp = 0
50-
..description = "Mock note description"
51-
..text = "Mock note text"
52-
..form = "Mock note form"
53-
..style = "Mock note style"
54-
..isDirty = 1;
55-
return note;
123+
return notes.firstWhere((Note n) => n.id == id);
56124
}
57125

58126
@override
59127
int getImagesCount(bool onlyDirty) {
60-
return 0;
128+
return images
129+
.where((DbImage i) => (!onlyDirty || (onlyDirty && i.isDirty == 1)))
130+
.length;
61131
}
62132

63133
@override
64134
List<DbImage> getImages({bool onlyDirty = false, bool onlySimple = true}) {
65-
DbImage image = DbImage()
66-
..id = 1
67-
..lon = 135
68-
..lat = 35
69-
..altim = 0
70-
// TODO:
71-
..timeStamp = 0
72-
..text = "Mock image text"
73-
..isDirty = 1;
74-
return [image];
135+
return images
136+
.where((DbImage i) => ((!onlyDirty || (onlyDirty && i.isDirty == 1)) &&
137+
(onlySimple != true || (onlySimple == true && i.noteId == null))))
138+
.toList();
75139
}
76140

77141
@override
78142
DbImage getImageById(int imageId) {
79-
DbImage image = DbImage()
80-
..id = 1
81-
..lon = 135
82-
..lat = 35
83-
..altim = 0
84-
// TODO:
85-
..timeStamp = 0
86-
..text = "Mock image text"
87-
..isDirty = 1;
88-
return image;
143+
return images.firstWhere((DbImage i) => i.id == imageId);
89144
}
90145

91146
@override
@@ -140,17 +195,21 @@ class MockProjectDb implements ProjectDb {
140195

141196
@override
142197
int getGpsLogCount(bool onlyDirty) {
143-
return 0;
198+
return logs
199+
.where((Log l) => (!onlyDirty || (onlyDirty && l.isDirty == 1)))
200+
.length;
144201
}
145202

146203
@override
147204
List<Log> getLogs({bool onlyDirty: false}) {
148-
return [];
205+
return logs
206+
.where((Log l) => (!onlyDirty || (onlyDirty && l.isDirty == 1)))
207+
.toList();
149208
}
150209

151210
@override
152211
Log? getLogById(int logId) {
153-
return null;
212+
return logs.firstWhere((Log l) => l.id == logId);
154213
}
155214

156215
@override
@@ -247,4 +306,4 @@ class MockProjectDb implements ProjectDb {
247306
void printInfo() {
248307
return;
249308
}
250-
}
309+
}

0 commit comments

Comments
 (0)