@@ -344,5 +344,52 @@ void main() {
344
344
345
345
check (getAnimation (tester).value).equals (0 );
346
346
});
347
+
348
+ testWidgets ('animation state persistence' , (WidgetTester tester) async {
349
+ // Check that _UnreadMarker maintains its in-progress animation
350
+ // as the number of items change in MessageList.
351
+
352
+ // TODO: pull this out into group
353
+ Animation getAnimation (WidgetTester tester, int messageId) {
354
+ final widget = tester.widget <FadeTransition >(find.descendant (
355
+ of: find.byKey (ValueKey (messageId)),
356
+ matching: find.byType (FadeTransition )));
357
+ return widget.opacity;
358
+ }
359
+
360
+ final message = eg.streamMessage (id: 1 , flags: []);
361
+ await setupMessageListPage (tester, messages: [message]);
362
+
363
+ // initial state: marker is visible
364
+ check (getAnimation (tester, message.id).value).equals (1.0 );
365
+
366
+ store.handleEvent (UpdateMessageFlagsAddEvent (
367
+ id: 0 ,
368
+ flag: MessageFlag .read,
369
+ messages: [message.id],
370
+ all: false ,
371
+ ));
372
+ await tester.pump (); // process handleEvent
373
+ await tester.pump (const Duration (milliseconds: 30 )); // run animation partially
374
+
375
+ final newMessage = eg.streamMessage (id: 2 , flags: [MessageFlag .read]);
376
+ store.handleEvent (MessageEvent (id: 0 , message: newMessage));
377
+ await tester.pump (); // process handleEvent
378
+
379
+ // in-progress state: original marker is still
380
+ // animating but new marker is not
381
+ check (find.byType (MessageItem ).evaluate ()).length.equals (2 );
382
+ check (getAnimation (tester, message.id).status)
383
+ .equals (AnimationStatus .forward);
384
+ check (getAnimation (tester, newMessage.id).status)
385
+ .equals (AnimationStatus .dismissed);
386
+
387
+ // If we introduce an animation bug (remove findChildIndexCallback
388
+ // on StickyHeaderListView.builder) this returns 1.
389
+ final frames = await tester.pumpAndSettle ();
390
+ check (frames).isGreaterThan (1 );
391
+ check (getAnimation (tester, message.id).status)
392
+ .equals (AnimationStatus .completed);
393
+ });
347
394
});
348
395
}
0 commit comments