@@ -37,18 +37,45 @@ Finally, you will create a `Box<Note>` which gives you a typed interface for sto
37
37
import 'objectbox.g.dart'; // this file will be generated by ObjectBox after running `pub run build_runner build`
38
38
39
39
void main() {
40
- var store = Store(getObjectBoxModel()); // Note: getObjectBoxModel() is generated for you in objectbox.g.dart
41
- var box = Box<Note>(store);
42
-
43
- var note = Note(text: "Hello");
44
- note.id = box.put(note);
45
- print("new note got id ${note.id}");
46
- print("refetched note: ${box.get(note.id)}");
47
-
48
- store.close();
40
+ var store = Store(getObjectBoxModel()); // Note: getObjectBoxModel() is generated for you in objectbox.g.dart
41
+ var box = Box<Note>(store);
42
+
43
+ var note = Note(text: "Hello");
44
+ note.id = box.put(note);
45
+ print("new note got id ${note.id}");
46
+ print("refetched note: ${box.get(note.id)}");
47
+
48
+ store.close();
49
49
}
50
50
```
51
51
52
- See also
52
+ Flutter
53
53
--------
54
- * sample [ Flutter android app] ( flutter/objectbox_demo ) - requires Flutter 1.12
54
+ * See a [ Flutter example app] ( flutter/objectbox_demo ) - requires Flutter 1.12
55
+
56
+ As opposed to a plain Dart app which runs directly on your PC, there are more restrictions where your Flutter app can
57
+ write data. Therefore, you should give ObjectBox a full path to a per-app documents directory, where to store the data
58
+ even when a user closes your app.
59
+
60
+ If you didn't specify this path to ObjectBox, it would try to use a default "objectbox" directory where the app is
61
+ currently running, but it doesn't have permissions to write there: ` failed to create store: 10199 Dir does not exist: objectbox (30) ` .
62
+
63
+ To configure ObjectBox properly, you can use ` getApplicationDocumentsDirectory() ` from the ` path_provider ` package.
64
+ See [ Flutter: read & write files] ( https://flutter.dev/docs/cookbook/persistence/reading-writing-files ) for more info.
65
+ Have a look how it's done in the Flutter example app:
66
+ ``` dart
67
+ import 'package:path_provider/path_provider.dart';
68
+
69
+ class _MyHomePageState extends State<MyHomePage> {
70
+ Store _store;
71
+
72
+ @override
73
+ void initState() {
74
+ super.initState();
75
+
76
+ getApplicationDocumentsDirectory().then((dir) {
77
+ _store = Store(getObjectBoxModel(), directory: dir.path + "/objectbox");
78
+ });
79
+ }
80
+ }
81
+ ```
0 commit comments