Skip to content

Commit e80cacb

Browse files
committed
Update docs to avoid flutter store opening confusion
1 parent ed99ffe commit e80cacb

File tree

2 files changed

+41
-37
lines changed

2 files changed

+41
-37
lines changed

example/README.md

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,41 @@
11
ObjectBox Examples
22
==========================
33

4+
Flutter
5+
--------
6+
* See a [Flutter example app](flutter/objectbox_demo) for code examples - requires Flutter 1.12
7+
8+
As opposed to a plain Dart app which runs directly on your PC, there are more restrictions where your Flutter app can
9+
write data. Therefore, you should give ObjectBox a full path to a per-app documents directory, where to store the data
10+
even when a user closes your app.
11+
12+
If you didn't specify this path to ObjectBox, it would try to use a default "objectbox" directory where the app is
13+
currently running, but it doesn't have permissions to write there: `failed to create store: 10199 Dir does not exist: objectbox (30)`.
14+
15+
To configure ObjectBox properly, you can use `getApplicationDocumentsDirectory()` from the `path_provider` package.
16+
See [Flutter: read & write files](https://flutter.dev/docs/cookbook/persistence/reading-writing-files) for more info.
17+
Have a look how it's done in the Flutter example app:
18+
```dart
19+
import 'package:path_provider/path_provider.dart';
20+
21+
class _MyHomePageState extends State<MyHomePage> {
22+
Store _store;
23+
24+
@override
25+
void initState() {
26+
super.initState();
27+
28+
getApplicationDocumentsDirectory().then((dir) {
29+
_store = Store(getObjectBoxModel(), directory: dir.path + "/objectbox");
30+
31+
// See below as well as examples/flutter/objectbox_demo for examples how to use objectbox
32+
});
33+
}
34+
}
35+
```
36+
37+
Dart native
38+
-----------
439
In the following file, e.g. `models.dart`, we import objectbox.dart to get definitions for `@Entity`,
540
`@Id` and other annotations and define a single entity that should be persisted by ObjectBox. You could have multiple
641
entities in the same file or you can have them spread across multiple files in the `lib` directory tree.
@@ -51,34 +86,3 @@ void main() {
5186
store.close();
5287
}
5388
```
54-
55-
Flutter
56-
--------
57-
* See a [Flutter example app](flutter/objectbox_demo) - requires Flutter 1.12
58-
59-
As opposed to a plain Dart app which runs directly on your PC, there are more restrictions where your Flutter app can
60-
write data. Therefore, you should give ObjectBox a full path to a per-app documents directory, where to store the data
61-
even when a user closes your app.
62-
63-
If you didn't specify this path to ObjectBox, it would try to use a default "objectbox" directory where the app is
64-
currently running, but it doesn't have permissions to write there: `failed to create store: 10199 Dir does not exist: objectbox (30)`.
65-
66-
To configure ObjectBox properly, you can use `getApplicationDocumentsDirectory()` from the `path_provider` package.
67-
See [Flutter: read & write files](https://flutter.dev/docs/cookbook/persistence/reading-writing-files) for more info.
68-
Have a look how it's done in the Flutter example app:
69-
```dart
70-
import 'package:path_provider/path_provider.dart';
71-
72-
class _MyHomePageState extends State<MyHomePage> {
73-
Store _store;
74-
75-
@override
76-
void initState() {
77-
super.initState();
78-
79-
getApplicationDocumentsDirectory().then((dir) {
80-
_store = Store(getObjectBoxModel(), directory: dir.path + "/objectbox");
81-
});
82-
}
83-
}
84-
```

lib/src/store.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ class Store {
2020
/// Creates a BoxStore using the model definition from your
2121
/// `objectbox.g.dart` file.
2222
///
23-
/// For example in a Dart app:
24-
/// ```
25-
/// var store = Store(getObjectBoxModel());
26-
/// ```
27-
///
2823
/// Or for a Flutter app:
29-
/// ```
24+
/// ```dart
3025
/// getApplicationDocumentsDirectory().then((dir) {
3126
/// _store = Store(getObjectBoxModel(), directory: dir.path + "/objectbox");
3227
/// });
3328
/// ```
3429
///
30+
/// For example in a Dart app:
31+
/// ```dart
32+
/// var store = Store(getObjectBoxModel());
33+
/// ```
34+
///
3535
/// See our examples for more details.
3636
Store(this.defs,
3737
{String directory, int maxDBSizeInKB, int fileMode, int maxReaders}) {

0 commit comments

Comments
 (0)