Skip to content

Commit

Permalink
feat: examples/alice_objectbox
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Jun 27, 2024
1 parent 091af35 commit 05599ac
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 109 deletions.
14 changes: 13 additions & 1 deletion examples/alice_objectbox/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import 'package:alice_objectbox/alice_store.dart';
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());
/// Provides access to the ObjectBox Store throughout the app.
late AliceStore aliceStore;

Future<void> main() async {
/// This is required so ObjectBox can get the application directory
/// to store the database in.
WidgetsFlutterBinding.ensureInitialized();

aliceStore = await AliceStore.create();

runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});
Expand Down
2 changes: 2 additions & 0 deletions examples/alice_objectbox/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ environment:
dependencies:
flutter:
sdk: flutter
alice:
alice_objectbox:
cupertino_icons: ^1.0.8

dev_dependencies:
Expand Down
4 changes: 4 additions & 0 deletions packages/alice_objectbox/lib/alice_store.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io' show Directory;

import 'package:alice_objectbox/model/cached_alice_http_call.dart';
import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart' as path;
Expand All @@ -20,6 +22,8 @@ class AliceStore {
"alice",
);

await Directory(storeDirectoryPath).create(recursive: true);

store ??= Store.isOpen(storeDirectoryPath)
? Store.attach(getObjectBoxModel(), storeDirectoryPath)
: await openStore(directory: storeDirectoryPath);
Expand Down
20 changes: 9 additions & 11 deletions packages/alice_objectbox/lib/model/cached_alice_http_call.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,49 +63,47 @@ class CachedAliceHttpCall implements AliceHttpCall {

@override
@Transient()
AliceHttpRequest? get request => requestRel?.target;
AliceHttpRequest? get request => requestRel.target;

@override
@Transient()
set request(AliceHttpRequest? value) {
requestRel?.target = value != null
requestRel.target = value != null
? CachedAliceHttpRequest.fromAliceHttpRequest(value)
: null;
}

@protected
final ToOne<CachedAliceHttpRequest>? requestRel =
ToOne<CachedAliceHttpRequest>();
final ToOne<CachedAliceHttpRequest> requestRel = ToOne<CachedAliceHttpRequest>();

@override
@Transient()
AliceHttpResponse? get response => responseRel?.target;
AliceHttpResponse? get response => responseRel.target;

@override
@Transient()
set response(AliceHttpResponse? value) {
responseRel?.target = value != null
responseRel.target = value != null
? CachedAliceHttpResponse.fromAliceHttpResponse(value)
: null;
}

@protected
final ToOne<CachedAliceHttpResponse>? responseRel =
ToOne<CachedAliceHttpResponse>();
final ToOne<CachedAliceHttpResponse> responseRel = ToOne<CachedAliceHttpResponse>();

@override
@Transient()
AliceHttpError? get error => errorRel?.target;
AliceHttpError? get error => errorRel.target;

@override
@Transient()
set error(AliceHttpError? value) {
errorRel?.target =
errorRel.target =
value != null ? CachedAliceHttpError.fromAliceHttpError(value) : null;
}

@protected
final ToOne<CachedAliceHttpError>? errorRel = ToOne<CachedAliceHttpError>();
final ToOne<CachedAliceHttpError> errorRel = ToOne<CachedAliceHttpError>();

@override
void setResponse(AliceHttpResponse response) {
Expand Down
94 changes: 47 additions & 47 deletions packages/alice_objectbox/lib/objectbox-model.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,220 +4,220 @@
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
"entities": [
{
"id": "1:795492642044767907",
"lastPropertyId": "14:7251587541401851452",
"id": "1:9112051699732156539",
"lastPropertyId": "14:4354662762236974529",
"name": "CachedAliceHttpCall",
"properties": [
{
"id": "1:5804378221431109317",
"id": "1:3762653877211677624",
"name": "objectId",
"type": 6,
"flags": 1
},
{
"id": "2:7272334615509979180",
"id": "2:3842302574345199884",
"name": "id",
"type": 6,
"flags": 32808,
"indexId": "1:4565593432710152261"
"indexId": "1:785825462386371646"
},
{
"id": "3:2423725452772481472",
"id": "3:2486716479761573541",
"name": "createdTime",
"type": 12
},
{
"id": "4:7431201984298066166",
"id": "4:5652467799946319465",
"name": "client",
"type": 9
},
{
"id": "5:6754942195864336650",
"id": "5:4684667944697724811",
"name": "loading",
"type": 1
},
{
"id": "6:3373208458967960734",
"id": "6:4083857791022485908",
"name": "secure",
"type": 1
},
{
"id": "7:1352990603220358436",
"id": "7:2468700886320707450",
"name": "method",
"type": 9
},
{
"id": "8:3664370209205571314",
"id": "8:1481352321860840686",
"name": "endpoint",
"type": 9
},
{
"id": "9:8183221547872287864",
"id": "9:168907952189534839",
"name": "server",
"type": 9
},
{
"id": "10:2300359236140682054",
"id": "10:2352012304390890819",
"name": "uri",
"type": 9
},
{
"id": "11:7862279959842279303",
"id": "11:5411203974018974012",
"name": "duration",
"type": 6
},
{
"id": "12:8462423596696641997",
"id": "12:6347069823169535184",
"name": "requestRelId",
"type": 11,
"flags": 520,
"indexId": "2:5052305317488294240",
"indexId": "2:1736187189570129453",
"relationTarget": "CachedAliceHttpRequest"
},
{
"id": "13:7077447070924302194",
"id": "13:2665094240670232880",
"name": "responseRelId",
"type": 11,
"flags": 520,
"indexId": "3:5239923625099331256",
"indexId": "3:736342038365124987",
"relationTarget": "CachedAliceHttpResponse"
},
{
"id": "14:7251587541401851452",
"id": "14:4354662762236974529",
"name": "errorRelId",
"type": 11,
"flags": 520,
"indexId": "4:3292746390836808516",
"indexId": "4:6876753875053649510",
"relationTarget": "CachedAliceHttpError"
}
],
"relations": []
},
{
"id": "2:2920518958531222117",
"lastPropertyId": "3:4360332889131133863",
"id": "2:1234822196006357971",
"lastPropertyId": "3:6606174208067502830",
"name": "CachedAliceHttpError",
"properties": [
{
"id": "1:3441925468177658281",
"id": "1:7595183079379424783",
"name": "objectId",
"type": 6,
"flags": 1
},
{
"id": "2:3732695790152900478",
"id": "2:2906952339862377074",
"name": "dbError",
"type": 9
},
{
"id": "3:4360332889131133863",
"id": "3:6606174208067502830",
"name": "dbStackTrace",
"type": 9
}
],
"relations": []
},
{
"id": "3:1318435393945231169",
"lastPropertyId": "10:3121674032364790532",
"id": "3:3952435099002188469",
"lastPropertyId": "10:5482956073710374459",
"name": "CachedAliceHttpRequest",
"properties": [
{
"id": "1:833323211192767425",
"id": "1:7860030543131149189",
"name": "objectId",
"type": 6,
"flags": 1
},
{
"id": "2:3527442623562936144",
"id": "2:400756712209683011",
"name": "size",
"type": 6
},
{
"id": "3:3230616071288079637",
"id": "3:1461695331578797514",
"name": "time",
"type": 12
},
{
"id": "4:4724888987680495281",
"id": "4:6367092714501419189",
"name": "contentType",
"type": 9
},
{
"id": "5:7569938724858843184",
"id": "5:6942973330930551852",
"name": "dbHeaders",
"type": 9
},
{
"id": "6:3575930149228390529",
"id": "6:5177090139150472743",
"name": "dbBody",
"type": 9
},
{
"id": "7:2572432170790316770",
"id": "7:7073566945336254377",
"name": "dbCookies",
"type": 30
},
{
"id": "8:869911787862940731",
"id": "8:7499443194345193384",
"name": "dbQueryParameters",
"type": 9
},
{
"id": "9:8059275937808545299",
"id": "9:3569666611249608973",
"name": "dbFormDataFiles",
"type": 30
},
{
"id": "10:3121674032364790532",
"id": "10:5482956073710374459",
"name": "dbFormDataFields",
"type": 30
}
],
"relations": []
},
{
"id": "4:3599726729348725275",
"lastPropertyId": "6:2934319795063615484",
"id": "4:8890972191143949164",
"lastPropertyId": "6:8264530521928833819",
"name": "CachedAliceHttpResponse",
"properties": [
{
"id": "1:6138846308730278927",
"id": "1:3995456757645260575",
"name": "objectId",
"type": 6,
"flags": 1
},
{
"id": "2:4856631098748217080",
"id": "2:3245463467272928109",
"name": "status",
"type": 6
},
{
"id": "3:4986685428550340886",
"id": "3:8483714278633944857",
"name": "size",
"type": 6
},
{
"id": "4:3047713617827854337",
"id": "4:2693845057233959128",
"name": "time",
"type": 12
},
{
"id": "5:8865594459779684325",
"id": "5:5298588582283239315",
"name": "dbBody",
"type": 9
},
{
"id": "6:2934319795063615484",
"id": "6:8264530521928833819",
"name": "dbHeaders",
"type": 9
}
],
"relations": []
}
],
"lastEntityId": "4:3599726729348725275",
"lastIndexId": "4:3292746390836808516",
"lastEntityId": "4:8890972191143949164",
"lastIndexId": "4:6876753875053649510",
"lastRelationId": "0:0",
"lastSequenceId": "0:0",
"modelVersion": 5,
Expand Down
Loading

0 comments on commit 05599ac

Please sign in to comment.