keep_alive_test.dart 35.6 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io' show Platform;

7
import 'package:flutter/foundation.dart';
8
import 'package:flutter/widgets.dart';
9
import 'package:flutter_test/flutter_test.dart';
10
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
11 12

class Leaf extends StatefulWidget {
13
  const Leaf({
14
    super.key,
15
    required this.child,
16
  });
17 18
  final Widget child;
  @override
19
  State<Leaf> createState() => _LeafState();
20 21 22 23 24 25 26 27 28 29 30
}

class _LeafState extends State<Leaf> {
  bool _keepAlive = false;

  void setKeepAlive(bool value) {
    setState(() { _keepAlive = value; });
  }

  @override
  Widget build(BuildContext context) {
31
    return KeepAlive(
32 33 34 35 36 37 38
      keepAlive: _keepAlive,
      child: widget.child,
    );
  }
}

List<Widget> generateList(Widget child) {
39
  return List<Widget>.generate(
40
    100,
41 42
    (int index) => Leaf(
      key: GlobalObjectKey<_LeafState>(index),
43 44 45 46 47 48 49
      child: child,
    ),
    growable: false,
  );
}

void main() {
50 51 52 53 54 55 56 57
  test('KeepAlive debugTypicalAncestorWidgetClass', () {
    final KeepAlive keepAlive = KeepAlive(keepAlive: false, child: Container());
    expect(
      keepAlive.debugTypicalAncestorWidgetDescription,
      'SliverWithKeepAliveWidget or TwoDimensionalViewport',
    );
  });

58
  testWidgetsWithLeakTracking('KeepAlive with ListView with itemExtent', (WidgetTester tester) async {
59
    await tester.pumpWidget(
60
      Directionality(
61
        textDirection: TextDirection.ltr,
62
        child: ListView(
63
          cacheExtent: 0.0,
64 65
          addAutomaticKeepAlives: false,
          addRepaintBoundaries: false,
66
          addSemanticIndexes: false,
67 68 69 70 71
          itemExtent: 12.3, // about 50 widgets visible
          children: generateList(const Placeholder()),
        ),
      ),
    );
72 73
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
74 75 76 77
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
78 79
    await tester.drag(find.byType(ListView), const Offset(0.0, -300.0)); // about 25 widgets' worth
    await tester.pump();
80
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3), skipOffstage: false), findsNothing);
81 82 83 84
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61)), findsOneWidget);
85
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
86
    const GlobalObjectKey<_LeafState>(60).currentState!.setKeepAlive(true);
87 88 89 90
    await tester.drag(find.byType(ListView), const Offset(0.0, 300.0)); // back to top
    await tester.pump();
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
91 92 93 94 95
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60), skipOffstage: false), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60)), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
96
    const GlobalObjectKey<_LeafState>(60).currentState!.setKeepAlive(false);
97 98 99
    await tester.pump();
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
100 101 102 103
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
104 105
  });

106
  testWidgetsWithLeakTracking('KeepAlive with ListView without itemExtent', (WidgetTester tester) async {
107
    await tester.pumpWidget(
108
      Directionality(
109
        textDirection: TextDirection.ltr,
110
        child: ListView(
111
          cacheExtent: 0.0,
112 113
          addAutomaticKeepAlives: false,
          addRepaintBoundaries: false,
114
          addSemanticIndexes: false,
115
          children: generateList(const SizedBox(height: 12.3, child: Placeholder())), // about 50 widgets visible
116 117 118
        ),
      ),
    );
119 120
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
121 122 123 124
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
125 126
    await tester.drag(find.byType(ListView), const Offset(0.0, -300.0)); // about 25 widgets' worth
    await tester.pump();
127
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3), skipOffstage: false), findsNothing);
128 129 130 131
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61)), findsOneWidget);
132
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
133
    const GlobalObjectKey<_LeafState>(60).currentState!.setKeepAlive(true);
134 135 136 137
    await tester.drag(find.byType(ListView), const Offset(0.0, 300.0)); // back to top
    await tester.pump();
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
138 139 140 141 142
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60), skipOffstage: false), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60)), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
143
    const GlobalObjectKey<_LeafState>(60).currentState!.setKeepAlive(false);
