Skip to content

Commit 825d880

Browse files
Bungeefanmboetger
authored andcommitted
Add missing removeStatusListener for bottom sheets (flutter#167899) (flutter#167900)
Fixes the missing `removeStatusListener` in `_StandardBottomSheetState`. * Fixes: flutter#167899 I was unsure about the test regarding this change and I couldn't find any similar tests, so I improvised with a custom controller class. Feel free to request/make changes to the test as required. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 5daffb0 commit 825d880

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

‎packages/flutter/lib/src/material/scaffold.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3273,6 +3273,7 @@ class _StandardBottomSheetState extends State<_StandardBottomSheet> {
32733273

32743274
@override
32753275
void dispose() {
3276+
widget.animationController.removeStatusListener(_handleStatusChange);
32763277
widget.onDispose?.call();
32773278
super.dispose();
32783279
}

‎packages/flutter/test/material/bottom_sheet_test.dart‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:flutter/foundation.dart';
88
import 'package:flutter/material.dart';
99
import 'package:flutter/semantics.dart';
1010
import 'package:flutter_test/flutter_test.dart';
11+
1112
import '../widgets/semantics_tester.dart';
1213

1314
void 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

Comments
 (0)