Skip to content

Commit

Permalink
feat: packages/alice_objectbox
Browse files Browse the repository at this point in the history
  • Loading branch information
techouse committed Jun 28, 2024
1 parent 338d5ca commit 536c334
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 367 deletions.
22 changes: 13 additions & 9 deletions examples/alice_objectbox/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:alice/alice.dart';
import 'package:alice_http/alice_http_adapter.dart';
import 'package:alice_http/alice_http_extensions.dart';
import 'package:alice_objectbox/alice_objectbox.dart';
import 'package:alice_objectbox/alice_store.dart';
import 'package:alice_objectbox/alice_objectbox_store.dart';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;

Expand All @@ -12,7 +12,8 @@ Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();

/// Initialize AliceStore before running the app.
final AliceStore store = await AliceStore.create(empty: true);
final AliceObjectBoxStore store =
await AliceObjectBoxStore.create(persistent: false);

runApp(MyApp(store: store));
}
Expand All @@ -23,7 +24,7 @@ class MyApp extends StatefulWidget {
required this.store,
});

final AliceStore store;
final AliceObjectBoxStore store;

@override
State<MyApp> createState() => _MyAppState();
Expand All @@ -32,12 +33,15 @@ class MyApp extends StatefulWidget {
class _MyAppState extends State<MyApp> {
late final AliceHttpAdapter _aliceHttpAdapter = AliceHttpAdapter();

late final Alice _alice = AliceObjectBox(
store: widget.store,
showNotification: true,
showInspectorOnShake: true,
maxCallsCount: 1000,
)..addAdapter(_aliceHttpAdapter);
late final Alice _alice = Alice(
showNotification: true,
showInspectorOnShake: true,
maxCallsCount: 1000,
aliceStorage: AliceObjectBox(
store: widget.store,
maxCallsCount: 1000,
))
..addAdapter(_aliceHttpAdapter);

@override
Widget build(BuildContext context) {
Expand Down
34 changes: 21 additions & 13 deletions packages/alice/lib/alice.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import 'package:alice/core/alice_adapter.dart';
import 'package:alice/core/alice_core.dart';
import 'package:alice/core/alice_memory_storage.dart';
import 'package:alice/core/alice_storage.dart';
import 'package:alice/model/alice_http_call.dart';
import 'package:alice/model/alice_log.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

export 'package:alice/core/alice_store.dart';
export 'package:alice/model/alice_log.dart';

class Alice {
Expand Down Expand Up @@ -33,6 +36,8 @@ class Alice {
GlobalKey<NavigatorState>? _navigatorKey;
late final AliceCore _aliceCore;

final AliceStorage? _aliceStorage;

/// Creates alice instance.
Alice({
GlobalKey<NavigatorState>? navigatorKey,
Expand All @@ -42,21 +47,24 @@ class Alice {
this.maxCallsCount = 1000,
this.directionality,
this.showShareButton = true,
}) : _navigatorKey = navigatorKey ?? GlobalKey<NavigatorState>() {
_aliceCore = buildAliceCore();
AliceStorage? aliceStorage,
}) : _navigatorKey = navigatorKey ?? GlobalKey<NavigatorState>(),
_aliceStorage = aliceStorage {
_aliceCore = AliceCore(
_navigatorKey,
showNotification: showNotification,
showInspectorOnShake: showInspectorOnShake,
notificationIcon: notificationIcon,
maxCallsCount: maxCallsCount,
directionality: directionality,
showShareButton: showShareButton,
aliceStorage: _aliceStorage ??
AliceMemoryStorage(
maxCallsCount: maxCallsCount,
),
);
}

@protected
AliceCore buildAliceCore() => AliceCore(
_navigatorKey,
showNotification: showNotification,
showInspectorOnShake: showInspectorOnShake,
notificationIcon: notificationIcon,
maxCallsCount: maxCallsCount,
directionality: directionality,
showShareButton: showShareButton,
);

/// Set custom navigation key. This will help if there's route library.
void setNavigatorKey(GlobalKey<NavigatorState> navigatorKey) {
_navigatorKey = navigatorKey;
Expand Down
Loading

0 comments on commit 536c334

Please sign in to comment.