Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature -> Develop | Added Local Storage option #43

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions assets/env/develop.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"backend_url": "",
"api_url": "",
"firebase_id": null,
"timeout_limit": 20000,
"timeout_limit": 20,
"enable_local_logs": false,
"enable_cloud_logs": false,
"enable_api_log_interceptor": false,
Expand All @@ -17,5 +17,6 @@
"one_signal_config": null,
"pusher_config": null,
"show_debug_panel": true,
"local_storage_type": "none",
"debug_panel_color": 3422552064
}
}
5 changes: 3 additions & 2 deletions assets/env/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"backend_url": "",
"api_url": "",
"firebase_id": null,
"timeout_limit": 20000,
"timeout_limit": 20,
"enable_local_logs": false,
"enable_cloud_logs": false,
"enable_api_log_interceptor": false,
Expand All @@ -17,5 +17,6 @@
"one_signal_config": null,
"pusher_config": null,
"show_debug_panel": false,
"local_storage_type": "none",
"debug_panel_color": 3422552064
}
}
5 changes: 3 additions & 2 deletions assets/env/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"backend_url": "",
"api_url": "",
"firebase_id": null,
"timeout_limit": 20000,
"timeout_limit": 20,
"enable_local_logs": false,
"enable_cloud_logs": false,
"enable_api_log_interceptor": false,
Expand All @@ -17,5 +17,6 @@
"one_signal_config": null,
"pusher_config": null,
"show_debug_panel": true,
"local_storage_type": "none",
"debug_panel_color": 3422552064
}
}
13 changes: 13 additions & 0 deletions lib/vaahextendflutter/base/base_controller.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import 'dart:async';
import 'dart:io';

import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:hive/hive.dart';
import 'package:path_provider/path_provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart';

import '../app_theme.dart';
import '../env/env.dart';
import '../env/storage.dart';
import '../services/api.dart';
import '../services/dynamic_links.dart';
import '../services/notification/internal/notification.dart';
Expand Down Expand Up @@ -45,6 +49,15 @@ class BaseController extends GetxController {
await InternalNotifications.init();
PushNotifications.askPermission();

if (config.localStorageType == LocalStorageType.hive) {
final Directory appDocDirectory = await getApplicationDocumentsDirectory();
await Directory('${appDocDirectory.path}/vaahflutterdir')
.create(recursive: true)
.then((Directory directory) async {
Hive.init(directory.path);
});
}

Comment on lines +52 to +60
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for better readability, this code should be look like this

 if (config.localStorageType == LocalStorageType.hive) {
        final Directory docsDirectory = await getApplicationDocumentsDirectory();
        final String storagePath = '${docsDirectory.path}/vaahflutterdir';
        final Directory storageDirectory = await Directory(storagePath).create(
          recursive: true,
        );

        Hive.init(storageDirectory.path);
      }

// Sentry Initialization (And/ Or) Running main app
if (null != config.sentryConfig && config.sentryConfig!.dsn.isNotEmpty) {
await SentryFlutter.init(
Expand Down
4 changes: 4 additions & 0 deletions lib/vaahextendflutter/env/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:json_annotation/json_annotation.dart';
import '../services/logging_library/logging_library.dart';
import 'logging.dart';
import 'notification.dart';
import 'storage.dart';

part 'env.g.dart';

Expand Down Expand Up @@ -58,6 +59,7 @@ class EnvironmentConfig {
this.oneSignalConfig,
this.pusherConfig,
required this.showDebugPanel,
required this.localStorageType,
required this.debugPanelColor,
});

Expand All @@ -78,6 +80,7 @@ class EnvironmentConfig {
final OneSignalConfig? oneSignalConfig;
final PusherConfig? pusherConfig;
final bool showDebugPanel;
final LocalStorageType localStorageType;
@JsonKey(fromJson: _colorFromJson, toJson: _colorToJson)
final Color debugPanelColor;

Expand Down Expand Up @@ -119,6 +122,7 @@ class EnvironmentConfig {
pushNotificationsServiceType: PushNotificationsServiceType.none,
internalNotificationsServiceType: InternalNotificationsServiceType.none,
showDebugPanel: true,
localStorageType: LocalStorageType.none,
debugPanelColor: Colors.black.withOpacity(0.8),
);
}
Expand Down
10 changes: 10 additions & 0 deletions lib/vaahextendflutter/env/env.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/vaahextendflutter/env/storage.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
enum LocalStorageType { hive, flutterSecureStorage, none }
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import '../../storage_response.dart';

abstract class LocalStorageService {
StorageResponse add(String collectionName);

Future<StorageResponse> create({
required String collectionName,
required String key,
required String value,
});

Future<StorageResponse> createMany({
required String collectionName,
required Map<String, String> values,
});

Future<StorageResponse> read({required String collectionName, required String key});

Future<StorageResponse> readMany({
required String collectionName,
required List<String> keys,
});

Future<StorageResponse> readAll({required String collectionName});

Future<StorageResponse> update({
required String collectionName,
required String key,
required String value,
});

Future<StorageResponse> updateMany({
required String collectionName,
required Map<String, String> values,
});

Future<StorageResponse> createOrUpdate({
required String collectionName,
required String key,
required String value,
});

Future<StorageResponse> createOrUpdateMany({
required String collectionName,
required Map<String, String> values,
});

Future<StorageResponse> delete({required String collectionName, required String key});

Future<StorageResponse> deleteMany({
required String collectionName,
List<String> keys = const [],
});

Future<StorageResponse> deleteAll({required String collectionName});
}
Loading