Skip to content

Commit 62997d1

Browse files
Added : Local Storage
1 parent 94c5501 commit 62997d1

16 files changed

+1967
-39
lines changed

assets/env/develop.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"backend_url": "",
88
"api_url": "",
99
"firebase_id": null,
10-
"timeout_limit": 20000,
10+
"timeout_limit": 20,
1111
"enable_local_logs": false,
1212
"enable_cloud_logs": false,
1313
"enable_api_log_interceptor": false,
@@ -17,5 +17,6 @@
1717
"one_signal_config": null,
1818
"pusher_config": null,
1919
"show_debug_panel": true,
20+
"local_storage_type": "none",
2021
"debug_panel_color": 3422552064
21-
}
22+
}

assets/env/production.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"backend_url": "",
88
"api_url": "",
99
"firebase_id": null,
10-
"timeout_limit": 20000,
10+
"timeout_limit": 20,
1111
"enable_local_logs": false,
1212
"enable_cloud_logs": false,
1313
"enable_api_log_interceptor": false,
@@ -17,5 +17,6 @@
1717
"one_signal_config": null,
1818
"pusher_config": null,
1919
"show_debug_panel": false,
20+
"local_storage_type": "none",
2021
"debug_panel_color": 3422552064
21-
}
22+
}

assets/env/staging.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"backend_url": "",
88
"api_url": "",
99
"firebase_id": null,
10-
"timeout_limit": 20000,
10+
"timeout_limit": 20,
1111
"enable_local_logs": false,
1212
"enable_cloud_logs": false,
1313
"enable_api_log_interceptor": false,
@@ -17,5 +17,6 @@
1717
"one_signal_config": null,
1818
"pusher_config": null,
1919
"show_debug_panel": true,
20+
"local_storage_type": "none",
2021
"debug_panel_color": 3422552064
21-
}
22+
}

lib/vaahextendflutter/base/base_controller.dart

+13
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import 'dart:async';
2+
import 'dart:io';
23

34
import 'package:firebase_core/firebase_core.dart';
45
import 'package:flutter/material.dart';
56
import 'package:get/get.dart';
67
import 'package:get_storage/get_storage.dart';
8+
import 'package:hive/hive.dart';
9+
import 'package:path_provider/path_provider.dart';
710
import 'package:sentry_flutter/sentry_flutter.dart';
811

912
import '../app_theme.dart';
1013
import '../env/env.dart';
14+
import '../env/storage.dart';
1115
import '../services/api.dart';
1216
import '../services/dynamic_links.dart';
1317
import '../services/notification/internal/notification.dart';
@@ -45,6 +49,15 @@ class BaseController extends GetxController {
4549
await InternalNotifications.init();
4650
PushNotifications.askPermission();
4751

52+
if (config.localStorageType == LocalStorageType.hive) {
53+
final Directory appDocDirectory = await getApplicationDocumentsDirectory();
54+
await Directory('${appDocDirectory.path}/vaahflutterdir')
55+
.create(recursive: true)
56+
.then((Directory directory) async {
57+
Hive.init(directory.path);
58+
});
59+
}
60+
4861
// Sentry Initialization (And/ Or) Running main app
4962
if (null != config.sentryConfig && config.sentryConfig!.dsn.isNotEmpty) {
5063
await SentryFlutter.init(

lib/vaahextendflutter/env/env.dart

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:json_annotation/json_annotation.dart';
99
import '../services/logging_library/logging_library.dart';
1010
import 'logging.dart';
1111
import 'notification.dart';
12+
import 'storage.dart';
1213

1314
part 'env.g.dart';
1415

@@ -58,6 +59,7 @@ class EnvironmentConfig {
5859
this.oneSignalConfig,
5960
this.pusherConfig,
6061
required this.showDebugPanel,
62+
required this.localStorageType,
6163
required this.debugPanelColor,
6264
});
6365

@@ -78,6 +80,7 @@ class EnvironmentConfig {
7880
final OneSignalConfig? oneSignalConfig;
7981
final PusherConfig? pusherConfig;
8082
final bool showDebugPanel;
83+
final LocalStorageType localStorageType;
8184
@JsonKey(fromJson: _colorFromJson, toJson: _colorToJson)
8285
final Color debugPanelColor;
8386

@@ -119,6 +122,7 @@ class EnvironmentConfig {
119122
pushNotificationsServiceType: PushNotificationsServiceType.none,
120123
internalNotificationsServiceType: InternalNotificationsServiceType.none,
121124
showDebugPanel: true,
125+
localStorageType: LocalStorageType.none,
122126
debugPanelColor: Colors.black.withOpacity(0.8),
123127
);
124128
}

lib/vaahextendflutter/env/env.g.dart

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
enum LocalStorageType { hive, flutterSecureStorage, none }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import '../../storage_response.dart';
2+
3+
abstract class LocalStorageService {
4+
StorageResponse add(String collectionName);
5+
6+
Future<StorageResponse> create({
7+
required String collectionName,
8+
required String key,
9+
required String value,
10+
});
11+
12+
Future<StorageResponse> createMany({
13+
required String collectionName,
14+
required Map<String, String> values,
15+
});
16+
17+
Future<StorageResponse> read({required String collectionName, required String key});
18+
19+
Future<StorageResponse> readMany({
20+
required String collectionName,
21+
required List<String> keys,
22+
});
23+
24+
Future<StorageResponse> readAll({required String collectionName});
25+
26+
Future<StorageResponse> update({
27+
required String collectionName,
28+
required String key,
29+
required String value,
30+
});
31+
32+
Future<StorageResponse> updateMany({
33+
required String collectionName,
34+
required Map<String, String> values,
35+
});
36+
37+
Future<StorageResponse> createOrUpdate({
38+
required String collectionName,
39+
required String key,
40+
required String value,
41+
});
42+
43+
Future<StorageResponse> createOrUpdateMany({
44+
required String collectionName,
45+
required Map<String, String> values,
46+
});
47+
48+
Future<StorageResponse> delete({required String collectionName, required String key});
49+
50+
Future<StorageResponse> deleteMany({
51+
required String collectionName,
52+
List<String> keys = const [],
53+
});
54+
55+
Future<StorageResponse> deleteAll({required String collectionName});
56+
}

0 commit comments

Comments
 (0)