144 145 146
    await tester.pump();
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
147 148 149 150
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
151 152
  });

153
  testWidgetsWithLeakTracking('KeepAlive with GridView', (WidgetTester tester) async {
154
    await tester.pumpWidget(
155
      Directionality(
156
        textDirection: TextDirection.ltr,
157
        child: GridView.count(
158
          cacheExtent: 0.0,
159 160
          addAutomaticKeepAlives: false,
          addRepaintBoundaries: false,
161
          addSemanticIndexes: false,
162 163
          crossAxisCount: 2,
          childAspectRatio: 400.0 / 24.6, // about 50 widgets visible
164
          children: generateList(const Placeholder()),
165 166 167
        ),
      ),
    );
168 169
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
170 171 172 173
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
174 175
    await tester.drag(find.byType(GridView), const Offset(0.0, -300.0)); // about 25 widgets' worth
    await tester.pump();
176
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3), skipOffstage: false), findsNothing);
177 178 179 180
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61)), findsOneWidget);
181
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
182
    const GlobalObjectKey<_LeafState>(60).currentState!.setKeepAlive(true);
183 184 185 186
    await tester.drag(find.byType(GridView), const Offset(0.0, 300.0)); // back to top
    await tester.pump();
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
187 188 189 190 191
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60), skipOffstage: false), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60)), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
192
    const GlobalObjectKey<_LeafState>(60).currentState!.setKeepAlive(false);
193 194 195
    await tester.pump();
    expect(find.byKey(const GlobalObjectKey<_LeafState>(3)), findsOneWidget);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(30)), findsOneWidget);
196 197 198 199
    expect(find.byKey(const GlobalObjectKey<_LeafState>(59), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(60), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(61), skipOffstage: false), findsNothing);
    expect(find.byKey(const GlobalObjectKey<_LeafState>(90), skipOffstage: false), findsNothing);
200 201
  });

