Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix not disposed items in Cupertino app and route. #134085

Merged
merged 7 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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