Skip to content

Commit f0f5728

Browse files
committed
fix(analytics): ensure events auto flush
Move timer construction to constructor as the timer is silently broken when instantiated as an instance variable.
1 parent 486bd8d commit f0f5728

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/analytics/amplify_analytics_pinpoint_dart/lib/src/impl/analytics_client/analytics_client.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ class AnalyticsClient {
3838
this._eventClient,
3939
this._eventCreator,
4040
this._endpointClient,
41-
);
41+
) {
42+
_autoEventSubmitter = StoppableTimer(
43+
duration: const Duration(seconds: 10),
44+
callback: flushEvents,
45+
);
46+
}
4247

4348
static AnalyticsClient? _instance;
4449

@@ -113,10 +118,7 @@ class AnalyticsClient {
113118
static const String _sessionStartEventType = '_session.start';
114119
static const String _sessionStopEventType = '_session.stop';
115120

116-
late final StoppableTimer _autoEventSubmitter = StoppableTimer(
117-
duration: const Duration(seconds: 10),
118-
callback: flushEvents,
119-
);
121+
late final StoppableTimer _autoEventSubmitter;
120122

121123
/// Send all cached events to AWS Pinpoint
122124
Future<void> flushEvents() async {

0 commit comments

Comments
 (0)