-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: develop
Are you sure you want to change the base?
Conversation
lib/vaahextendflutter/env.dart
Outdated
|
||
class HiveConfig { | ||
final String directoryName; | ||
final Future<Directory> _appDocDirectory = getApplicationDocumentsDirectory(); | ||
|
||
HiveConfig({this.directoryName = 'dir'}); | ||
|
||
Future<void> init() async { | ||
await _appDocDirectory; | ||
Directory dir = await _appDocDirectory; | ||
await Directory('${dir.path}/dir').create(recursive: true).then((Directory directory) async { | ||
Hive.init(directory.path); | ||
}); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config are supposed to hold config values only & no methods, having init method here is worst practice. please check sentry config & implementation.
@@ -43,6 +43,9 @@ class BaseController extends GetxController { | |||
await PushNotifications.init(); | |||
await InternalNotifications.init(); | |||
PushNotifications.askPermission(); | |||
if (config.hiveConfig != null) { | |||
await config.hiveConfig!.init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
configs aren't supposed to have functions like this
lib/vaahextendflutter/env.dart
Outdated
@@ -208,6 +219,8 @@ enum PushNotificationsServiceType { local, remote, both, none } | |||
|
|||
enum InternalNotificationsServiceType { pusher, firebase, custom, none } | |||
|
|||
enum LocalStorageType { hive, flutterSecureStorage, none } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add support for both as well.
lib/vaahextendflutter/env.dart
Outdated
|
||
class HiveConfig { | ||
final String directoryName; | ||
final Future<Directory> _appDocDirectory = getApplicationDocumentsDirectory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this in config, it should be in service class or something
final Future<Directory> _appDocDirectory = getApplicationDocumentsDirectory();
lib/vaahextendflutter/env.dart
Outdated
final String directoryName; | ||
final Future<Directory> _appDocDirectory = getApplicationDocumentsDirectory(); | ||
|
||
HiveConfig({this.directoryName = 'dir'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default value not looking good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, is this ever used
hive.init(); | ||
return hive; | ||
case LocalStorageType.flutterSecureStorage: | ||
return FlutterSecureStorageImpl(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
call init on this too, all classes which implements base class should have init (even if it is empty methos)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refer #43 (comment)
///The argument [name] is used to open Hive box with that name. | ||
/// | ||
///If you don't provide [name], 'default' will be used. | ||
factory Storage.createLocal({String name = 'default'}) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove factory constructor & use init.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check
vaahflutter/lib/vaahextendflutter/services/notification/internal/notification.dart
Line 35 in ff155ef
static Future<void> init() async { |
/// | ||
///The argument [name] is used to open Hive box with that name. | ||
/// | ||
///If you don't provide [name], 'default' will be used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format comments properly
/// example: | ||
///```dart | ||
/// Storage.createLocal('name') | ||
/// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format comments properly
///If the key is already present in the [Storage] it's vlaue will be overwritten. | ||
///```dart | ||
///await storage.create(key: 'key', value: 'value'); | ||
/// ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format comments properly
979592f
to
f80f573
Compare
3e72079
to
2299443
Compare
5683b8a
to
dce850a
Compare
b958cd0
to
b05e28b
Compare
5813238
to
196c193
Compare
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); | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
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);
}
class LocalStorageExtendable { | ||
static const String defaultCollectionName = 'vaah-fluter-box'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to create extra class, you still can access your custom function and other crud functions by doing this
class CustomStorageService extends LocalStorageWithHive {
Future<StorageResponse> customFunction(String collectionName, String key) async {
return read(collectionName: collectionName, key: key);
}
}
void main() {
CustomStorageService custom = CustomStorageService();
custom.deleteAll(collectionName: '');
custom.customFunction('collection_name', 'key');
}
9ea92f5
to
39a01da
Compare
6067ec6
to
62997d1
Compare
Handing this over to @we-kislay-k001 from @we-mohd-i001 |
Task #9596 - Flutter > VaahFlutter > Research > Add Local Storage (Hive)
Task #9615 - Flutter > VaahFlutter > Research > Add Local Storage (FLutter Secure Storage)
Task #9751 - Flutter > VaahFlutter > Local Storage > Improvement
Time invested: 96:45 | Billable: 96:45 | Non-Billable: 00:00
Problem Statement
Describe The Fix/ Solution You Implemented
Proof of your testing (Demo link or video links or image links)
Using Hive
Using Flutter Secure Storage
Dependencies
Updated:
Added:
Merge Request Checklist
industry standards
warnings/ errors
fordart analyzer
tests
pass locally with my changes (No tests are there as of now)properly formatted
feature
on the latestdevelop
flutter run
after the rebasecomments
¬es
inwireframe
and verified that I did take care of thatUI
must match withdesign
&wireframe
if availableversion/ build
(x.x.x+xxx
)develop
exists in yourfeature
branch after rebase.