DraggableScrollableActuator should dispose notifier. (#133917)

This commit is contained in:
Polina Cherkasova 2023-09-06 15:07:07 -07:00 committed by GitHub
parent 41ebf282d4
commit 1f0730e67a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 6 deletions

View File

@ -1015,12 +1015,12 @@ class _DraggableScrollableSheetScrollPosition extends ScrollPositionWithSingleCo
/// in library users' code). Generally, it's easier to control the sheet
/// directly by creating a controller and passing the controller to the sheet in
/// its constructor (see [DraggableScrollableSheet.controller]).
class DraggableScrollableActuator extends StatelessWidget {
class DraggableScrollableActuator extends StatefulWidget {
/// Creates a widget that can notify descendent [DraggableScrollableSheet]s
/// to reset to their initial position.
///
/// The [child] parameter is required.
DraggableScrollableActuator({
const DraggableScrollableActuator({
super.key,
required this.child,
});
@ -1031,7 +1031,6 @@ class DraggableScrollableActuator extends StatelessWidget {
/// Must not be null.
final Widget child;
final _ResetNotifier _notifier = _ResetNotifier();
/// Notifies any descendant [DraggableScrollableSheet] that it should reset
/// to its initial position.
@ -1047,9 +1046,22 @@ class DraggableScrollableActuator extends StatelessWidget {
return notifier._sendReset();
}
@override
State<DraggableScrollableActuator> createState() => _DraggableScrollableActuatorState();
}
class _DraggableScrollableActuatorState extends State<DraggableScrollableActuator> {
final _ResetNotifier _notifier = _ResetNotifier();
@override
Widget build(BuildContext context) {
return _InheritedResetNotifier(notifier: _notifier, child: child);
return _InheritedResetNotifier(notifier: _notifier, child: widget.child);
}
@override
void dispose() {
_notifier.dispose();
super.dispose();
}
}

View File

@ -415,7 +415,7 @@ void main() {
expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX, _floatOffsetY));
});
testWidgets('centerFloat', (WidgetTester tester) async {
testWidgetsWithLeakTracking('centerFloat', (WidgetTester tester) async {
await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.centerFloat));
expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_centerOffsetX, _floatOffsetY));
@ -1037,7 +1037,7 @@ void main() {
);
});
testWidgets('centerFloat', (WidgetTester tester) async {
testWidgetsWithLeakTracking('centerFloat', (WidgetTester tester) async {
const Rect defaultRect = Rect.fromLTRB(372.0, 478.0, 428.0, 534.0);
// Positioned relative to BottomNavigationBar
const Rect bottomNavigationBarRect = Rect.fromLTRB(372.0, 422.0, 428.0, 478.0);