@@ -14,7 +14,7 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
1414 return StorageResponse (errors: [
1515 StorageError (
1616 message: 'FlutterSecureStorage does not support multiple collections.' ,
17- failedKey: '' ,
17+ failedKey: name ,
1818 stackTrace: StackTrace .current,
1919 ),
2020 ]);
@@ -26,7 +26,8 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
2626 required String key,
2727 required String value,
2828 }) async {
29- if (await _storage.containsKey (key: key)) {
29+ final bool hasKey = await _storage.containsKey (key: key);
30+ if (hasKey) {
3031 return StorageResponse (
3132 errors: [
3233 StorageError (
@@ -39,7 +40,10 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
3940 }
4041 try {
4142 await _storage.write (key: key, value: value);
42- return StorageResponse (data: value, message: 'Entry created with key: "$key "' );
43+ return StorageResponse (
44+ data: value,
45+ message: 'Entry created with key: "$key "' ,
46+ );
4347 } catch (e) {
4448 return StorageResponse (
4549 errors: [
@@ -62,17 +66,23 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
6266 List <StorageError > errors = [];
6367 List <String > success = [];
6468
65- for (String k in values.keys) {
66- final result = await create (collectionName: collectionName, key: k, value: values[k]! );
69+ for (final String key in values.keys) {
70+ final result = await create (
71+ collectionName: collectionName,
72+ key: key,
73+ value: values[key]! ,
74+ );
6775 if (result.hasData) {
6876 remainingEntries-- ;
6977 success.add (result.data);
70- } else if (result.hasError) {
71- errors.add (result.errors! .first);
7278 }
79+ errors.add (result.errors! .first);
7380 }
7481 if (errors.isEmpty) {
75- return StorageResponse (data: success, message: 'All entries created successfully.' );
82+ return StorageResponse (
83+ data: success,
84+ message: 'All entries created successfully.' ,
85+ );
7686 } else if (remainingEntries == values.length) {
7787 return StorageResponse (errors: errors);
7888 }
@@ -85,7 +95,8 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
8595
8696 @override
8797 Future <StorageResponse > read ({String collectionName = '' , required String key}) async {
88- if (! (await _storage.containsKey (key: key))) {
98+ final bool hasKey = await _storage.containsKey (key: key);
99+ if (! hasKey) {
89100 return StorageResponse (
90101 errors: [
91102 StorageError (
@@ -98,7 +109,10 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
98109 }
99110 try {
100111 String ? result = await _storage.read (key: key);
101- return StorageResponse (data: result, message: 'Read successful: Entry with key: "$key ".' );
112+ return StorageResponse (
113+ data: result,
114+ message: 'Read successful: Entry with key: "$key ".' ,
115+ );
102116 } catch (e) {
103117 return StorageResponse (
104118 errors: [
@@ -121,14 +135,16 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
121135 int remainingKeys = keys.length;
122136 List <StorageError > errors = [];
123137 Map <String , String ?> data = {};
124- for (String k in keys) {
125- final result = await read (collectionName: collectionName, key: k);
138+ for (final String key in keys) {
139+ final StorageResponse result = await read (
140+ collectionName: collectionName,
141+ key: key,
142+ );
126143 if (result.hasData) {
127- data[k ] = result.data;
144+ data[key ] = result.data;
128145 remainingKeys-- ;
129- } else if (result.hasError) {
130- errors.add (result.errors! .first);
131146 }
147+ errors.add (result.errors! .first);
132148 }
133149 if (errors.isEmpty) {
134150 return StorageResponse (data: data, message: 'Read successful.' );
@@ -145,7 +161,6 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
145161 errors: [
146162 StorageError (
147163 message: 'No keys provided' ,
148- failedKey: '' ,
149164 stackTrace: StackTrace .current,
150165 ),
151166 ],
@@ -158,7 +173,7 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
158173 final Map <String , String > result = await _storage.readAll ();
159174 return StorageResponse (data: result, message: 'Read successful.' );
160175 } catch (e) {
161- StorageError error = StorageError (
176+ final StorageError error = StorageError (
162177 message: 'Failed to read entries: $e ' ,
163178 failedKey: '' ,
164179 stackTrace: StackTrace .current,
@@ -173,7 +188,8 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
173188 required String key,
174189 required String value,
175190 }) async {
176- if (! (await _storage.containsKey (key: key))) {
191+ final bool hasKey = await _storage.containsKey (key: key);
192+ if (! hasKey) {
177193 return StorageResponse (
178194 errors: [
179195 StorageError (
@@ -186,7 +202,10 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
186202 }
187203 try {
188204 await _storage.write (key: key, value: value);
189- return StorageResponse (data: value, message: 'Entry updated at key: $key ' );
205+ return StorageResponse (
206+ data: value,
207+ message: 'Entry updated at key: $key ' ,
208+ );
190209 } catch (e) {
191210 final error = StorageError (
192211 failedKey: key,
@@ -205,17 +224,23 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
205224 int remainigEntries = values.length;
206225 List <StorageError > errors = [];
207226 List <String > success = [];
208- for (String k in values.keys) {
209- final result = await update (collectionName: collectionName, key: k, value: values[k]! );
227+ for (final String key in values.keys) {
228+ final StorageResponse result = await update (
229+ collectionName: collectionName,
230+ key: key,
231+ value: values[key]! ,
232+ );
210233 if (result.hasData) {
211234 remainigEntries-- ;
212235 success.add (result.data);
213- } else if (result.hasError) {
214- errors.add (result.errors! .first);
215236 }
237+ errors.add (result.errors! .first);
216238 }
217239 if (errors.isEmpty) {
218- return StorageResponse (data: success, message: 'Updated all given entries.' );
240+ return StorageResponse (
241+ data: success,
242+ message: 'Updated all given entries.' ,
243+ );
219244 } else if (remainigEntries == values.length) {
220245 return StorageResponse (errors: errors);
221246 }
@@ -232,7 +257,8 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
232257 required String key,
233258 required String value,
234259 }) async {
235- if (! (await _storage.containsKey (key: key))) {
260+ final bool hasKey = await _storage.containsKey (key: key);
261+ if (! hasKey) {
236262 return create (key: key, value: value);
237263 }
238264 return update (key: key, value: value);
@@ -246,11 +272,11 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
246272 int remainigEntries = values.length;
247273 List <StorageError > errors = [];
248274 List <String > success = [];
249- for (String k in values.keys) {
250- final result = await createOrUpdate (
275+ for (final String key in values.keys) {
276+ final StorageResponse result = await createOrUpdate (
251277 collectionName: collectionName,
252- key: k ,
253- value: values[k ]! ,
278+ key: key ,
279+ value: values[key ]! ,
254280 );
255281 if (result.hasData) {
256282 remainigEntries-- ;
@@ -272,7 +298,8 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
272298
273299 @override
274300 Future <StorageResponse > delete ({String collectionName = '' , required String key}) async {
275- if (! (await _storage.containsKey (key: key))) {
301+ final bool hasKey = await _storage.containsKey (key: key);
302+ if (! hasKey) {
276303 return StorageResponse (
277304 errors: [
278305 StorageError (
@@ -285,7 +312,10 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
285312 }
286313 try {
287314 await _storage.delete (key: key);
288- return StorageResponse (message: 'Deleted value at key: $key ' , isSuccess: true );
315+ return StorageResponse (
316+ message: 'Deleted value at key: $key ' ,
317+ isSuccess: true ,
318+ );
289319 } catch (e) {
290320 final error = StorageError (
291321 failedKey: key,
@@ -304,8 +334,11 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
304334 if (keys.isNotEmpty) {
305335 int remainingKeys = keys.length;
306336 List <StorageError > errors = [];
307- for (String k in keys) {
308- final result = await delete (collectionName: collectionName, key: k);
337+ for (final String key in keys) {
338+ final StorageResponse result = await delete (
339+ collectionName: collectionName,
340+ key: key,
341+ );
309342 if (result.hasData) {
310343 remainingKeys-- ;
311344 }
@@ -340,7 +373,10 @@ class LocalStorageWithFlutterSecureStorage implements LocalStorageService {
340373 Future <StorageResponse > deleteAll ({String collectionName = '' }) async {
341374 try {
342375 await _storage.deleteAll ();
343- return const StorageResponse (message: 'Deleted all entries.' , isSuccess: true );
376+ return const StorageResponse (
377+ message: 'Deleted all entries.' ,
378+ isSuccess: true ,
379+ );
344380 } catch (e) {
345381 return StorageResponse (errors: [
346382 StorageError (
0 commit comments