202
  testWidgetsWithLeakTracking('KeepAlive render tree description', (WidgetTester tester) async {
203
    await tester.pumpWidget(
204
      Directionality(
205
        textDirection: TextDirection.ltr,
206
        child: ListView(
207 208
          addAutomaticKeepAlives: false,
          addRepaintBoundaries: false,
209
          addSemanticIndexes: false,
210 211 212 213 214
          itemExtent: 400.0, // 2 visible children
          children: generateList(const Placeholder()),
        ),
      ),
    );
215
    // The important lines below are the ones marked with "<----"
216
    expect(tester.binding.renderView.toStringDeep(minLevel: DiagnosticLevel.info), equalsIgnoringHashCodes(
217
      '_ReusableRenderView#00000\n'
218
      ' │ debug mode enabled - ${Platform.operatingSystem}\n'
219
      ' │ view size: Size(2400.0, 1800.0) (in physical pixels)\n'
220 221 222 223
      ' │ device pixel ratio: 3.0 (physical pixels per logical pixel)\n'
      ' │ configuration: Size(800.0, 600.0) at 3.0x (in logical pixels)\n'
      ' │\n'
      ' └─child: RenderRepaintBoundary#00000\n'
224
      '   │ needs compositing\n'
225 226 227 228 229 230 231 232 233
      '   │ parentData: <none>\n'
      '   │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '   │ layer: OffsetLayer#00000\n'
      '   │ size: Size(800.0, 600.0)\n'
      '   │ metrics: 0.0% useful (1 bad vs 0 good)\n'
      '   │ diagnosis: insufficient data to draw conclusion (less than five\n'
      '   │   repaints)\n'
      '   │\n'
      '   └─child: RenderCustomPaint#00000\n'
234
      '     │ needs compositing\n'
235 236 237
      '     │ parentData: <none> (can use size)\n'
      '     │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '     │ size: Size(800.0, 600.0)\n'
Ian Hickson's avatar
Ian Hickson committed
238 239 240 241 242
      '     │ painter: null\n'
      '     │ foregroundPainter:\n'
      '     │   _GlowingOverscrollIndicatorPainter(_GlowController(color:\n'
      '     │   Color(0xffffffff), axis: vertical), _GlowController(color:\n'
      '     │   Color(0xffffffff), axis: vertical))\n'
243 244
      '     │\n'
      '     └─child: RenderRepaintBoundary#00000\n'
245
      '       │ needs compositing\n'
246 247 248 249 250 251 252 253
      '       │ parentData: <none> (can use size)\n'
      '       │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '       │ layer: OffsetLayer#00000\n'
      '       │ size: Size(800.0, 600.0)\n'
      '       │ metrics: 0.0% useful (1 bad vs 0 good)\n'
      '       │ diagnosis: insufficient data to draw conclusion (less than five\n'
      '       │   repaints)\n'
      '       │\n'
Ian Hickson's avatar
Ian Hickson committed
254
      '       └─child: _RenderScrollSemantics#00000\n'
255
      '         │ needs compositing\n'
256 257
      '         │ parentData: <none> (can use size)\n'
      '         │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
258
      '         │ semantics node: SemanticsNode#1\n'
259
      '         │ semantic boundary\n'
260 261
      '         │ size: Size(800.0, 600.0)\n'
      '         │\n'
262
      '         └─child: RenderPointerListener#00000\n'
263
      '           │ needs compositing\n'
264 265 266
      '           │ parentData: <none> (can use size)\n'
      '           │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '           │ size: Size(800.0, 600.0)\n'
267 268
      '           │ behavior: deferToChild\n'
      '           │ listeners: signal\n'
269
      '           │\n'
270
      '           └─child: RenderSemanticsGestureHandler#00000\n'
271
      '             │ needs compositing\n'
272 273 274
      '             │ parentData: <none> (can use size)\n'
      '             │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '             │ size: Size(800.0, 600.0)\n'
275
      '             │ behavior: opaque\n'
276
      '             │ gestures: vertical scroll\n'
277
      '             │\n'
278
      '             └─child: RenderPointerListener#00000\n'
279
      '               │ needs compositing\n'
280 281 282
      '               │ parentData: <none> (can use size)\n'
      '               │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '               │ size: Size(800.0, 600.0)\n'
283
      '               │ behavior: opaque\n'
284
      '               │ listeners: down, panZoomStart\n'
285
      '               │\n'
286
      '               └─child: RenderSemanticsAnnotations#00000\n'
287
      '                 │ needs compositing\n'
288 289 290
      '                 │ parentData: <none> (can use size)\n'
      '                 │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '                 │ size: Size(800.0, 600.0)\n'
291
      '                 │\n'
292
      '                 └─child: RenderIgnorePointer#00000\n'
293
      '                   │ needs compositing\n'
294 295 296
      '                   │ parentData: <none> (can use size)\n'
      '                   │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '                   │ size: Size(800.0, 600.0)\n'
297
      '                   │ ignoring: false\n'
298
      '                   │ ignoringSemantics: null\n'
299
      '                   │\n'
300
      '                   └─child: RenderViewport#00000\n'
301
      '                     │ needs compositing\n'
302 303 304 305 306 307 308 309
      '                     │ parentData: <none> (can use size)\n'
      '                     │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '                     │ layer: OffsetLayer#00000\n'
      '                     │ size: Size(800.0, 600.0)\n'
      '                     │ axisDirection: down\n'
      '                     │ crossAxisDirection: right\n'
      '                     │ offset: ScrollPositionWithSingleContext#00000(offset: 0.0, range:\n'
      '                     │   0.0..39400.0, viewport: 600.0, ScrollableState,\n'
310 311 312
      '                     │   AlwaysScrollableScrollPhysics -> ClampingScrollPhysics ->\n'
      '                     │   RangeMaintainingScrollPhysics, IdleScrollActivity#00000,\n'
      '                     │   ScrollDirection.idle)\n'
313
      '                     │ anchor: 0.0\n'
314
      '                     │\n'
315
      '                     └─center child: RenderSliverPadding#00000 relayoutBoundary=up1\n'
316 317 318 319 320
      '                       │ parentData: paintOffset=Offset(0.0, 0.0) (can use size)\n'
      '                       │ constraints: SliverConstraints(AxisDirection.down,\n'
      '                       │   GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
      '                       │   0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n'
      '                       │   crossAxisDirection: AxisDirection.right,\n'
321 322
      '                       │   viewportMainAxisExtent: 600.0, remainingCacheExtent: 850.0,\n'
      '                       │   cacheOrigin: 0.0)\n'
323 324 325
      '                       │ geometry: SliverGeometry(scrollExtent: 40000.0, paintExtent:\n'
      '                       │   600.0, maxPaintExtent: 40000.0, hasVisualOverflow: true,\n'
      '                       │   cacheExtent: 850.0)\n'
326 327
      '                       │ padding: EdgeInsets.zero\n'
      '                       │ textDirection: ltr\n'
328
      '                       │\n'
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
      '                       └─child: RenderSliverFixedExtentList#00000 relayoutBoundary=up2\n'
      '                         │ parentData: paintOffset=Offset(0.0, 0.0) (can use size)\n'
      '                         │ constraints: SliverConstraints(AxisDirection.down,\n'
      '                         │   GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
      '                         │   0.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n'
      '                         │   crossAxisDirection: AxisDirection.right,\n'
      '                         │   viewportMainAxisExtent: 600.0, remainingCacheExtent: 850.0,\n'
      '                         │   cacheOrigin: 0.0)\n'
      '                         │ geometry: SliverGeometry(scrollExtent: 40000.0, paintExtent:\n'
      '                         │   600.0, maxPaintExtent: 40000.0, hasVisualOverflow: true,\n'
      '                         │   cacheExtent: 850.0)\n'
      '                         │ currently live children: 0 to 2\n'
      '                         │\n'
      '                         ├─child with index 0: RenderLimitedBox#00000\n'
      '                         │ │ parentData: index=0; layoutOffset=0.0\n'
      '                         │ │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         │ │ size: Size(800.0, 400.0)\n'
      '                         │ │ maxWidth: 400.0\n'
      '                         │ │ maxHeight: 400.0\n'
      '                         │ │\n'
      '                         │ └─child: RenderCustomPaint#00000\n'
      '                         │     parentData: <none> (can use size)\n'
      '                         │     constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         │     size: Size(800.0, 400.0)\n'
      '                         │     painter: _PlaceholderPainter#00000()\n'
      '                         │     preferredSize: Size(Infinity, Infinity)\n'
355
      '                         │\n'
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
      '                         ├─child with index 1: RenderLimitedBox#00000\n'                                      // <----- no dashed line starts here
      '                         │ │ parentData: index=1; layoutOffset=400.0\n'
      '                         │ │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         │ │ size: Size(800.0, 400.0)\n'
      '                         │ │ maxWidth: 400.0\n'
      '                         │ │ maxHeight: 400.0\n'
      '                         │ │\n'
      '                         │ └─child: RenderCustomPaint#00000\n'
      '                         │     parentData: <none> (can use size)\n'
      '                         │     constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         │     size: Size(800.0, 400.0)\n'
      '                         │     painter: _PlaceholderPainter#00000()\n'
      '                         │     preferredSize: Size(Infinity, Infinity)\n'
      '                         │\n'
      '                         └─child with index 2: RenderLimitedBox#00000 NEEDS-PAINT\n'
      '                           │ parentData: index=2; layoutOffset=800.0\n'
      '                           │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                           │ size: Size(800.0, 400.0)\n'
      '                           │ maxWidth: 400.0\n'
      '                           │ maxHeight: 400.0\n'
      '                           │\n'
      '                           └─child: RenderCustomPaint#00000 NEEDS-PAINT\n'
      '                               parentData: <none> (can use size)\n'
      '                               constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                               size: Size(800.0, 400.0)\n'
      '                               painter: _PlaceholderPainter#00000()\n'
      '                               preferredSize: Size(Infinity, Infinity)\n',
383
    ));
384
    const GlobalObjectKey<_LeafState>(0).currentState!.setKeepAlive(true);
385 386
    await tester.drag(find.byType(ListView), const Offset(0.0, -1000.0));
    await tester.pump();
387
    const GlobalObjectKey<_LeafState>(3).currentState!.setKeepAlive(true);
388 389
    await tester.drag(find.byType(ListView), const Offset(0.0, -1000.0));
    await tester.pump();
390
    expect(tester.binding.renderView.toStringDeep(minLevel: DiagnosticLevel.info), equalsIgnoringHashCodes(
391
      '_ReusableRenderView#00000\n'
392
      ' │ debug mode enabled - ${Platform.operatingSystem}\n'
393
      ' │ view size: Size(2400.0, 1800.0) (in physical pixels)\n'
394 395 396 397
      ' │ device pixel ratio: 3.0 (physical pixels per logical pixel)\n'
      ' │ configuration: Size(800.0, 600.0) at 3.0x (in logical pixels)\n'
      ' │\n'
      ' └─child: RenderRepaintBoundary#00000\n'
398
      '   │ needs compositing\n'
399 400 401 402 403 404 405 406 407
      '   │ parentData: <none>\n'
      '   │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '   │ layer: OffsetLayer#00000\n'
      '   │ size: Size(800.0, 600.0)\n'
      '   │ metrics: 0.0% useful (1 bad vs 0 good)\n'
      '   │ diagnosis: insufficient data to draw conclusion (less than five\n'
      '   │   repaints)\n'
      '   │\n'
      '   └─child: RenderCustomPaint#00000\n'
408
      '     │ needs compositing\n'
409 410 411
      '     │ parentData: <none> (can use size)\n'
      '     │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '     │ size: Size(800.0, 600.0)\n'
Ian Hickson's avatar
Ian Hickson committed
412 413 414 415 416
      '     │ painter: null\n'
      '     │ foregroundPainter:\n'
      '     │   _GlowingOverscrollIndicatorPainter(_GlowController(color:\n'
      '     │   Color(0xffffffff), axis: vertical), _GlowController(color:\n'
      '     │   Color(0xffffffff), axis: vertical))\n'
417 418
      '     │\n'
      '     └─child: RenderRepaintBoundary#00000\n'
419
      '       │ needs compositing\n'
420 421 422 423 424 425 426 427
      '       │ parentData: <none> (can use size)\n'
      '       │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '       │ layer: OffsetLayer#00000\n'
      '       │ size: Size(800.0, 600.0)\n'
      '       │ metrics: 0.0% useful (1 bad vs 0 good)\n'
      '       │ diagnosis: insufficient data to draw conclusion (less than five\n'
      '       │   repaints)\n'
      '       │\n'
Ian Hickson's avatar
Ian Hickson committed
428
      '       └─child: _RenderScrollSemantics#00000\n'
429
      '         │ needs compositing\n'
430 431
      '         │ parentData: <none> (can use size)\n'
      '         │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
432
      '         │ semantics node: SemanticsNode#1\n'
433
      '         │ semantic boundary\n'
434 435
      '         │ size: Size(800.0, 600.0)\n'
      '         │\n'
436
      '         └─child: RenderPointerListener#00000\n'
437
      '           │ needs compositing\n'
438 439 440
      '           │ parentData: <none> (can use size)\n'
      '           │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '           │ size: Size(800.0, 600.0)\n'
441 442
      '           │ behavior: deferToChild\n'
      '           │ listeners: signal\n'
443
      '           │\n'
444
      '           └─child: RenderSemanticsGestureHandler#00000\n'
445
      '             │ needs compositing\n'
446 447 448
      '             │ parentData: <none> (can use size)\n'
      '             │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '             │ size: Size(800.0, 600.0)\n'
449
      '             │ behavior: opaque\n'
450
      '             │ gestures: vertical scroll\n'
451
      '             │\n'
452
      '             └─child: RenderPointerListener#00000\n'
453
      '               │ needs compositing\n'
454 455 456
      '               │ parentData: <none> (can use size)\n'
      '               │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '               │ size: Size(800.0, 600.0)\n'
457
      '               │ behavior: opaque\n'
458
      '               │ listeners: down, panZoomStart\n'
459
      '               │\n'
460
      '               └─child: RenderSemanticsAnnotations#00000\n'
461
      '                 │ needs compositing\n'
462 463 464
      '                 │ parentData: <none> (can use size)\n'
      '                 │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '                 │ size: Size(800.0, 600.0)\n'
465
      '                 │\n'
466
      '                 └─child: RenderIgnorePointer#00000\n'
467
      '                   │ needs compositing\n'
468 469 470
      '                   │ parentData: <none> (can use size)\n'
      '                   │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '                   │ size: Size(800.0, 600.0)\n'
471
      '                   │ ignoring: false\n'
472
      '                   │ ignoringSemantics: null\n'
473
      '                   │\n'
474
      '                   └─child: RenderViewport#00000\n'
475
      '                     │ needs compositing\n'
476 477 478 479 480 481 482 483
      '                     │ parentData: <none> (can use size)\n'
      '                     │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '                     │ layer: OffsetLayer#00000\n'
      '                     │ size: Size(800.0, 600.0)\n'
      '                     │ axisDirection: down\n'
      '                     │ crossAxisDirection: right\n'
      '                     │ offset: ScrollPositionWithSingleContext#00000(offset: 2000.0,\n'
      '                     │   range: 0.0..39400.0, viewport: 600.0, ScrollableState,\n'
484 485 486
      '                     │   AlwaysScrollableScrollPhysics -> ClampingScrollPhysics ->\n'
      '                     │   RangeMaintainingScrollPhysics, IdleScrollActivity#00000,\n'
      '                     │   ScrollDirection.idle)\n'
487
      '                     │ anchor: 0.0\n'
488
      '                     │\n'
489
      '                     └─center child: RenderSliverPadding#00000 relayoutBoundary=up1\n'
490 491 492 493 494
      '                       │ parentData: paintOffset=Offset(0.0, 0.0) (can use size)\n'
      '                       │ constraints: SliverConstraints(AxisDirection.down,\n'
      '                       │   GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
      '                       │   2000.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n'
      '                       │   crossAxisDirection: AxisDirection.right,\n'
495 496
      '                       │   viewportMainAxisExtent: 600.0, remainingCacheExtent: 1100.0,\n'
      '                       │   cacheOrigin: -250.0)\n'
497 498 499
      '                       │ geometry: SliverGeometry(scrollExtent: 40000.0, paintExtent:\n'
      '                       │   600.0, maxPaintExtent: 40000.0, hasVisualOverflow: true,\n'
      '                       │   cacheExtent: 1100.0)\n'
500 501
      '                       │ padding: EdgeInsets.zero\n'
      '                       │ textDirection: ltr\n'
502
      '                       │\n'
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
      '                       └─child: RenderSliverFixedExtentList#00000 relayoutBoundary=up2\n'
      '                         │ parentData: paintOffset=Offset(0.0, 0.0) (can use size)\n'
      '                         │ constraints: SliverConstraints(AxisDirection.down,\n'
      '                         │   GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
      '                         │   2000.0, remainingPaintExtent: 600.0, crossAxisExtent: 800.0,\n'
      '                         │   crossAxisDirection: AxisDirection.right,\n'
      '                         │   viewportMainAxisExtent: 600.0, remainingCacheExtent: 1100.0,\n'
      '                         │   cacheOrigin: -250.0)\n'
      '                         │ geometry: SliverGeometry(scrollExtent: 40000.0, paintExtent:\n'
      '                         │   600.0, maxPaintExtent: 40000.0, hasVisualOverflow: true,\n'
      '                         │   cacheExtent: 1100.0)\n'
      '                         │ currently live children: 4 to 7\n'
      '                         │\n'
      '                         ├─child with index 4: RenderLimitedBox#00000 NEEDS-PAINT\n'
      '                         │ │ parentData: index=4; layoutOffset=1600.0\n'
      '                         │ │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         │ │ size: Size(800.0, 400.0)\n'
      '                         │ │ maxWidth: 400.0\n'
      '                         │ │ maxHeight: 400.0\n'
      '                         │ │\n'
      '                         │ └─child: RenderCustomPaint#00000 NEEDS-PAINT\n'
      '                         │     parentData: <none> (can use size)\n'
      '                         │     constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         │     size: Size(800.0, 400.0)\n'
      '                         │     painter: _PlaceholderPainter#00000()\n'
      '                         │     preferredSize: Size(Infinity, Infinity)\n'
      '                         │\n'
      '                         ├─child with index 5: RenderLimitedBox#00000\n'                                     // <----- this is index 5, not 0
      '                         │ │ parentData: index=5; layoutOffset=2000.0\n'
      '                         │ │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         │ │ size: Size(800.0, 400.0)\n'
      '                         │ │ maxWidth: 400.0\n'
      '                         │ │ maxHeight: 400.0\n'
      '                         │ │\n'
      '                         │ └─child: RenderCustomPaint#00000\n'
      '                         │     parentData: <none> (can use size)\n'
      '                         │     constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         │     size: Size(800.0, 400.0)\n'
      '                         │     painter: _PlaceholderPainter#00000()\n'
      '                         │     preferredSize: Size(Infinity, Infinity)\n'
543
      '                         │\n'
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
      '                         ├─child with index 6: RenderLimitedBox#00000\n'
      '                         │ │ parentData: index=6; layoutOffset=2400.0\n'
      '                         │ │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         │ │ size: Size(800.0, 400.0)\n'
      '                         │ │ maxWidth: 400.0\n'
      '                         │ │ maxHeight: 400.0\n'
      '                         │ │\n'
      '                         │ └─child: RenderCustomPaint#00000\n'
      '                         │     parentData: <none> (can use size)\n'
      '                         │     constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         │     size: Size(800.0, 400.0)\n'
      '                         │     painter: _PlaceholderPainter#00000()\n'
      '                         │     preferredSize: Size(Infinity, Infinity)\n'
      '                         │\n'
      '                         ├─child with index 7: RenderLimitedBox#00000 NEEDS-PAINT\n'
      '                         ╎ │ parentData: index=7; layoutOffset=2800.0\n'
      '                         ╎ │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         ╎ │ size: Size(800.0, 400.0)\n'
      '                         ╎ │ maxWidth: 400.0\n'
      '                         ╎ │ maxHeight: 400.0\n'
      '                         ╎ │\n'
      '                         ╎ └─child: RenderCustomPaint#00000 NEEDS-PAINT\n'
      '                         ╎     parentData: <none> (can use size)\n'
      '                         ╎     constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         ╎     size: Size(800.0, 400.0)\n'
      '                         ╎     painter: _PlaceholderPainter#00000()\n'
      '                         ╎     preferredSize: Size(Infinity, Infinity)\n'
      '                         ╎\n'
      '                         ╎╌child with index 0 (kept alive but not laid out): RenderLimitedBox#00000\n'               // <----- this one is index 0 and is marked as being kept alive but not laid out
      '                         ╎ │ parentData: index=0; keepAlive; layoutOffset=0.0\n'
      '                         ╎ │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         ╎ │ size: Size(800.0, 400.0)\n'
      '                         ╎ │ maxWidth: 400.0\n'
      '                         ╎ │ maxHeight: 400.0\n'
      '                         ╎ │\n'
      '                         ╎ └─child: RenderCustomPaint#00000\n'
      '                         ╎     parentData: <none> (can use size)\n'
      '                         ╎     constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                         ╎     size: Size(800.0, 400.0)\n'
      '                         ╎     painter: _PlaceholderPainter#00000()\n'
      '                         ╎     preferredSize: Size(Infinity, Infinity)\n'
      '                         ╎\n'
      '                         └╌child with index 3 (kept alive but not laid out): RenderLimitedBox#00000\n'
      '                           │ parentData: index=3; keepAlive; layoutOffset=1200.0\n'
      '                           │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                           │ size: Size(800.0, 400.0)\n'
      '                           │ maxWidth: 400.0\n'
      '                           │ maxHeight: 400.0\n'
      '                           │\n'
      '                           └─child: RenderCustomPaint#00000\n'
      '                               parentData: <none> (can use size)\n'
      '                               constraints: BoxConstraints(w=800.0, h=400.0)\n'
      '                               size: Size(800.0, 400.0)\n'
      '                               painter: _PlaceholderPainter#00000()\n'
      '                               preferredSize: Size(Infinity, Infinity)\n',
599
    ));
600
  }, skip: kIsWeb); // https://github.com/flutter/flutter/issues/87876
601
}