@@ -1090,6 +1090,8 @@ class TugboatReplayController extends ChangeNotifier {
10901090 bool _skipCapture = false ;
10911091 bool _captureLifecycleActive = true ;
10921092 int _captureLifecycleEpoch = 0 ;
1093+ AppLifecycleState ? _lastLifecycleState;
1094+ String ? _lastLifecycleEventType;
10931095 int _routeEpoch = 0 ;
10941096 final Map <String , _RouteCaptureWork > _activeRouteCaptures =
10951097 < String , _RouteCaptureWork > {};
@@ -1655,6 +1657,8 @@ class TugboatReplayController extends ChangeNotifier {
16551657 _clearReleasedInteractions (reason: InteractionRejectionReason .sessionEnd);
16561658 _captureLifecycleActive = true ;
16571659 _captureLifecycleEpoch++ ;
1660+ _lastLifecycleState = null ;
1661+ _lastLifecycleEventType = null ;
16581662 _endSessionFuture = null ;
16591663 _clock
16601664 ..reset ()
@@ -5151,6 +5155,17 @@ class TugboatReplayController extends ChangeNotifier {
51515155 }
51525156
51535157 void recordAppLifecycleState (AppLifecycleState state) {
5158+ final eventType = _appLifecycleEventType (state);
5159+ // Flutter emits hidden + paused back-to-back on every background
5160+ // transition (inactive -> hidden -> paused). Both map to
5161+ // app_backgrounded, so without dedup each background produces two
5162+ // identical events at the same atMs (see pmkit.raw_events). Drop exact
5163+ // repeats and consecutive same-type events; a new event is only emitted
5164+ // on an effective transition (e.g. backgrounded -> foregrounded ->
5165+ // backgrounded still emits twice, correctly).
5166+ final isDuplicate =
5167+ state == _lastLifecycleState ||
5168+ eventType == _lastLifecycleEventType;
51545169 switch (state) {
51555170 case AppLifecycleState .paused:
51565171 case AppLifecycleState .hidden:
@@ -5186,11 +5201,17 @@ class TugboatReplayController extends ChangeNotifier {
51865201 case AppLifecycleState .inactive:
51875202 break ;
51885203 }
5204+ _lastLifecycleState = state;
5205+ if (isDuplicate) {
5206+ _lastLifecycleEventType = eventType;
5207+ return ;
5208+ }
5209+ _lastLifecycleEventType = eventType;
51895210 _addEvent (
51905211 TugboatEvent (
51915212 id: _nextId ('event' ),
51925213 atMs: atMs,
5193- type: _appLifecycleEventType (state) ,
5214+ type: eventType ,
51945215 data: {'state' : state.name},
51955216 ),
51965217 );
0 commit comments