Skip to content

Commit fdde241

Browse files
authored
DraggableScrollableController should dispatch creation in constructor. (flutter#135423)
1 parent 0f5cc2c commit fdde241

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

packages/flutter/lib/src/widgets/draggable_scrollable_sheet.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ typedef ScrollableWidgetBuilder = Widget Function(
5252
/// fire when [pixels] changes without [size] changing. For example, if the
5353
/// constraints provided to an attached sheet change.
5454
class DraggableScrollableController extends ChangeNotifier {
55+
/// Creates a controller for [DraggableScrollableSheet].
56+
DraggableScrollableController() {
57+
if (kFlutterMemoryAllocationsEnabled) {
58+
ChangeNotifier.maybeDispatchObjectCreation(this);
59+
}
60+
}
61+
5562
_DraggableScrollableSheetScrollController? _attachedController;
5663
final Set<AnimationController> _animationControllers = <AnimationController>{};
5764

packages/flutter/test/material/scaffold_test.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ void main() {
273273

274274
testWidgetsWithLeakTracking('Floating action button shrinks when bottom sheet becomes dominant', (WidgetTester tester) async {
275275
final DraggableScrollableController draggableController = DraggableScrollableController();
276+
addTearDown(draggableController.dispose);
276277
const double kBottomSheetDominatesPercentage = 0.3;
277278

278279
await tester.pumpWidget(MaterialApp(home: Scaffold(
@@ -312,6 +313,7 @@ void main() {
312313

313314
testWidgetsWithLeakTracking('Scaffold shows scrim when bottom sheet becomes dominant', (WidgetTester tester) async {
314315
final DraggableScrollableController draggableController = DraggableScrollableController();
316+
addTearDown(draggableController.dispose);
315317
const double kBottomSheetDominatesPercentage = 0.3;
316318
const double kMinBottomSheetScrimOpacity = 0.1;
317319
const double kMaxBottomSheetScrimOpacity = 0.6;
@@ -2762,6 +2764,7 @@ void main() {
27622764

27632765
testWidgetsWithLeakTracking('showBottomSheet removes scrim when draggable sheet is dismissed', (WidgetTester tester) async {
27642766
final DraggableScrollableController draggableController = DraggableScrollableController();
2767+
addTearDown(draggableController.dispose);
27652768
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
27662769
PersistentBottomSheetController<void>? sheetController;
27672770

packages/flutter/test/widgets/draggable_scrollable_sheet_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,9 @@ void main() {
16811681

16821682
testWidgetsWithLeakTracking('DraggableScrollableSheet controller can be changed while animating', (WidgetTester tester) async {
16831683
final DraggableScrollableController controller1 = DraggableScrollableController();
1684+
addTearDown(controller1.dispose);
16841685
final DraggableScrollableController controller2 = DraggableScrollableController();
1686+
addTearDown(controller2.dispose);
16851687

16861688
DraggableScrollableController controller = controller1;
16871689
await tester.pumpWidget(MaterialApp(
@@ -1733,4 +1735,11 @@ void main() {
17331735
expect(controller1.isAttached, false);
17341736
expect(controller2.isAttached, false);
17351737
});
1738+
1739+
testWidgetsWithLeakTracking('$DraggableScrollableController dispatches creation in constructor.', (WidgetTester widgetTester) async {
1740+
await expectLater(
1741+
await memoryEvents(() async => DraggableScrollableController().dispose(), DraggableScrollableController),
1742+
areCreateAndDispose,
1743+
);
1744+
});
17361745
}

0 commit comments

Comments
 (0)