DraggableScrollableController should dispatch creation in constructor. (#135423)

This commit is contained in:
Kostia Sokolovskyi
2023-09-30 02:45:35 +02:00
committed by GitHub
parent 0f5cc2c0ae
commit fdde24195f
3 changed files with 19 additions and 0 deletions

View File

@@ -52,6 +52,13 @@ typedef ScrollableWidgetBuilder = Widget Function(
/// fire when [pixels] changes without [size] changing. For example, if the
/// constraints provided to an attached sheet change.
class DraggableScrollableController extends ChangeNotifier {
/// Creates a controller for [DraggableScrollableSheet].
DraggableScrollableController() {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}
_DraggableScrollableSheetScrollController? _attachedController;
final Set<AnimationController> _animationControllers = <AnimationController>{};

View File

@@ -273,6 +273,7 @@ void main() {
testWidgetsWithLeakTracking('Floating action button shrinks when bottom sheet becomes dominant', (WidgetTester tester) async {
final DraggableScrollableController draggableController = DraggableScrollableController();
addTearDown(draggableController.dispose);
const double kBottomSheetDominatesPercentage = 0.3;
await tester.pumpWidget(MaterialApp(home: Scaffold(
@@ -312,6 +313,7 @@ void main() {
testWidgetsWithLeakTracking('Scaffold shows scrim when bottom sheet becomes dominant', (WidgetTester tester) async {
final DraggableScrollableController draggableController = DraggableScrollableController();
addTearDown(draggableController.dispose);
const double kBottomSheetDominatesPercentage = 0.3;
const double kMinBottomSheetScrimOpacity = 0.1;
const double kMaxBottomSheetScrimOpacity = 0.6;
@@ -2762,6 +2764,7 @@ void main() {
testWidgetsWithLeakTracking('showBottomSheet removes scrim when draggable sheet is dismissed', (WidgetTester tester) async {
final DraggableScrollableController draggableController = DraggableScrollableController();
addTearDown(draggableController.dispose);
final GlobalKey<ScaffoldState> scaffoldKey = GlobalKey();
PersistentBottomSheetController<void>? sheetController;

View File

@@ -1681,7 +1681,9 @@ void main() {
testWidgetsWithLeakTracking('DraggableScrollableSheet controller can be changed while animating', (WidgetTester tester) async {
final DraggableScrollableController controller1 = DraggableScrollableController();
addTearDown(controller1.dispose);
final DraggableScrollableController controller2 = DraggableScrollableController();
addTearDown(controller2.dispose);
DraggableScrollableController controller = controller1;
await tester.pumpWidget(MaterialApp(
@@ -1733,4 +1735,11 @@ void main() {
expect(controller1.isAttached, false);
expect(controller2.isAttached, false);
});
testWidgetsWithLeakTracking('$DraggableScrollableController dispatches creation in constructor.', (WidgetTester widgetTester) async {
await expectLater(
await memoryEvents(() async => DraggableScrollableController().dispose(), DraggableScrollableController),
areCreateAndDispose,
);
});
}