File tree Expand file tree Collapse file tree 6 files changed +41
-5
lines changed Expand file tree Collapse file tree 6 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,10 @@ Analytics createClient(Configuration configuration) {
19
19
configuration = setFlushPolicies (configuration, defaultFlushPolicies);
20
20
}
21
21
22
- final analytics = Analytics (configuration, storeFactory ());
22
+ final analytics = Analytics (
23
+ configuration,
24
+ storeFactory (storageJson: configuration.storageJson ?? true ),
25
+ );
23
26
24
27
if (configuration.debug) {
25
28
analytics.addPlugin (EventLogger ());
Original file line number Diff line number Diff line change @@ -9,8 +9,11 @@ import 'package:segment_analytics/utils/store/store.dart';
9
9
import 'package:path_provider/path_provider.dart' ;
10
10
11
11
class StoreImpl with Store {
12
+ final bool storageJson;
13
+ StoreImpl ({this .storageJson = true });
12
14
@override
13
15
Future <Map <String , dynamic >?> getPersisted (String key) {
16
+ if (! storageJson) return Future .value (null );
14
17
return _readFile (key);
15
18
}
16
19
@@ -19,8 +22,18 @@ class StoreImpl with Store {
19
22
20
23
@override
21
24
Future setPersisted (String key, Map <String , dynamic > value) {
25
+ if (! storageJson) return Future .value ();
22
26
return _writeFile (key, value);
23
27
}
28
+
29
+ @override
30
+ Future deletePersisted (String key) async {
31
+ if (! storageJson) return ;
32
+ final file = File (await _fileName (key));
33
+ if (await file.exists ()) {
34
+ await file.delete ();
35
+ }
36
+ }
24
37
25
38
Future _writeFile (String fileKey, Map <String , dynamic > data) async {
26
39
RandomAccessFile file =
Original file line number Diff line number Diff line change @@ -4,12 +4,14 @@ mixin Store {
4
4
Future <Map <String , dynamic >?> getPersisted (String key);
5
5
6
6
Future setPersisted (String key, Map <String , dynamic > value);
7
+
8
+ Future deletePersisted (String key);
7
9
8
10
Future get ready;
9
11
10
12
void dispose ();
11
13
}
12
14
13
- StoreImpl storeFactory () {
14
- return StoreImpl ();
15
+ StoreImpl storeFactory ({ bool storageJson = true } ) {
16
+ return StoreImpl (storageJson : storageJson );
15
17
}
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import 'package:segment_analytics/errors.dart';
4
4
import 'store.dart' ;
5
5
6
6
class StoreImpl with Store {
7
+ final bool storageJson;
8
+ StoreImpl ({this .storageJson = true });
7
9
@override
8
10
Future <Map <String , dynamic >?> getPersisted (String key) {
9
11
throw PlatformNotSupportedError ();
@@ -16,9 +18,14 @@ class StoreImpl with Store {
16
18
Future setPersisted (String key, Map <String , dynamic > value) {
17
19
throw PlatformNotSupportedError ();
18
20
}
21
+
22
+ @override
23
+ Future deletePersisted (String key) {
24
+ throw PlatformNotSupportedError ();
25
+ }
19
26
20
27
@override
21
28
void dispose () {
22
29
throw PlatformNotSupportedError ();
23
30
}
24
- }
31
+ }
Original file line number Diff line number Diff line change @@ -5,10 +5,13 @@ import 'package:segment_analytics/utils/store/store.dart';
5
5
import 'package:web/web.dart' as web;
6
6
7
7
class StoreImpl implements Store {
8
+ final bool storageJson;
9
+ StoreImpl ({this .storageJson = true });
8
10
web.Storage get localStorage => web.window.localStorage;
9
11
10
12
@override
11
13
Future <Map <String , dynamic >?> getPersisted (String key) {
14
+ if (! storageJson) return Future .value (null );
12
15
return _readFromStorage (key);
13
16
}
14
17
@@ -17,9 +20,17 @@ class StoreImpl implements Store {
17
20
18
21
@override
19
22
Future setPersisted (String key, Map <String , dynamic > value) {
23
+ if (! storageJson) return Future .value ();
20
24
_writeToStorage (key, value);
21
25
return Future .value ();
22
26
}
27
+
28
+ @override
29
+ Future deletePersisted (String key) {
30
+ if (! storageJson) return Future .value ();
31
+ localStorage.removeItem (_getFileName (key));
32
+ return Future .value ();
33
+ }
23
34
24
35
String _getFileName (String fileKey) {
25
36
return "analytics-flutter-$fileKey .json" ;
Original file line number Diff line number Diff line change 1
1
name : segment_analytics
2
2
description : The hassle-free way to add Segment analytics to your Flutter app.
3
- version : 1.1.8
3
+ version : 1.1.9
4
4
homepage : https://github.com/segmentio/analytics_flutter#readme
5
5
repository : https://github.com/segmentio/analytics_flutter/tree/main/packages/core#readme
6
6
issue_tracker : https://github.com/segmentio/analytics_flutter/issues
You can’t perform that action at this time.
0 commit comments