Unverified Commit fdde2419 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

DraggableScrollableController should dispatch creation in constructor. (#135423)

parent 0f5cc2c0
...@@ -52,6 +52,13 @@ typedef ScrollableWidgetBuilder = Widget Function( ...@@ -52,6 +52,13 @@ typedef ScrollableWidgetBuilder = Widget Function(
/// fire when [pixels] changes without [size] changing. For example, if the /// fire when [pixels] changes without [size] changing. For example, if the
/// constraints provided to an attached sheet change. /// constraints provided to an attached sheet change.
class DraggableScrollableController extends ChangeNotifier { class DraggableScrollableController extends ChangeNotifier {
/// Creates a controller for [DraggableScrollableSheet].
DraggableScrollableController() {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}
_DraggableScrollableSheetScrollController? _attachedController; _DraggableScrollableSheetScrollController? _attachedController;
final Set<AnimationController> _animationControllers = <AnimationController>{}; final Set<AnimationController> _animationControllers = <AnimationController>{};
......
...@@ -273,6 +273,7 @@ void main() { ...@@ -273,6 +273,7 @@ void main() {
testWidgetsWithLeakTracking('Floating action button shrinks when bottom sheet becomes dominant', (WidgetTester tester) async { testWidgetsWithLeakTracking('Floating action button shrinks when bottom sheet becomes dominant', (WidgetTester tester) async {
final DraggableScrollableController draggableController = DraggableScrollableController(); final DraggableScrollableController draggableController = DraggableScrollableController();
addTearDown(draggableController.dispose);
const double kBottomSheetDominatesPercentage = 0.3; const double kBottomSheetDominatesPercentage = 0.3;
await tester.pumpWidget(MaterialApp(home: Scaffold( await tester.pumpWidget(MaterialApp(home: Scaffold(
...@@ -312,6 +313,7 @@ void main() { ...@@ -312,6 +313,7 @@ void main() {
testWidgetsWithLeakTracking('Scaffold shows scrim when bottom sheet becomes dominant', (WidgetTester tester) async { testWidgetsWithLeakTracking('Scaffold shows scrim when bottom sheet becomes dominant', (WidgetTester tester) async {
final DraggableScrollableController draggableController = DraggableScrollableController(); final DraggableScrollableController draggableController = DraggableScrollableController();
addTearDown(draggableController.dispose);
const double kBottomSheetDominatesPercentage = 0.3; const double kBottomSheetDominatesPercentage = 0.3;
const double kMinBottomSheetScrimOpacity = 0.1; const double kMinBottomSheetScrimOpacity = 0.1;
const double kMaxBottomSheetScrimOpacity = 0.6; const double kMaxBottomSheetScrimOpacity = 0.6;
...@@ -2762,6 +2764,7 @@ void main() { ...@@ -2762,6 +2764,7 @@ void main() {
testWidgetsWithLeakTracking('showBottomSheet removes scrim when draggable sheet is dismissed', (WidgetTester tester) async { testWidgetsWithLeakTracking('showBottomSheet removes scrim when draggable sheet is dismissed', (WidgetTester tester) async {
final DraggableScrollableController draggableController = DraggableScrollableController(); final DraggableScrollableController draggableController = DraggableScrollableController();
addTearDown(draggableController.dispose);
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey(); final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
PersistentBottomSheetController<void>? sheetController; PersistentBottomSheetController<void>? sheetController;
......
...@@ -1681,7 +1681,9 @@ void main() { ...@@ -1681,7 +1681,9 @@ void main() {
testWidgetsWithLeakTracking('DraggableScrollableSheet controller can be changed while animating', (WidgetTester tester) async { testWidgetsWithLeakTracking('DraggableScrollableSheet controller can be changed while animating', (WidgetTester tester) async {
final DraggableScrollableController controller1 = DraggableScrollableController(); final DraggableScrollableController controller1 = DraggableScrollableController();
addTearDown(controller1.dispose);
final DraggableScrollableController controller2 = DraggableScrollableController(); final DraggableScrollableController controller2 = DraggableScrollableController();
addTearDown(controller2.dispose);
DraggableScrollableController controller = controller1; DraggableScrollableController controller = controller1;
await tester.pumpWidget(MaterialApp( await tester.pumpWidget(MaterialApp(
...@@ -1733,4 +1735,11 @@ void main() { ...@@ -1733,4 +1735,11 @@ void main() {
expect(controller1.isAttached, false); expect(controller1.isAttached, false);
expect(controller2.isAttached, false); expect(controller2.isAttached, false);
}); });
testWidgetsWithLeakTracking('$DraggableScrollableController dispatches creation in constructor.', (WidgetTester widgetTester) async {
await expectLater(
await memoryEvents(() async => DraggableScrollableController().dispose(), DraggableScrollableController),
areCreateAndDispose,
);
});
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment