TabController should dispatch creation in constructor. (#133952)
This commit is contained in:
committed by
GitHub
parent
c00e9798ff
commit
49e16867a3
@@ -6,6 +6,7 @@ import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
import '../foundation/memory_allocations.dart';
|
||||
import 'constants.dart';
|
||||
|
||||
// Examples can assume:
|
||||
@@ -114,7 +115,11 @@ class TabController extends ChangeNotifier {
|
||||
_animationController = AnimationController.unbounded(
|
||||
value: initialIndex.toDouble(),
|
||||
vsync: vsync,
|
||||
);
|
||||
) {
|
||||
if (kFlutterMemoryAllocationsEnabled) {
|
||||
ChangeNotifier.maybeDispatchObjectCreation(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Private constructor used by `_copyWith`. This allows a new TabController to
|
||||
// be created without having to create a new animationController.
|
||||
|
||||
@@ -1380,6 +1380,7 @@ class _TabBarState extends State<TabBar> {
|
||||
_controller!.removeListener(_handleTabControllerTick);
|
||||
}
|
||||
_controller = null;
|
||||
_scrollController?.dispose();
|
||||
// We don't own the _controller Animation, so it's not disposed here.
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ void main() {
|
||||
vsync: const TestVSync(),
|
||||
length: 3,
|
||||
);
|
||||
addTearDown(tabController.dispose);
|
||||
await tester.pumpWidget(buildFrame(tabController));
|
||||
|
||||
expect(tabController.index, 0);
|
||||
@@ -91,6 +92,7 @@ void main() {
|
||||
vsync: const TestVSync(),
|
||||
length: 3,
|
||||
);
|
||||
addTearDown(tabController.dispose);
|
||||
await tester.pumpWidget(buildFrame(tabController));
|
||||
|
||||
expect(tabController.index, 0);
|
||||
@@ -135,6 +137,7 @@ void main() {
|
||||
initialIndex: 1,
|
||||
length: 3,
|
||||
);
|
||||
addTearDown(tabController.dispose);
|
||||
await tester.pumpWidget(buildFrame(tabController));
|
||||
|
||||
expect(tabController.index, 1);
|
||||
@@ -196,6 +199,7 @@ void main() {
|
||||
initialIndex: 1,
|
||||
length: 3,
|
||||
);
|
||||
addTearDown(tabController.dispose);
|
||||
await tester.pumpWidget(buildFrame(tabController, color: kRed, selectedColor: kBlue));
|
||||
|
||||
expect(tabController.index, 1);
|
||||
@@ -212,6 +216,7 @@ void main() {
|
||||
initialIndex: 1,
|
||||
length: 3,
|
||||
);
|
||||
addTearDown(tabController.dispose);
|
||||
await tester.pumpWidget(buildFrame(tabController, indicatorSize: 16.0));
|
||||
|
||||
final Iterable<Element> indicatorElements = find.descendant(
|
||||
@@ -233,6 +238,7 @@ void main() {
|
||||
initialIndex: 1,
|
||||
length: 3,
|
||||
);
|
||||
addTearDown(tabController.dispose);
|
||||
|
||||
Iterable<TabPageSelectorIndicator> indicators;
|
||||
|
||||
|
||||
16
packages/flutter/test/material/tab_controller_test.dart
Normal file
16
packages/flutter/test/material/tab_controller_test.dart
Normal file
@@ -0,0 +1,16 @@
|
||||
// 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() {
|
||||
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
|
||||
const Key key1 = GlobalObjectKey('key1');
|
||||
const Key key2 = GlobalObjectKey('key2');
|
||||
|
||||
@@ -861,7 +861,7 @@ void main() {
|
||||
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 TabController controller = TabController(
|
||||
length: 3,
|
||||
|
||||
Reference in New Issue
Block a user