Unverified Commit 49e16867 authored by Polina Cherkasova's avatar Polina Cherkasova Committed by GitHub

TabController should dispatch creation in constructor. (#133952)

parent c00e9798
...@@ -6,6 +6,7 @@ import 'dart:math' as math; ...@@ -6,6 +6,7 @@ import 'dart:math' as math;
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import '../foundation/memory_allocations.dart';
import 'constants.dart'; import 'constants.dart';
// Examples can assume: // Examples can assume:
...@@ -114,7 +115,11 @@ class TabController extends ChangeNotifier { ...@@ -114,7 +115,11 @@ class TabController extends ChangeNotifier {
_animationController = AnimationController.unbounded( _animationController = AnimationController.unbounded(
value: initialIndex.toDouble(), value: initialIndex.toDouble(),
vsync: vsync, vsync: vsync,
); ) {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}
// Private constructor used by `_copyWith`. This allows a new TabController to // Private constructor used by `_copyWith`. This allows a new TabController to
// be created without having to create a new animationController. // be created without having to create a new animationController.
......
...@@ -1380,6 +1380,7 @@ class _TabBarState extends State<TabBar> { ...@@ -1380,6 +1380,7 @@ class _TabBarState extends State<TabBar> {
_controller!.removeListener(_handleTabControllerTick); _controller!.removeListener(_handleTabControllerTick);
} }
_controller = null; _controller = null;
_scrollController?.dispose();
// We don't own the _controller Animation, so it's not disposed here. // We don't own the _controller Animation, so it's not disposed here.
super.dispose(); super.dispose();
} }
......
...@@ -70,6 +70,7 @@ void main() { ...@@ -70,6 +70,7 @@ void main() {
vsync: const TestVSync(), vsync: const TestVSync(),
length: 3, length: 3,
); );
addTearDown(tabController.dispose);
await tester.pumpWidget(buildFrame(tabController)); await tester.pumpWidget(buildFrame(tabController));
expect(tabController.index, 0); expect(tabController.index, 0);
...@@ -91,6 +92,7 @@ void main() { ...@@ -91,6 +92,7 @@ void main() {
vsync: const TestVSync(), vsync: const TestVSync(),
length: 3, length: 3,
); );
addTearDown(tabController.dispose);
await tester.pumpWidget(buildFrame(tabController)); await tester.pumpWidget(buildFrame(tabController));
expect(tabController.index, 0); expect(tabController.index, 0);
...@@ -135,6 +137,7 @@ void main() { ...@@ -135,6 +137,7 @@ void main() {
initialIndex: 1, initialIndex: 1,
length: 3, length: 3,
); );
addTearDown(tabController.dispose);
await tester.pumpWidget(buildFrame(tabController)); await tester.pumpWidget(buildFrame(tabController));
expect(tabController.index, 1); expect(tabController.index, 1);
...@@ -196,6 +199,7 @@ void main() { ...@@ -196,6 +199,7 @@ void main() {
initialIndex: 1, initialIndex: 1,
length: 3, length: 3,
); );
addTearDown(tabController.dispose);
await tester.pumpWidget(buildFrame(tabController, color: kRed, selectedColor: kBlue)); await tester.pumpWidget(buildFrame(tabController, color: kRed, selectedColor: kBlue));
expect(tabController.index, 1); expect(tabController.index, 1);
...@@ -212,6 +216,7 @@ void main() { ...@@ -212,6 +216,7 @@ void main() {
initialIndex: 1, initialIndex: 1,
length: 3, length: 3,
); );
addTearDown(tabController.dispose);
await tester.pumpWidget(buildFrame(tabController, indicatorSize: 16.0)); await tester.pumpWidget(buildFrame(tabController, indicatorSize: 16.0));
final Iterable<Element> indicatorElements = find.descendant( final Iterable<Element> indicatorElements = find.descendant(
...@@ -233,6 +238,7 @@ void main() { ...@@ -233,6 +238,7 @@ void main() {
initialIndex: 1, initialIndex: 1,
length: 3, length: 3,
); );
addTearDown(tabController.dispose);
Iterable<TabPageSelectorIndicator> indicators; Iterable<TabPageSelectorIndicator> indicators;
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
void main() {
testWidgetsWithLeakTracking('$TabController dispatches creation in constructor.', (WidgetTester widgetTester) async {
await expectLater(
await memoryEvents(() async => TabController(length: 1, vsync: const TestVSync()).dispose(), TabController),
areCreateAndDispose,
);
});
}
...@@ -1062,7 +1062,7 @@ void main() { ...@@ -1062,7 +1062,7 @@ void main() {
element.createChild(0, after: null); element.createChild(0, after: null);
}); });
testWidgetsWithLeakTracking('GlobalKey - re-attach child to new parents, and the old parent is deactivated(unmounted)', (WidgetTester tester) async { testWidgets('GlobalKey - re-attach child to new parents, and the old parent is deactivated(unmounted)', (WidgetTester tester) async {
// This is a regression test for https://github.com/flutter/flutter/issues/62055 // This is a regression test for https://github.com/flutter/flutter/issues/62055
const Key key1 = GlobalObjectKey('key1'); const Key key1 = GlobalObjectKey('key1');
const Key key2 = GlobalObjectKey('key2'); const Key key2 = GlobalObjectKey('key2');
......
...@@ -861,7 +861,7 @@ void main() { ...@@ -861,7 +861,7 @@ void main() {
expect(targetMidLeftPage1, findsOneWidget); expect(targetMidLeftPage1, findsOneWidget);
}); });
testWidgetsWithLeakTracking('ensureVisible does not move TabViews', (WidgetTester tester) async { testWidgets('ensureVisible does not move TabViews', (WidgetTester tester) async {
final TickerProvider vsync = TestTickerProvider(); final TickerProvider vsync = TestTickerProvider();
final TabController controller = TabController( final TabController controller = TabController(
length: 3, length: 3,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment