Skip to content

Commit 1f0730e

Browse files
authored
DraggableScrollableActuator should dispose notifier. (#133917)
1 parent 41ebf28 commit 1f0730e

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,12 +1015,12 @@ class _DraggableScrollableSheetScrollPosition extends ScrollPositionWithSingleCo
10151015
/// in library users' code). Generally, it's easier to control the sheet
10161016
/// directly by creating a controller and passing the controller to the sheet in
10171017
/// its constructor (see [DraggableScrollableSheet.controller]).
1018-
class DraggableScrollableActuator extends StatelessWidget {
1018+
class DraggableScrollableActuator extends StatefulWidget {
10191019
/// Creates a widget that can notify descendent [DraggableScrollableSheet]s
10201020
/// to reset to their initial position.
10211021
///
10221022
/// The [child] parameter is required.
1023-
DraggableScrollableActuator({
1023+
const DraggableScrollableActuator({
10241024
super.key,
10251025
required this.child,
10261026
});
@@ -1031,7 +1031,6 @@ class DraggableScrollableActuator extends StatelessWidget {
10311031
/// Must not be null.
10321032
final Widget child;
10331033

1034-
final _ResetNotifier _notifier = _ResetNotifier();
10351034

10361035
/// Notifies any descendant [DraggableScrollableSheet] that it should reset
10371036
/// to its initial position.
@@ -1047,9 +1046,22 @@ class DraggableScrollableActuator extends StatelessWidget {
10471046
return notifier._sendReset();
10481047
}
10491048

1049+
@override
1050+
State<DraggableScrollableActuator> createState() => _DraggableScrollableActuatorState();
1051+
}
1052+
1053+
class _DraggableScrollableActuatorState extends State<DraggableScrollableActuator> {
1054+
final _ResetNotifier _notifier = _ResetNotifier();
1055+
10501056
@override
10511057
Widget build(BuildContext context) {
1052-
return _InheritedResetNotifier(notifier: _notifier, child: child);
1058+
return _InheritedResetNotifier(notifier: _notifier, child: widget.child);
1059+
}
1060+
1061+
@override
1062+
void dispose() {
1063+
_notifier.dispose();
1064+
super.dispose();
10531065
}
10541066
}
10551067

packages/flutter/test/material/floating_action_button_location_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ void main() {
415415
expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX, _floatOffsetY));
416416
});
417417

418-
testWidgets('centerFloat', (WidgetTester tester) async {
418+
testWidgetsWithLeakTracking('centerFloat', (WidgetTester tester) async {
419419
await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.centerFloat));
420420

421421
expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_centerOffsetX, _floatOffsetY));
@@ -1037,7 +1037,7 @@ void main() {
10371037
);
10381038
});
10391039

1040-
testWidgets('centerFloat', (WidgetTester tester) async {
1040+
testWidgetsWithLeakTracking('centerFloat', (WidgetTester tester) async {
10411041
const Rect defaultRect = Rect.fromLTRB(372.0, 478.0, 428.0, 534.0);
10421042
// Positioned relative to BottomNavigationBar
10431043
const Rect bottomNavigationBarRect = Rect.fromLTRB(372.0, 422.0, 428.0, 478.0);

0 commit comments

Comments
 (0)