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 11

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

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

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

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

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

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

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

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

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

201
  testWidgets('KeepAlive render tree description', (WidgetTester tester) async {
202
    await tester.pumpWidget(
203
      Directionality(
204
        textDirection: TextDirection.ltr,
205
        child: ListView(
206 207
          addAutomaticKeepAlives: false,
          addRepaintBoundaries: false,
208
          addSemanticIndexes: false,
209 210 211 212 213
          itemExtent: 400.0, // 2 visible children
          children: generateList(const Placeholder()),
        ),
      ),
    );
214
    // The important lines below are the ones marked with "<----"
215
    expect(tester.binding.renderView.toStringDeep(minLevel: DiagnosticLevel.info), equalsIgnoringHashCodes(
216
      '_ReusableRenderView#00000\n'
217
      ' │ debug mode enabled - ${Platform.operatingSystem}\n'
218
      ' │ view size: Size(2400.0, 1800.0) (in physical pixels)\n'
219
      ' │ device pixel ratio: 3.0 (physical pixels per logical pixel)\n'
220 221
      ' │ configuration: BoxConstraints(w=800.0, h=600.0) at 3.0x (in\n'
      ' │   logical pixels)\n'
222 223
      ' │\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
      '                       │ parentData: paintOffset=Offset(0.0, 0.0) (can use size)\n'
      '                       │ constraints: SliverConstraints(AxisDirection.down,\n'
      '                       │   GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
319 320 321 322
      '                       │   0.0, precedingScrollExtent: 0.0, remainingPaintExtent: 600.0,\n'
      '                       │   crossAxisExtent: 800.0, crossAxisDirection:\n'
      '                       │   AxisDirection.right, viewportMainAxisExtent: 600.0,\n'
      '                       │   remainingCacheExtent: 850.0, 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
      '                       └─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'
333 334 335 336
      '                         │   0.0, precedingScrollExtent: 0.0, remainingPaintExtent: 600.0,\n'
      '                         │   crossAxisExtent: 800.0, crossAxisDirection:\n'
      '                         │   AxisDirection.right, viewportMainAxisExtent: 600.0,\n'
      '                         │   remainingCacheExtent: 850.0, cacheOrigin: 0.0)\n'
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
      '                         │ 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
      ' │ device pixel ratio: 3.0 (physical pixels per logical pixel)\n'
395 396
      ' │ configuration: BoxConstraints(w=800.0, h=600.0) at 3.0x (in\n'
      ' │   logical pixels)\n'
397 398
      ' │\n'
      ' └─child: RenderRepaintBoundary#00000\n'
399
      '   │ needs compositing\n'
400 401 402 403 404 405 406 407 408
      '   │ 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'
409
      '     │ needs compositing\n'
410 411 412
      '     │ 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
413 414 415 416 417
      '     │ painter: null\n'
      '     │ foregroundPainter:\n'
      '     │   _GlowingOverscrollIndicatorPainter(_GlowController(color:\n'
      '     │   Color(0xffffffff), axis: vertical), _GlowController(color:\n'
      '     │   Color(0xffffffff), axis: vertical))\n'
418 419
      '     │\n'
      '     └─child: RenderRepaintBoundary#00000\n'
420
      '       │ needs compositing\n'
421 422 423 424 425 426 427 428
      '       │ 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
429
      '       └─child: _RenderScrollSemantics#00000\n'
430
      '         │ needs compositing\n'
431 432
      '         │ parentData: <none> (can use size)\n'
      '         │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
433
      '         │ semantics node: SemanticsNode#1\n'
434
      '         │ semantic boundary\n'
435 436
      '         │ size: Size(800.0, 600.0)\n'
      '         │\n'
437
      '         └─child: RenderPointerListener#00000\n'
438
      '           │ needs compositing\n'
439 440 441
      '           │ parentData: <none> (can use size)\n'
      '           │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '           │ size: Size(800.0, 600.0)\n'
442 443
      '           │ behavior: deferToChild\n'
      '           │ listeners: signal\n'
444
      '           │\n'
445
      '           └─child: RenderSemanticsGestureHandler#00000\n'
446
      '             │ needs compositing\n'
447 448 449
      '             │ parentData: <none> (can use size)\n'
      '             │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '             │ size: Size(800.0, 600.0)\n'
450
      '             │ behavior: opaque\n'
451
      '             │ gestures: vertical scroll\n'
452
      '             │\n'
453
      '             └─child: RenderPointerListener#00000\n'
454
      '               │ needs compositing\n'
455 456 457
      '               │ parentData: <none> (can use size)\n'
      '               │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '               │ size: Size(800.0, 600.0)\n'
458
      '               │ behavior: opaque\n'
459
      '               │ listeners: down, panZoomStart\n'
460
      '               │\n'
461
      '               └─child: RenderSemanticsAnnotations#00000\n'
462
      '                 │ needs compositing\n'
463 464 465
      '                 │ parentData: <none> (can use size)\n'
      '                 │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '                 │ size: Size(800.0, 600.0)\n'
466
      '                 │\n'
467
      '                 └─child: RenderIgnorePointer#00000\n'
468
      '                   │ needs compositing\n'
469 470 471
      '                   │ parentData: <none> (can use size)\n'
      '                   │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
      '                   │ size: Size(800.0, 600.0)\n'
472
      '                   │ ignoring: false\n'
473
      '                   │ ignoringSemantics: null\n'
474
      '                   │\n'
475
      '                   └─child: RenderViewport#00000\n'
476
      '                     │ needs compositing\n'
477 478 479 480 481 482 483 484
      '                     │ 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'
485 486 487
      '                     │   AlwaysScrollableScrollPhysics -> ClampingScrollPhysics ->\n'
      '                     │   RangeMaintainingScrollPhysics, IdleScrollActivity#00000,\n'
      '                     │   ScrollDirection.idle)\n'
488
      '                     │ anchor: 0.0\n'
489
      '                     │\n'
490
      '                     └─center child: RenderSliverPadding#00000 relayoutBoundary=up1\n'
491 492 493
      '                       │ parentData: paintOffset=Offset(0.0, 0.0) (can use size)\n'
      '                       │ constraints: SliverConstraints(AxisDirection.down,\n'
      '                       │   GrowthDirection.forward, ScrollDirection.idle, scrollOffset:\n'
494 495 496 497
      '                       │   2000.0, precedingScrollExtent: 0.0, remainingPaintExtent:\n'
      '                       │   600.0, crossAxisExtent: 800.0, crossAxisDirection:\n'
      '                       │   AxisDirection.right, viewportMainAxisExtent: 600.0,\n'
      '                       │   remainingCacheExtent: 1100.0, cacheOrigin: -250.0)\n'
498 499 500
      '                       │ geometry: SliverGeometry(scrollExtent: 40000.0, paintExtent:\n'
      '                       │   600.0, maxPaintExtent: 40000.0, hasVisualOverflow: true,\n'
      '                       │   cacheExtent: 1100.0)\n'
501 502
      '                       │ padding: EdgeInsets.zero\n'
      '                       │ textDirection: ltr\n'
503
      '                       │\n'
504 505 506 507
      '                       └─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'
508 509 510 511
      '                         │   2000.0, precedingScrollExtent: 0.0, remainingPaintExtent:\n'
      '                         │   600.0, crossAxisExtent: 800.0, crossAxisDirection:\n'
      '                         │   AxisDirection.right, viewportMainAxisExtent: 600.0,\n'
      '                         │   remainingCacheExtent: 1100.0, cacheOrigin: -250.0)\n'
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 543
      '                         │ 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'
544
      '                         │\n'
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 599
      '                         ├─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',
600
    ));
601
  }, skip: kIsWeb); // https://github.com/flutter/flutter/issues/87876
602
}