Skip to content

Commit

Permalink
Fix not disposed items in Cupertino app and route. (flutter#134085)
Browse files Browse the repository at this point in the history
  • Loading branch information
polina-c authored Sep 6, 2023
1 parent 99f5cf0 commit 61a388a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/flutter/lib/src/cupertino/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,12 @@ class _CupertinoAppState extends State<CupertinoApp> {
_heroController = CupertinoApp.createCupertinoHeroController();
}

@override
void dispose() {
_heroController.dispose();
super.dispose();
}

// Combine the default localization for Cupertino with the ones contributed
// by the localizationsDelegates parameter, if any. Only the first delegate
// of a particular LocalizationsDelegate.type is loaded so the
Expand Down
6 changes: 6 additions & 0 deletions packages/flutter/lib/src/cupertino/route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ mixin CupertinoRouteTransitionMixin<T> on PageRoute<T> {
return _previousTitle!;
}

@override
void dispose() {
_previousTitle?.dispose();
super.dispose();
}

@override
void didChangePrevious(Route<dynamic>? previousRoute) {
final String? previousTitleString = previousRoute is CupertinoRouteTransitionMixin
Expand Down
12 changes: 9 additions & 3 deletions packages/flutter/test/cupertino/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';

void main() {
testWidgets('Heroes work', (WidgetTester tester) async {
testWidgetsWithLeakTracking('Heroes work', (WidgetTester tester) async {
await tester.pumpWidget(CupertinoApp(
home: ListView(children: <Widget>[
const Hero(tag: 'a', child: Text('foo')),
Expand Down Expand Up @@ -394,6 +395,11 @@ void main() {
return renderEditable!;
}

final FocusNode focusNode = FocusNode();
addTearDown(focusNode.dispose);
final TextEditingController controller = TextEditingController();
addTearDown(controller.dispose);

await tester.pumpWidget(
CupertinoApp(
theme: const CupertinoThemeData(
Expand All @@ -405,8 +411,8 @@ void main() {
return EditableText(
backgroundCursorColor: DefaultSelectionStyle.of(context).selectionColor!,
cursorColor: DefaultSelectionStyle.of(context).cursorColor!,
controller: TextEditingController(),
focusNode: FocusNode(),
controller: controller,
focusNode: focusNode,
style: const TextStyle(),
);
},
Expand Down

0 comments on commit 61a388a

Please sign in to comment.