parent
8295d36ace
commit
e70129c6ba
@ -0,0 +1,23 @@
|
||||
import 'package:objectbox/objectbox.dart';
|
||||
|
||||
@Entity()
|
||||
class User {
|
||||
int id = 0;
|
||||
String username;
|
||||
String email;
|
||||
String token;
|
||||
|
||||
User(this.id, this.username, this.email, this.token);
|
||||
}
|
||||
|
||||
@Entity()
|
||||
class Activity {
|
||||
int id;
|
||||
@Index()
|
||||
String uuid;
|
||||
String filename;
|
||||
String category;
|
||||
DateTime date;
|
||||
|
||||
Activity(this.id, this.uuid, this.filename, this.category, this.date);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
import 'package:smartfit_app_mobile/objectbox.g.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:smartfit_app_mobile/modele/local_db/model.dart';
|
||||
|
||||
class ObjectBox {
|
||||
late final Store store;
|
||||
late final Box userBox;
|
||||
late final Box activityBox;
|
||||
|
||||
ObjectBox._create(this.store);
|
||||
|
||||
static Future<ObjectBox> create() async {
|
||||
final docsDir = await getApplicationDocumentsDirectory();
|
||||
// Future<Store> openStore() {...} is defined in the generated objectbox.g.dart
|
||||
final store =
|
||||
await openStore(directory: p.join(docsDir.path, "obx-example"));
|
||||
return ObjectBox._create(store);
|
||||
}
|
||||
|
||||
init() {
|
||||
userBox = store.box<User>();
|
||||
activityBox = store.box<Activity>();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue