Skip to content

Commit 5813238

Browse files
committed
Updated: flow of parameter passing
1 parent e8f3ed7 commit 5813238

File tree

3 files changed

+50
-41
lines changed

3 files changed

+50
-41
lines changed

lib/vaahextendflutter/services/storage/local/services/base_service.dart

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,50 @@ abstract class LocalStorageService {
44
StorageResponse add(String collectionName);
55

66
Future<StorageResponse> create({
7-
String collectionName,
7+
required String collectionName,
88
required String key,
99
required String value,
1010
});
1111

12-
Future<StorageResponse> createMany({String collectionName, required Map<String, String> values});
12+
Future<StorageResponse> createMany({
13+
required String collectionName,
14+
required Map<String, String> values,
15+
});
1316

14-
Future<StorageResponse> read({String collectionName, required String key});
17+
Future<StorageResponse> read({required String collectionName, required String key});
1518

16-
Future<StorageResponse> readMany({String collectionName, required List<String> keys});
19+
Future<StorageResponse> readMany({required String collectionName, required List<String> keys});
1720

18-
Future<StorageResponse> readAll({String collectionName});
21+
Future<StorageResponse> readAll({required String collectionName});
1922

2023
Future<StorageResponse> update({
21-
String collectionName,
24+
required String collectionName,
2225
required String key,
2326
required String value,
2427
});
2528

26-
Future<StorageResponse> updateMany({String collectionName, required Map<String, String> values});
29+
Future<StorageResponse> updateMany({
30+
required String collectionName,
31+
required Map<String, String> values,
32+
});
2733

2834
Future<StorageResponse> createOrUpdate({
29-
String collectionName,
35+
required String collectionName,
3036
required String key,
3137
required String value,
3238
});
3339

3440
Future<StorageResponse> createOrUpdateMany({
35-
String collectionName,
41+
required String collectionName,
3642
required Map<String, String> values,
3743
});
3844

39-
Future<StorageResponse> delete({String collectionName, required String key});
45+
Future<StorageResponse> delete({required String collectionName, required String key});
4046

41-
Future<StorageResponse> deleteMany({String collectionName, List<String> keys = const []});
47+
Future<StorageResponse> deleteMany({
48+
required String collectionName,
49+
List<String> keys = const [],
50+
});
4251

43-
Future<StorageResponse> deleteAll({String collectionName});
52+
Future<StorageResponse> deleteAll({required String collectionName});
4453
}

lib/vaahextendflutter/services/storage/local/services/hive.dart

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ import 'base_service.dart';
66

