Unverified Commit 453a04d9 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

TwoDimensionalChildDelegate should dispatch creation and disposal events (#145684)

parent 47bfa827
...@@ -885,6 +885,13 @@ Widget _createErrorWidget(Object exception, StackTrace stackTrace) { ...@@ -885,6 +885,13 @@ Widget _createErrorWidget(Object exception, StackTrace stackTrace) {
/// * [TwoDimensionalChildListDelegate], an concrete subclass of this that /// * [TwoDimensionalChildListDelegate], an concrete subclass of this that
/// uses a two dimensional array to layout children. /// uses a two dimensional array to layout children.
abstract class TwoDimensionalChildDelegate extends ChangeNotifier { abstract class TwoDimensionalChildDelegate extends ChangeNotifier {
/// Creates a delegate that supplies children for scrolling in two dimensions.
TwoDimensionalChildDelegate() {
if (kFlutterMemoryAllocationsEnabled) {
ChangeNotifier.maybeDispatchObjectCreation(this);
}
}
/// Returns the child with the given [ChildVicinity], which is described in /// Returns the child with the given [ChildVicinity], which is described in
/// terms of x and y indices. /// terms of x and y indices.
/// ///
......
...@@ -7,7 +7,6 @@ import 'dart:math' as math; ...@@ -7,7 +7,6 @@ import 'dart:math' as math;
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'two_dimensional_utils.dart'; import 'two_dimensional_utils.dart';
...@@ -1063,10 +1062,7 @@ void main() { ...@@ -1063,10 +1062,7 @@ void main() {
return tester.element(findKey(vicinity)); return tester.element(findKey(vicinity));
} }
testWidgets('Axis.vertical', testWidgets('Axis.vertical', (WidgetTester tester) async {
// TODO(polina-c): RenderTwoDimensionalViewport should dispose _delegate https://github.com/flutter/flutter/issues/145628 [leaks-to-clean]
experimentalLeakTesting: LeakTesting.settings.withIgnoredAll(),
(WidgetTester tester) async {
await tester.pumpWidget(simpleBuilderTest(useCacheExtent: true)); await tester.pumpWidget(simpleBuilderTest(useCacheExtent: true));
Scrollable.ensureVisible(findContext( Scrollable.ensureVisible(findContext(
......
// 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() {
test('TwoDimensionalChildBuilderDelegate dispatches memory events', () async {
await expectLater(
await memoryEvents(
() => TwoDimensionalChildBuilderDelegate(builder: (_, __) => null).dispose(),
TwoDimensionalChildBuilderDelegate,
),
areCreateAndDispose,
);
});
test('TwoDimensionalChildListDelegate dispatches memory events', () async {
await expectLater(
await memoryEvents(
() => TwoDimensionalChildListDelegate(children: <List<Widget>>[]).dispose(),
TwoDimensionalChildListDelegate,
),
areCreateAndDispose,
);
});
}
...@@ -360,6 +360,8 @@ void main() { ...@@ -360,6 +360,8 @@ void main() {
addTearDown(verticalController.dispose); addTearDown(verticalController.dispose);
final ScrollController horizontalController = ScrollController(); final ScrollController horizontalController = ScrollController();
addTearDown(horizontalController.dispose); addTearDown(horizontalController.dispose);
late final TwoDimensionalChildBuilderDelegate delegate;
addTearDown(() => delegate.dispose());
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
...@@ -368,7 +370,7 @@ void main() { ...@@ -368,7 +370,7 @@ void main() {
verticalDetails: ScrollableDetails.vertical(controller: verticalController), verticalDetails: ScrollableDetails.vertical(controller: verticalController),
horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController),
diagonalDragBehavior: DiagonalDragBehavior.free, diagonalDragBehavior: DiagonalDragBehavior.free,
delegate: TwoDimensionalChildBuilderDelegate( delegate: delegate = TwoDimensionalChildBuilderDelegate(
maxXIndex: 100, maxXIndex: 100,
maxYIndex: 100, maxYIndex: 100,
builder: (BuildContext context, ChildVicinity vicinity) { builder: (BuildContext context, ChildVicinity vicinity) {
...@@ -503,6 +505,8 @@ void main() { ...@@ -503,6 +505,8 @@ void main() {
addTearDown(verticalController.dispose); addTearDown(verticalController.dispose);
final ScrollController horizontalController = ScrollController(); final ScrollController horizontalController = ScrollController();
addTearDown(horizontalController.dispose); addTearDown(horizontalController.dispose);
late final TwoDimensionalChildBuilderDelegate delegate;
addTearDown(() => delegate.dispose());
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
...@@ -511,7 +515,7 @@ void main() { ...@@ -511,7 +515,7 @@ void main() {
verticalDetails: ScrollableDetails.vertical(controller: verticalController), verticalDetails: ScrollableDetails.vertical(controller: verticalController),
horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController),
diagonalDragBehavior: DiagonalDragBehavior.free, diagonalDragBehavior: DiagonalDragBehavior.free,
delegate: TwoDimensionalChildBuilderDelegate( delegate: delegate = TwoDimensionalChildBuilderDelegate(
maxXIndex: 100, maxXIndex: 100,
maxYIndex: 100, maxYIndex: 100,
builder: (BuildContext context, ChildVicinity vicinity) { builder: (BuildContext context, ChildVicinity vicinity) {
...@@ -588,6 +592,8 @@ void main() { ...@@ -588,6 +592,8 @@ void main() {
addTearDown(verticalController.dispose); addTearDown(verticalController.dispose);
final ScrollController horizontalController = ScrollController(); final ScrollController horizontalController = ScrollController();
addTearDown(horizontalController.dispose); addTearDown(horizontalController.dispose);
late final TwoDimensionalChildBuilderDelegate delegate;
addTearDown(() => delegate.dispose());
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
...@@ -596,7 +602,7 @@ void main() { ...@@ -596,7 +602,7 @@ void main() {
verticalDetails: ScrollableDetails.vertical(controller: verticalController), verticalDetails: ScrollableDetails.vertical(controller: verticalController),
horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController),
diagonalDragBehavior: DiagonalDragBehavior.free, diagonalDragBehavior: DiagonalDragBehavior.free,
delegate: TwoDimensionalChildBuilderDelegate( delegate: delegate = TwoDimensionalChildBuilderDelegate(
maxXIndex: 20, maxXIndex: 20,
maxYIndex: 1, maxYIndex: 1,
builder: _testChildBuilder, builder: _testChildBuilder,
...@@ -636,6 +642,8 @@ void main() { ...@@ -636,6 +642,8 @@ void main() {
addTearDown(verticalController.dispose); addTearDown(verticalController.dispose);
final ScrollController horizontalController = ScrollController(); final ScrollController horizontalController = ScrollController();
addTearDown(horizontalController.dispose); addTearDown(horizontalController.dispose);
late final TwoDimensionalChildBuilderDelegate delegate;
addTearDown(() => delegate.dispose());
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
...@@ -644,7 +652,7 @@ void main() { ...@@ -644,7 +652,7 @@ void main() {
verticalDetails: ScrollableDetails.vertical(controller: verticalController), verticalDetails: ScrollableDetails.vertical(controller: verticalController),
horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController),
diagonalDragBehavior: DiagonalDragBehavior.weightedEvent, diagonalDragBehavior: DiagonalDragBehavior.weightedEvent,
delegate: TwoDimensionalChildBuilderDelegate( delegate: delegate = TwoDimensionalChildBuilderDelegate(
maxXIndex: 20, maxXIndex: 20,
maxYIndex: 1, maxYIndex: 1,
builder: _testChildBuilder, builder: _testChildBuilder,
...@@ -684,6 +692,8 @@ void main() { ...@@ -684,6 +692,8 @@ void main() {
addTearDown(verticalController.dispose); addTearDown(verticalController.dispose);
final ScrollController horizontalController = ScrollController(); final ScrollController horizontalController = ScrollController();
addTearDown(horizontalController.dispose); addTearDown(horizontalController.dispose);
late final TwoDimensionalChildBuilderDelegate delegate;
addTearDown(() => delegate.dispose());
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
...@@ -692,7 +702,7 @@ void main() { ...@@ -692,7 +702,7 @@ void main() {
verticalDetails: ScrollableDetails.vertical(controller: verticalController), verticalDetails: ScrollableDetails.vertical(controller: verticalController),
horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController),
diagonalDragBehavior: DiagonalDragBehavior.weightedContinuous, diagonalDragBehavior: DiagonalDragBehavior.weightedContinuous,
delegate: TwoDimensionalChildBuilderDelegate( delegate: delegate = TwoDimensionalChildBuilderDelegate(
maxXIndex: 20, maxXIndex: 20,
maxYIndex: 1, maxYIndex: 1,
builder: _testChildBuilder, builder: _testChildBuilder,
...@@ -734,6 +744,8 @@ void main() { ...@@ -734,6 +744,8 @@ void main() {
addTearDown(verticalController.dispose); addTearDown(verticalController.dispose);
final ScrollController horizontalController = ScrollController(); final ScrollController horizontalController = ScrollController();
addTearDown(horizontalController.dispose); addTearDown(horizontalController.dispose);
late final TwoDimensionalChildBuilderDelegate delegate;
addTearDown(() => delegate.dispose());
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
...@@ -742,7 +754,7 @@ void main() { ...@@ -742,7 +754,7 @@ void main() {
verticalDetails: ScrollableDetails.vertical(controller: verticalController), verticalDetails: ScrollableDetails.vertical(controller: verticalController),
horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController),
diagonalDragBehavior: DiagonalDragBehavior.free, diagonalDragBehavior: DiagonalDragBehavior.free,
delegate: TwoDimensionalChildBuilderDelegate( delegate: delegate = TwoDimensionalChildBuilderDelegate(
maxXIndex: 1, maxXIndex: 1,
maxYIndex: 20, maxYIndex: 20,
builder: _testChildBuilder, builder: _testChildBuilder,
...@@ -782,6 +794,8 @@ void main() { ...@@ -782,6 +794,8 @@ void main() {
addTearDown(verticalController.dispose); addTearDown(verticalController.dispose);
final ScrollController horizontalController = ScrollController(); final ScrollController horizontalController = ScrollController();
addTearDown(horizontalController.dispose); addTearDown(horizontalController.dispose);
late final TwoDimensionalChildBuilderDelegate delegate;
addTearDown(() => delegate.dispose());
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
...@@ -790,7 +804,7 @@ void main() { ...@@ -790,7 +804,7 @@ void main() {
verticalDetails: ScrollableDetails.vertical(controller: verticalController), verticalDetails: ScrollableDetails.vertical(controller: verticalController),
horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController),
diagonalDragBehavior: DiagonalDragBehavior.weightedEvent, diagonalDragBehavior: DiagonalDragBehavior.weightedEvent,
delegate: TwoDimensionalChildBuilderDelegate( delegate: delegate = TwoDimensionalChildBuilderDelegate(
maxXIndex: 1, maxXIndex: 1,
maxYIndex: 20, maxYIndex: 20,
builder: _testChildBuilder, builder: _testChildBuilder,
...@@ -830,6 +844,8 @@ void main() { ...@@ -830,6 +844,8 @@ void main() {
addTearDown(verticalController.dispose); addTearDown(verticalController.dispose);
final ScrollController horizontalController = ScrollController(); final ScrollController horizontalController = ScrollController();
addTearDown(horizontalController.dispose); addTearDown(horizontalController.dispose);
late final TwoDimensionalChildBuilderDelegate delegate;
addTearDown(() => delegate.dispose());
await tester.pumpWidget( await tester.pumpWidget(
Directionality( Directionality(
...@@ -838,7 +854,7 @@ void main() { ...@@ -838,7 +854,7 @@ void main() {
verticalDetails: ScrollableDetails.vertical(controller: verticalController), verticalDetails: ScrollableDetails.vertical(controller: verticalController),
horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController), horizontalDetails: ScrollableDetails.horizontal(controller: horizontalController),
diagonalDragBehavior: DiagonalDragBehavior.weightedContinuous, diagonalDragBehavior: DiagonalDragBehavior.weightedContinuous,
delegate: TwoDimensionalChildBuilderDelegate( delegate: delegate = TwoDimensionalChildBuilderDelegate(
maxXIndex: 1, maxXIndex: 1,
maxYIndex: 20, maxYIndex: 20,
builder: _testChildBuilder, builder: _testChildBuilder,
......
...@@ -335,6 +335,7 @@ void main() { ...@@ -335,6 +335,7 @@ void main() {
); );
} }
); );
addTearDown(builderDelegate.dispose);
await tester.pumpWidget(simpleBuilderTest( await tester.pumpWidget(simpleBuilderTest(
delegate: builderDelegate, delegate: builderDelegate,
......
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