mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
fixes DialogRoute
memory leak (#147816)
This commit is contained in:
parent
82fb5db893
commit
0d22d9101a
@ -1308,13 +1308,7 @@ class SimpleDialog extends StatelessWidget {
|
||||
}
|
||||
|
||||
Widget _buildMaterialDialogTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
|
||||
return FadeTransition(
|
||||
opacity: CurvedAnimation(
|
||||
parent: animation,
|
||||
curve: Curves.easeOut,
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
return child;
|
||||
}
|
||||
|
||||
/// Displays a Material dialog above the current contents of the app, with
|
||||
@ -1589,6 +1583,33 @@ class DialogRoute<T> extends RawDialogRoute<T> {
|
||||
transitionDuration: const Duration(milliseconds: 150),
|
||||
transitionBuilder: _buildMaterialDialogTransitions,
|
||||
);
|
||||
|
||||
CurvedAnimation? _curvedAnimation;
|
||||
|
||||
void _setAnimation(Animation<double> animation) {
|
||||
if (_curvedAnimation?.parent != animation) {
|
||||
_curvedAnimation?.dispose();
|
||||
_curvedAnimation = CurvedAnimation(
|
||||
parent: animation,
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget buildTransitions(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
|
||||
_setAnimation(animation);
|
||||
return FadeTransition(
|
||||
opacity: _curvedAnimation!,
|
||||
child: super.buildTransitions(context, animation, secondaryAnimation, child),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_curvedAnimation?.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
double _scalePadding(double textScaleFactor) {
|
||||
|
@ -15,6 +15,7 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
|
||||
|
||||
import '../widgets/semantics_tester.dart';
|
||||
|
||||
@ -355,7 +356,10 @@ void main() {
|
||||
expect(tester.getSize(find.widgetWithText(CupertinoDialogAction, 'OK')), equals(const Size(310.0, 98.0)));
|
||||
});
|
||||
|
||||
testWidgets('Dialog respects small constraints.', (WidgetTester tester) async {
|
||||
testWidgets('Dialog respects small constraints.',
|
||||
// TODO(polina-c): remove when fixed https://github.com/flutter/flutter/issues/145600 [leak-tracking-opt-in]
|
||||
experimentalLeakTesting: LeakTesting.settings.withTracked(classes: const <String>['CurvedAnimation']),
|
||||
(WidgetTester tester) async {
|
||||
final ScrollController scrollController = ScrollController();
|
||||
addTearDown(scrollController.dispose);
|
||||
await tester.pumpWidget(
|
||||
|
Loading…
Reference in New Issue
Block a user