77
/// A class implementing LocalStorageService interface using Hive as storage backend.
88
class LocalStorageWithHive implements LocalStorageService {
9-
static const String _defaultCollectionName = 'vaah-flutter-box';
10-
119
final Map<String, Future<Box>> _collections = {
12-
_defaultCollectionName: Hive.openBox(_defaultCollectionName),
10+
'vaah-flutter-box': Hive.openBox('vaah-flutter-box'),
1311
};
1412

1513
@override
@@ -32,7 +30,7 @@ class LocalStorageWithHive implements LocalStorageService {
3230

3331
@override
3432
Future<StorageResponse> create({
35-
String collectionName = _defaultCollectionName,
33+
required String collectionName,
3634
required String key,
3735
required String value,
3836
}) async {
@@ -80,7 +78,7 @@ class LocalStorageWithHive implements LocalStorageService {
8078

8179
@override
8280
Future<StorageResponse> createMany({
83-
String collectionName = _defaultCollectionName,
81+
required String collectionName,
8482
required Map<String, String> values,
8583
}) async {
8684
int totalEntries = values.length;
@@ -111,7 +109,7 @@ class LocalStorageWithHive implements LocalStorageService {
111109

112110
@override
113111
Future<StorageResponse> read({
114-
String collectionName = _defaultCollectionName,
112+
required String collectionName,
115113
required String key,
116114
}) async {
117115
if (!_collections.containsKey(collectionName)) {
@@ -155,7 +153,7 @@ class LocalStorageWithHive implements LocalStorageService {
155153

156154
@override
157155
Future<StorageResponse> readMany({
158-
String collectionName = _defaultCollectionName,
156+
required String collectionName,
159157
required List<String> keys,
160158
}) async {
161159
if (keys.isNotEmpty) {
@@ -193,7 +191,7 @@ class LocalStorageWithHive implements LocalStorageService {
193191
}
194192

195193
@override
196-
Future<StorageResponse> readAll({String collectionName = _defaultCollectionName}) async {
194+
Future<StorageResponse> readAll({required String collectionName}) async {
197195
if (!_collections.containsKey(collectionName)) {
198196
return StorageResponse(
199197
errors: [
@@ -229,7 +227,7 @@ class LocalStorageWithHive implements LocalStorageService {
229227

230228
@override
231229
Future<StorageResponse> update({
232-
String collectionName = _defaultCollectionName,
230+
required String collectionName,
233231
required String key,
234232
required String value,
235233
}) async {
@@ -271,7 +269,7 @@ class LocalStorageWithHive implements LocalStorageService {
271269

272270
@override
273271
Future<StorageResponse> updateMany({
274-
String collectionName = _defaultCollectionName,
272+
required String collectionName,
275273
required Map<String, String> values,
276274
}) async {
277275
int remainigEntries = values.length;
@@ -299,7 +297,7 @@ class LocalStorageWithHive implements LocalStorageService {
299297

300298
@override
301299
Future<StorageResponse> createOrUpdate({
302-
String collectionName = _defaultCollectionName,
300+
required String collectionName,
303301
required String key,
304302
required String value,
305303
}) async {
@@ -323,7 +321,7 @@ class LocalStorageWithHive implements LocalStorageService {
323321

324322
@override
325323
Future<StorageResponse> createOrUpdateMany({
326-
String collectionName = _defaultCollectionName,
324+
required String collectionName,
327325
required Map<String, String> values,
328326
}) async {
329327
int remainigEntries = values.length;
@@ -354,8 +352,7 @@ class LocalStorageWithHive implements LocalStorageService {
354352
}
355353

356354
@override
357-
Future<StorageResponse> delete(
358-
{String collectionName = _defaultCollectionName, dynamic key}) async {
355+
Future<StorageResponse> delete({required String collectionName, dynamic key}) async {
359356
if (!_collections.containsKey(collectionName)) {
360357
return StorageResponse(
361358
errors: [
@@ -394,7 +391,7 @@ class LocalStorageWithHive implements LocalStorageService {
394391

395392
@override
396393
Future<StorageResponse> deleteMany({
397-
String collectionName = _defaultCollectionName,
394+
required String collectionName,
398395
List<String> keys = const [],
399396
}) async {
400397
List<StorageError> errors = [];
@@ -462,7 +459,7 @@ class LocalStorageWithHive implements LocalStorageService {
462459
}
463460

464461
@override
465-
Future<StorageResponse> deleteAll({String collectionName = _defaultCollectionName}) async {
462+
Future<StorageResponse> deleteAll({required String collectionName}) async {
466463
if (!_collections.containsKey(collectionName)) {
467464
return StorageResponse(
468465
errors: [

lib/vaahextendflutter/services/storage/local/storage.dart

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ LocalStorageService get instanceLocal {
2020

2121
abstract class LocalStorage {
2222
static final LocalStorageService _instanceLocal = instanceLocal;
23+
static const defaultCollectionName = 'vaah-flutter-box';
2324

2425
/// Adds a new collection (which is basically a Hive Box) with [collectionName] in [LocalStorage].
2526
/// In the case of [LocalStorageWithHive], it opens a box with name [collectionName] provided.
@@ -94,7 +95,7 @@ abstract class LocalStorage {
9495
///
9596
/// ```
9697
static Future<StorageResponse> create({
97-
String collectionName = 'vaah-flutter-box',
98+
String collectionName = defaultCollectionName,
9899
required String key,
99100
required String value,
100101
}) {
@@ -161,7 +162,7 @@ abstract class LocalStorage {
161162
///
162163
/// ```
163164
static Future<StorageResponse> createMany({
164-
String collectionName = 'vaah-flutter-box',
165+
String collectionName = defaultCollectionName,
165166
required Map<String, String> values,
166167
}) {
167168
return _instanceLocal.createMany(collectionName: collectionName, values: values);
@@ -196,8 +197,10 @@ abstract class LocalStorage {
196197
/// response.errors; // List<StorageError>
197198
/// }
198199
/// ```
199-
static Future<StorageResponse> read(
200-
{String collectionName = 'vaah-flutter-box', required String key}) {
200+
static Future<StorageResponse> read({
201+
String collectionName = defaultCollectionName,
202+
required String key,
203+
}) {
201204
return _instanceLocal.read(collectionName: collectionName, key: key);
202205
}
203206

@@ -240,7 +243,7 @@ abstract class LocalStorage {
240243
/// }
241244
/// ```
242245
static Future<StorageResponse> readMany({
243-
String collectionName = 'vaah-flutter-box',
246+
String collectionName = defaultCollectionName,
244247
required List<String> keys,
245248
}) {
246249
return _instanceLocal.readMany(collectionName: collectionName, keys: keys);
@@ -273,7 +276,7 @@ abstract class LocalStorage {
273276
/// }
274277
///
275278
/// ```
276-
static Future<StorageResponse> readAll({String collectionName = 'vaah-flutter-box'}) {
279+
static Future<StorageResponse> readAll({String collectionName = defaultCollectionName}) {
277280
return _instanceLocal.readAll(collectionName: collectionName);
278281
}
279282

@@ -308,7 +311,7 @@ abstract class LocalStorage {
308311
///
309312
/// ```
310313
static Future<StorageResponse> update({
311-
String collectionName = 'vaah-flutter-box',
314+
String collectionName = defaultCollectionName,
312315
required String key,
313316
required String value,
314317
}) {
@@ -362,7 +365,7 @@ abstract class LocalStorage {
362365
///
363366
/// ```
364367
static Future<StorageResponse> updateMany({
365-
String collectionName = 'vaah-flutter-box',
368+
String collectionName = defaultCollectionName,
366369
required Map<String, String> values,
367370
}) {
368371
return _instanceLocal.updateMany(collectionName: collectionName, values: values);
@@ -398,7 +401,7 @@ abstract class LocalStorage {
398401
///
399402
/// ```
400403
static Future<StorageResponse> createOrUpdate({
401-
String collectionName = 'vaah-flutter-box',
404+
String collectionName = defaultCollectionName,
402405
required String key,
403406
required String value,
404407
}) {
@@ -449,7 +452,7 @@ abstract class LocalStorage {
449452
///
450453
/// ```
451454
static Future<StorageResponse> createOrUpdateMany({
452-
String collectionName = 'vaah-flutter-box',
455+
String collectionName = defaultCollectionName,
453456
required Map<String, String> values,
454457
}) {
455458
return _instanceLocal.createOrUpdateMany(collectionName: collectionName, values: values);
@@ -482,7 +485,7 @@ abstract class LocalStorage {
482485
///
483486
/// ```
484487
static Future<StorageResponse> delete({
485-
String collectionName = 'vaah-flutter-box',
488+
String collectionName = defaultCollectionName,
486489
required String key,
487490
}) {
488491
return _instanceLocal.delete(collectionName: collectionName, key: key);
@@ -529,7 +532,7 @@ abstract class LocalStorage {
529532
///
530533
/// ```
531534
static Future<StorageResponse> deleteMany({
532-
String collectionName = 'vaah-flutter-box',
535+
String collectionName = defaultCollectionName,
533536
List<String> keys = const [],
534537
}) {
535538
return _instanceLocal.deleteMany(collectionName: collectionName, keys: keys);
@@ -568,7 +571,7 @@ abstract class LocalStorage {
568571
/// }
569572
///
570573
/// ```
571-
static Future<StorageResponse> deleteAll({String collectionName = 'vaah-flutter-box'}) {
574+
static Future<StorageResponse> deleteAll({String collectionName = defaultCollectionName}) {
572575
return _instanceLocal.deleteAll(collectionName: collectionName);
573576
}
574577
}

0 commit comments

Comments
 (0)