@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart';
88import 'package:flutter/material.dart' ;
99import 'package:flutter/semantics.dart' ;
1010import 'package:flutter_test/flutter_test.dart' ;
11+
1112import '../widgets/semantics_tester.dart' ;
1213
1314void main () {
@@ -1799,6 +1800,40 @@ void main() {
17991800 },
18001801 );
18011802
1803+ testWidgets (
1804+ 'The framework removes all animation listeners from foreign controllers when disposing.' ,
1805+ (WidgetTester tester) async {
1806+ final GlobalKey <ScaffoldState > scaffoldKey = GlobalKey <ScaffoldState >();
1807+ final _StatusTestAnimationController controller = _StatusTestAnimationController (
1808+ vsync: const TestVSync (),
1809+ duration: const Duration (seconds: 2 ),
1810+ reverseDuration: const Duration (seconds: 2 ),
1811+ );
1812+ addTearDown (controller.dispose);
1813+
1814+ await tester.pumpWidget (
1815+ MaterialApp (home: Scaffold (key: scaffoldKey, body: const Center (child: Text ('body' )))),
1816+ );
1817+
1818+ await tester.pump ();
1819+ expect (controller.isListening, isFalse);
1820+
1821+ scaffoldKey.currentState! .showBottomSheet ((BuildContext context) {
1822+ return const SizedBox (height: 200.0 , child: Text ('BottomSheet' ));
1823+ }, transitionAnimationController: controller);
1824+
1825+ await tester.pumpAndSettle ();
1826+ expect (controller.isListening, isTrue);
1827+ expect (find.text ('BottomSheet' ), findsOneWidget);
1828+
1829+ // Swipe the bottom sheet to dismiss it.
1830+ await tester.drag (find.text ('BottomSheet' ), const Offset (0.0 , 150.0 ));
1831+ await tester.pumpAndSettle (); // Bottom sheet dismiss animation.
1832+ expect (controller.isListening, isFalse);
1833+ expect (find.text ('BottomSheet' ), findsNothing);
1834+ },
1835+ );
1836+
18021837 testWidgets (
18031838 'Calling PersistentBottomSheetController.close does not crash when it is not the current bottom sheet' ,
18041839 (WidgetTester tester) async {
@@ -2808,3 +2843,13 @@ class _TestPage extends StatelessWidget {
28082843 );
28092844 }
28102845}
2846+
2847+ class _StatusTestAnimationController extends AnimationController with AnimationLazyListenerMixin {
2848+ _StatusTestAnimationController ({super .duration, super .reverseDuration, required super .vsync});
2849+
2850+ @override
2851+ void didStartListening () {}
2852+
2853+ @override
2854+ void didStopListening () {}
2855+ }
0 commit comments