@@ -577,6 +577,38 @@ void main() {
577577 expect (values2, contains (testUser1));
578578 expect (values2, contains (updated));
579579 });
580+
581+ test ('stream() creates new holder after previous holder is closed' , () async {
582+ await userContainer.add (testUser1);
583+
584+ // Create first stream (creates first holder internally)
585+ final stream1 = userContainer.stream (testUser1.id);
586+ final values1 = < User ? > [];
587+ final sub1 = stream1.listen (values1.add);
588+ await Future .delayed (Duration (milliseconds: 50 ));
589+ await sub1.cancel ();
590+
591+ // Get and dispose the holder created by stream
592+ final holder1 = userContainer.itemHolder (testUser1.id);
593+ holder1.dispose ();
594+
595+ // Create second stream (should clean up closed holder and create new one)
596+ final stream2 = userContainer.stream (testUser1.id);
597+ final values2 = < User ? > [];
598+ final sub2 = stream2.listen (values2.add);
599+ await Future .delayed (Duration (milliseconds: 50 ));
600+
601+ // Update the value to verify the new stream is working
602+ final updated = User (testUser1.id, 'Updated' , testUser1.email, 31 );
603+ await userContainer.update (updated);
604+ await Future .delayed (Duration (milliseconds: 50 ));
605+
606+ await sub2.cancel ();
607+
608+ // Verify the second stream received both initial and updated values
609+ expect (values2, contains (testUser1));
610+ expect (values2, contains (updated));
611+ });
580612 });
581613
582614 group ('streamAll' , () {
0 commit comments