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

5
import 'package:flutter/material.dart';
Adam Barth's avatar
Adam Barth committed
6
import 'package:flutter/rendering.dart';
7
import 'package:flutter_test/flutter_test.dart';
8
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
Adam Barth's avatar
Adam Barth committed
9

10 11
void verify(WidgetTester tester, List<Offset> answerKey) {
  final List<Offset> testAnswers = tester.renderObjectList<RenderBox>(find.byType(SizedBox)).map<Offset>(
12
    (RenderBox target) => target.localToGlobal(Offset.zero),
Adam Barth's avatar
Adam Barth committed
13 14 15 16 17
  ).toList();
  expect(testAnswers, equals(answerKey));
}

void main() {
18
  testWidgetsWithLeakTracking('Basic Wrap test (LTR)', (WidgetTester tester) async {
Adam Barth's avatar
Adam Barth committed
19
    await tester.pumpWidget(
20
      const Wrap(
21
        textDirection: TextDirection.ltr,
22
        children: <Widget>[
23 24 25 26
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
Adam Barth's avatar
Adam Barth committed
27 28 29
        ],
      ),
    );
30
    verify(tester, <Offset>[
31
      Offset.zero,
32 33 34
      const Offset(300.0, 0.0),
      const Offset(0.0, 100.0),
      const Offset(300.0, 100.0),
Adam Barth's avatar
Adam Barth committed
35 36 37
    ]);

    await tester.pumpWidget(
38
      const Wrap(
Adam Barth's avatar
Adam Barth committed
39
        alignment: WrapAlignment.center,
40
        textDirection: TextDirection.ltr,
41
        children: <Widget>[
42 43 44 45
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
Adam Barth's avatar
Adam Barth committed
46 47 48
        ],
      ),
    );
49 50 51 52 53
    verify(tester, <Offset>[
      const Offset(100.0, 0.0),
      const Offset(400.0, 0.0),
      const Offset(100.0, 100.0),
      const Offset(400.0, 100.0),
Adam Barth's avatar
Adam Barth committed
54 55 56
    ]);

    await tester.pumpWidget(
57
      const Wrap(
Adam Barth's avatar
Adam Barth committed
58
        alignment: WrapAlignment.end,
59
        textDirection: TextDirection.ltr,
60
        children: <Widget>[
61 62 63 64
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
Adam Barth's avatar
Adam Barth committed
65 66 67
        ],
      ),
    );
68 69 70 71 72
    verify(tester, <Offset>[
      const Offset(200.0, 0.0),
      const Offset(500.0, 0.0),
      const Offset(200.0, 100.0),
      const Offset(500.0, 100.0),
Adam Barth's avatar
Adam Barth committed
73 74 75
    ]);

    await tester.pumpWidget(
76
      const Wrap(
77
        textDirection: TextDirection.ltr,
78
        children: <Widget>[
79 80 81 82
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
Adam Barth's avatar
Adam Barth committed
83 84 85
        ],
      ),
    );
86
    verify(tester, <Offset>[
87
      Offset.zero,
88 89 90
      const Offset(300.0, 0.0),
      const Offset(0.0, 100.0),
      const Offset(300.0, 100.0),
Adam Barth's avatar
Adam Barth committed
91 92 93
    ]);

    await tester.pumpWidget(
94
      const Wrap(
Adam Barth's avatar
Adam Barth committed
95
        crossAxisAlignment: WrapCrossAlignment.center,
96
        textDirection: TextDirection.ltr,
97
        children: <Widget>[
98 99 100 101
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
Adam Barth's avatar
Adam Barth committed
102 103 104
        ],
      ),
    );
105 106 107 108 109
    verify(tester, <Offset>[
      const Offset(0.0, 25.0),
      const Offset(300.0, 0.0),
      const Offset(0.0, 100.0),
      const Offset(300.0, 125.0),
Adam Barth's avatar
Adam Barth committed
110 111 112
    ]);

    await tester.pumpWidget(
113
      const Wrap(
Adam Barth's avatar
Adam Barth committed
114
        crossAxisAlignment: WrapCrossAlignment.end,
115
        textDirection: TextDirection.ltr,
116
        children: <Widget>[
117 118 119 120
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
Adam Barth's avatar
Adam Barth committed
121 122 123
        ],
      ),
    );
124 125 126 127 128
    verify(tester, <Offset>[
      const Offset(0.0, 50.0),
      const Offset(300.0, 0.0),
      const Offset(0.0, 100.0),
      const Offset(300.0, 150.0),
Adam Barth's avatar
Adam Barth committed
129 130 131 132
    ]);

  });

133
  testWidgetsWithLeakTracking('Basic Wrap test (RTL)', (WidgetTester tester) async {
134
    await tester.pumpWidget(
135
      const Wrap(
136
        textDirection: TextDirection.rtl,
137
        children: <Widget>[
138 139 140 141
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
142 143 144 145 146 147 148 149 150 151 152
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(500.0, 0.0),
      const Offset(200.0, 0.0),
      const Offset(500.0, 100.0),
      const Offset(200.0, 100.0),
    ]);

    await tester.pumpWidget(
153
      const Wrap(
154 155
        alignment: WrapAlignment.center,
        textDirection: TextDirection.rtl,
156
        children: <Widget>[
157 158 159 160
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
161 162 163 164 165 166 167 168 169 170 171
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(400.0, 0.0),
      const Offset(100.0, 0.0),
      const Offset(400.0, 100.0),
      const Offset(100.0, 100.0),
    ]);

    await tester.pumpWidget(
172
      const Wrap(
173 174
        alignment: WrapAlignment.end,
        textDirection: TextDirection.rtl,
175
        children: <Widget>[
176 177 178 179
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
180 181 182 183 184
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(300.0, 0.0),
185
      Offset.zero,
186 187 188 189 190
      const Offset(300.0, 100.0),
      const Offset(0.0, 100.0),
    ]);

    await tester.pumpWidget(
191
      const Wrap(
192 193
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
194
        children: <Widget>[
195 196 197 198
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
199 200 201 202 203 204 205 206 207 208 209
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(0.0, 550.0),
      const Offset(300.0, 500.0),
      const Offset(0.0, 400.0),
      const Offset(300.0, 450.0),
    ]);

    await tester.pumpWidget(
210
      const Wrap(
211 212 213
        crossAxisAlignment: WrapCrossAlignment.center,
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
214
        children: <Widget>[
215 216 217 218
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
219 220 221 222 223 224 225 226 227 228 229
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(0.0, 525.0),
      const Offset(300.0, 500.0),
      const Offset(0.0, 400.0),
      const Offset(300.0, 425.0),
    ]);

    await tester.pumpWidget(
230
      const Wrap(
231 232 233
        crossAxisAlignment: WrapCrossAlignment.end,
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
234
        children: <Widget>[
235 236 237 238
          SizedBox(width: 300.0, height: 50.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 100.0),
          SizedBox(width: 300.0, height: 50.0),
239 240 241 242 243 244 245 246 247 248 249 250
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(0.0, 500.0),
      const Offset(300.0, 500.0),
      const Offset(0.0, 400.0),
      const Offset(300.0, 400.0),
    ]);

  });

251
  testWidgetsWithLeakTracking('Empty wrap', (WidgetTester tester) async {
252
    await tester.pumpWidget(const Center(child: Wrap(alignment: WrapAlignment.center)));
Adam Barth's avatar
Adam Barth committed
253 254 255
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(Size.zero));
  });

256
  testWidgetsWithLeakTracking('Wrap alignment (LTR)', (WidgetTester tester) async {
257
    await tester.pumpWidget(const Wrap(
Adam Barth's avatar
Adam Barth committed
258 259
      alignment: WrapAlignment.center,
      spacing: 5.0,
260
      textDirection: TextDirection.ltr,
261
      children: <Widget>[
262 263 264
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
Adam Barth's avatar
Adam Barth committed
265 266 267
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
268 269 270 271
    verify(tester, <Offset>[
      const Offset(95.0, 0.0),
      const Offset(200.0, 0.0),
      const Offset(405.0, 0.0),
Adam Barth's avatar
Adam Barth committed
272 273
    ]);

274
    await tester.pumpWidget(const Wrap(
Adam Barth's avatar
Adam Barth committed
275 276
      alignment: WrapAlignment.spaceBetween,
      spacing: 5.0,
277
      textDirection: TextDirection.ltr,
278
      children: <Widget>[
279 280 281
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
Adam Barth's avatar
Adam Barth committed
282 283 284
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
285
    verify(tester, <Offset>[
286
      Offset.zero,
287 288
      const Offset(200.0, 0.0),
      const Offset(500.0, 0.0),
Adam Barth's avatar
Adam Barth committed
289 290
    ]);

291
    await tester.pumpWidget(const Wrap(
Adam Barth's avatar
Adam Barth committed
292 293
      alignment: WrapAlignment.spaceAround,
      spacing: 5.0,
294
      textDirection: TextDirection.ltr,
295
      children: <Widget>[
296 297 298
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
Adam Barth's avatar
Adam Barth committed
299 300 301
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
302 303 304 305
    verify(tester, <Offset>[
      const Offset(30.0, 0.0),
      const Offset(195.0, 0.0),
      const Offset(460.0, 0.0),
Adam Barth's avatar
Adam Barth committed
306 307
    ]);

308
    await tester.pumpWidget(const Wrap(
Adam Barth's avatar
Adam Barth committed
309 310
      alignment: WrapAlignment.spaceEvenly,
      spacing: 5.0,
311
      textDirection: TextDirection.ltr,
312
      children: <Widget>[
313 314 315
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
Adam Barth's avatar
Adam Barth committed
316 317 318
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
319 320 321 322
    verify(tester, <Offset>[
      const Offset(45.0, 0.0),
      const Offset(195.0, 0.0),
      const Offset(445.0, 0.0),
Adam Barth's avatar
Adam Barth committed
323 324 325
    ]);
  });

326
  testWidgetsWithLeakTracking('Wrap alignment (RTL)', (WidgetTester tester) async {
327
    await tester.pumpWidget(const Wrap(
328 329 330
      alignment: WrapAlignment.center,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
331
      children: <Widget>[
332 333 334
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
335 336 337 338 339 340 341 342 343
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(605.0, 0.0),
      const Offset(400.0, 0.0),
      const Offset(95.0, 0.0),
    ]);

344
    await tester.pumpWidget(const Wrap(
345 346 347
      alignment: WrapAlignment.spaceBetween,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
348
      children: <Widget>[
349 350 351
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
352 353 354 355 356 357
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(700.0, 0.0),
      const Offset(400.0, 0.0),
358
      Offset.zero,
359 360
    ]);

361
    await tester.pumpWidget(const Wrap(
362 363 364
      alignment: WrapAlignment.spaceAround,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
365
      children: <Widget>[
366 367 368
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
369 370 371 372 373 374 375 376 377
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(670.0, 0.0),
      const Offset(405.0, 0.0),
      const Offset(30.0, 0.0),
    ]);

378
    await tester.pumpWidget(const Wrap(
379 380 381
      alignment: WrapAlignment.spaceEvenly,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
382
      children: <Widget>[
383 384 385
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
386 387 388 389 390 391 392 393 394 395
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(655.0, 0.0),
      const Offset(405.0, 0.0),
      const Offset(45.0, 0.0),
    ]);
  });

396
  testWidgetsWithLeakTracking('Wrap runAlignment (DOWN)', (WidgetTester tester) async {
397
    await tester.pumpWidget(const Wrap(
Adam Barth's avatar
Adam Barth committed
398 399
      runAlignment: WrapAlignment.center,
      runSpacing: 5.0,
400
      textDirection: TextDirection.ltr,
401
      children: <Widget>[
402 403 404 405 406
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
Adam Barth's avatar
Adam Barth committed
407 408 409
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
410 411 412 413 414 415
    verify(tester, <Offset>[
      const Offset(0.0, 230.0),
      const Offset(100.0, 230.0),
      const Offset(300.0, 230.0),
      const Offset(0.0, 265.0),
      const Offset(0.0, 310.0),
Adam Barth's avatar
Adam Barth committed
416 417
    ]);

418
    await tester.pumpWidget(const Wrap(
Adam Barth's avatar
Adam Barth committed
419 420
      runAlignment: WrapAlignment.spaceBetween,
      runSpacing: 5.0,
421
      textDirection: TextDirection.ltr,
422
      children: <Widget>[
423 424 425 426 427
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
Adam Barth's avatar
Adam Barth committed
428 429 430
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
431
    verify(tester, <Offset>[
432
      Offset.zero,
433 434 435 436
      const Offset(100.0, 0.0),
      const Offset(300.0, 0.0),
      const Offset(0.0, 265.0),
      const Offset(0.0, 540.0),
Adam Barth's avatar
Adam Barth committed
437 438
    ]);

439
    await tester.pumpWidget(const Wrap(
Adam Barth's avatar
Adam Barth committed
440 441
      runAlignment: WrapAlignment.spaceAround,
      runSpacing: 5.0,
442
      textDirection: TextDirection.ltr,
443
      children: <Widget>[
444 445 446 447 448
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 70.0),
Adam Barth's avatar
Adam Barth committed
449 450 451
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
452 453 454 455 456 457
    verify(tester, <Offset>[
      const Offset(0.0, 75.0),
      const Offset(100.0, 75.0),
      const Offset(300.0, 75.0),
      const Offset(0.0, 260.0),
      const Offset(0.0, 455.0),
Adam Barth's avatar
Adam Barth committed
458 459
    ]);

460
    await tester.pumpWidget(const Wrap(
Adam Barth's avatar
Adam Barth committed
461 462
      runAlignment: WrapAlignment.spaceEvenly,
      runSpacing: 5.0,
463
      textDirection: TextDirection.ltr,
464
      children: <Widget>[
465 466 467 468 469
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
Adam Barth's avatar
Adam Barth committed
470 471 472
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
473 474 475 476 477 478
    verify(tester, <Offset>[
      const Offset(0.0, 115.0),
      const Offset(100.0, 115.0),
      const Offset(300.0, 115.0),
      const Offset(0.0, 265.0),
      const Offset(0.0, 425.0),
Adam Barth's avatar
Adam Barth committed
479 480 481 482
    ]);

  });

483
  testWidgetsWithLeakTracking('Wrap runAlignment (UP)', (WidgetTester tester) async {
484
    await tester.pumpWidget(const Wrap(
485 486 487 488
      runAlignment: WrapAlignment.center,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
489
      children: <Widget>[
490 491 492 493 494
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
495 496 497 498 499 500 501 502 503 504 505
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 360.0),
      const Offset(100.0, 350.0),
      const Offset(300.0, 340.0),
      const Offset(0.0, 295.0),
      const Offset(0.0, 230.0),
    ]);

506
    await tester.pumpWidget(const Wrap(
507 508 509 510
      runAlignment: WrapAlignment.spaceBetween,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
511
      children: <Widget>[
512 513 514 515 516
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
517 518 519 520 521 522 523 524
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 590.0),
      const Offset(100.0, 580.0),
      const Offset(300.0, 570.0),
      const Offset(0.0, 295.0),
525
      Offset.zero,
526 527
    ]);

528
    await tester.pumpWidget(const Wrap(
529 530 531 532
      runAlignment: WrapAlignment.spaceAround,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
533
      children: <Widget>[
534 535 536 537 538
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 70.0),
539 540 541 542 543 544 545 546 547 548 549
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 515.0),
      const Offset(100.0, 505.0),
      const Offset(300.0, 495.0),
      const Offset(0.0, 300.0),
      const Offset(0.0, 75.0),
    ]);

550
    await tester.pumpWidget(const Wrap(
551 552 553 554
      runAlignment: WrapAlignment.spaceEvenly,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
555
      children: <Widget>[
556 557 558 559 560
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
        SizedBox(width: 400.0, height: 40.0),
        SizedBox(width: 500.0, height: 60.0),
561 562 563 564 565 566 567 568 569 570 571 572 573
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 475.0),
      const Offset(100.0, 465.0),
      const Offset(300.0, 455.0),
      const Offset(0.0, 295.0),
      const Offset(0.0, 115.0),
    ]);

  });

574
  testWidgetsWithLeakTracking('Shrink-wrapping Wrap test', (WidgetTester tester) async {
Adam Barth's avatar
Adam Barth committed
575
    await tester.pumpWidget(
576
      const Align(
577
        alignment: Alignment.topLeft,
578
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
579 580
          alignment: WrapAlignment.end,
          crossAxisAlignment: WrapCrossAlignment.end,
581
          textDirection: TextDirection.ltr,
582
          children: <Widget>[
583 584 585 586
            SizedBox(width: 100.0, height: 10.0),
            SizedBox(width: 200.0, height: 20.0),
            SizedBox(width: 300.0, height: 30.0),
            SizedBox(width: 400.0, height: 40.0),
Adam Barth's avatar
Adam Barth committed
587 588 589 590 591
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(600.0, 70.0)));
592 593 594 595 596
    verify(tester, <Offset>[
      const Offset(0.0, 20.0),
      const Offset(100.0, 10.0),
      const Offset(300.0, 0.0),
      const Offset(200.0, 30.0),
Adam Barth's avatar
Adam Barth committed
597 598 599
    ]);

    await tester.pumpWidget(
600
      const Align(
601
        alignment: Alignment.topLeft,
602
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
603 604
          alignment: WrapAlignment.end,
          crossAxisAlignment: WrapCrossAlignment.end,
605
          textDirection: TextDirection.ltr,
606
          children: <Widget>[
607 608 609 610
            SizedBox(width: 400.0, height: 40.0),
            SizedBox(width: 300.0, height: 30.0),
            SizedBox(width: 200.0, height: 20.0),
            SizedBox(width: 100.0, height: 10.0),
Adam Barth's avatar
Adam Barth committed
611 612 613 614 615
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(700.0, 60.0)));
616
    verify(tester, <Offset>[
617
      Offset.zero,
618 619 620
      const Offset(400.0, 10.0),
      const Offset(400.0, 40.0),
      const Offset(600.0, 50.0),
Adam Barth's avatar
Adam Barth committed
621 622 623
    ]);
  });

624
  testWidgetsWithLeakTracking('Wrap spacing test', (WidgetTester tester) async {
Adam Barth's avatar
Adam Barth committed
625
    await tester.pumpWidget(
626
      const Align(
627
        alignment: Alignment.topLeft,
628
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
629
          runSpacing: 10.0,
630
          textDirection: TextDirection.ltr,
631
          children: <Widget>[
632 633 634 635
            SizedBox(width: 500.0, height: 10.0),
            SizedBox(width: 500.0, height: 20.0),
            SizedBox(width: 500.0, height: 30.0),
            SizedBox(width: 500.0, height: 40.0),
Adam Barth's avatar
Adam Barth committed
636 637 638 639 640
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(500.0, 130.0)));
641
    verify(tester, <Offset>[
642
      Offset.zero,
643 644 645
      const Offset(0.0, 20.0),
      const Offset(0.0, 50.0),
      const Offset(0.0, 90.0),
Adam Barth's avatar
Adam Barth committed
646 647 648
    ]);
  });

649
  testWidgetsWithLeakTracking('Vertical Wrap test with spacing', (WidgetTester tester) async {
Adam Barth's avatar
Adam Barth committed
650
    await tester.pumpWidget(
651
      const Align(
652
        alignment: Alignment.topLeft,
653
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
654 655 656
          direction: Axis.vertical,
          spacing: 10.0,
          runSpacing: 15.0,
657
          textDirection: TextDirection.ltr,
658
          children: <Widget>[
659 660 661 662 663 664
            SizedBox(width: 10.0, height: 250.0),
            SizedBox(width: 20.0, height: 250.0),
            SizedBox(width: 30.0, height: 250.0),
            SizedBox(width: 40.0, height: 250.0),
            SizedBox(width: 50.0, height: 250.0),
            SizedBox(width: 60.0, height: 250.0),
Adam Barth's avatar
Adam Barth committed
665 666 667 668 669
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(150.0, 510.0)));
670
    verify(tester, <Offset>[
671
      Offset.zero,
672 673 674 675 676
      const Offset(0.0, 260.0),
      const Offset(35.0, 0.0),
      const Offset(35.0, 260.0),
      const Offset(90.0, 0.0),
      const Offset(90.0, 260.0),
Adam Barth's avatar
Adam Barth committed
677 678 679
    ]);

    await tester.pumpWidget(
680
      const Align(
681
        alignment: Alignment.topLeft,
682
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
683 684
          spacing: 12.0,
          runSpacing: 8.0,
685
          textDirection: TextDirection.ltr,
686
          children: <Widget>[
687 688 689 690 691 692
            SizedBox(width: 10.0, height: 250.0),
            SizedBox(width: 20.0, height: 250.0),
            SizedBox(width: 30.0, height: 250.0),
            SizedBox(width: 40.0, height: 250.0),
            SizedBox(width: 50.0, height: 250.0),
            SizedBox(width: 60.0, height: 250.0),
Adam Barth's avatar
Adam Barth committed
693 694 695 696
          ],
        ),
      ),
    );
697
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(270.0, 250.0)));
698
    verify(tester, <Offset>[
699
      Offset.zero,
700 701 702 703 704
      const Offset(22.0, 0.0),
      const Offset(54.0, 0.0),
      const Offset(96.0, 0.0),
      const Offset(148.0, 0.0),
      const Offset(210.0, 0.0),
Adam Barth's avatar
Adam Barth committed
705 706 707
    ]);
  });

708
  testWidgetsWithLeakTracking('Visual overflow generates a clip', (WidgetTester tester) async {
709
    await tester.pumpWidget(const Wrap(
710
      textDirection: TextDirection.ltr,
711
      children: <Widget>[
712
        SizedBox(width: 500.0, height: 500.0),
Adam Barth's avatar
Adam Barth committed
713 714 715 716 717
      ],
    ));

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)), isNot(paints..clipRect()));

718
    await tester.pumpWidget(const Wrap(
719
      textDirection: TextDirection.ltr,
720
      clipBehavior: Clip.hardEdge,
721
      children: <Widget>[
722 723
        SizedBox(width: 500.0, height: 500.0),
        SizedBox(width: 500.0, height: 500.0),
Adam Barth's avatar
Adam Barth committed
724 725 726 727 728 729
      ],
    ));

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)), paints..clipRect());
  });

730
  testWidgetsWithLeakTracking('Hit test children in wrap', (WidgetTester tester) async {
Adam Barth's avatar
Adam Barth committed
731 732
    final List<String> log = <String>[];

733
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
734 735
      spacing: 10.0,
      runSpacing: 15.0,
736
      textDirection: TextDirection.ltr,
Adam Barth's avatar
Adam Barth committed
737
      children: <Widget>[
738 739 740 741
        const SizedBox(width: 200.0, height: 300.0),
        const SizedBox(width: 200.0, height: 300.0),
        const SizedBox(width: 200.0, height: 300.0),
        const SizedBox(width: 200.0, height: 300.0),
742
        SizedBox(
Adam Barth's avatar
Adam Barth committed
743 744
          width: 200.0,
          height: 300.0,
745
          child: GestureDetector(
Adam Barth's avatar
Adam Barth committed
746 747 748 749 750 751 752
            behavior: HitTestBehavior.opaque,
            onTap: () { log.add('hit'); },
          ),
        ),
      ],
    ));

753
    await tester.tapAt(const Offset(209.0, 314.0));
Adam Barth's avatar
Adam Barth committed
754 755
    expect(log, isEmpty);

756
    await tester.tapAt(const Offset(211.0, 314.0));
Adam Barth's avatar
Adam Barth committed
757 758
    expect(log, isEmpty);

759
    await tester.tapAt(const Offset(209.0, 316.0));
Adam Barth's avatar
Adam Barth committed
760 761
    expect(log, isEmpty);

762
    await tester.tapAt(const Offset(211.0, 316.0));
Adam Barth's avatar
Adam Barth committed
763 764 765
    expect(log, equals(<String>['hit']));
  });

766
  testWidgetsWithLeakTracking('RenderWrap toStringShallow control test', (WidgetTester tester) async {
767
    await tester.pumpWidget(const Wrap(alignment: WrapAlignment.center));
Adam Barth's avatar
Adam Barth committed
768 769 770 771 772

    final RenderBox wrap = tester.renderObject(find.byType(Wrap));
    expect(wrap.toStringShallow(), hasOneLineDescription);
  });

773
  testWidgetsWithLeakTracking('RenderWrap toString control test', (WidgetTester tester) async {
774
    await tester.pumpWidget(const Wrap(
Adam Barth's avatar
Adam Barth committed
775 776
      direction: Axis.vertical,
      runSpacing: 7.0,
777
      textDirection: TextDirection.ltr,
778
      children: <Widget>[
779 780 781 782
        SizedBox(width: 500.0, height: 400.0),
        SizedBox(width: 500.0, height: 400.0),
        SizedBox(width: 500.0, height: 400.0),
        SizedBox(width: 500.0, height: 400.0),
Adam Barth's avatar
Adam Barth committed
783 784 785 786 787 788 789 790
      ],
    ));

    final RenderBox wrap = tester.renderObject(find.byType(Wrap));
    final double width = wrap.getMinIntrinsicWidth(600.0);
    expect(width, equals(2021));
  });

791
  testWidgetsWithLeakTracking('Wrap baseline control test', (WidgetTester tester) async {
Adam Barth's avatar
Adam Barth committed
792
    await tester.pumpWidget(
793
      const Center(
794
        child: Baseline(
795
          baseline: 175.0,
Adam Barth's avatar
Adam Barth committed
796
          baselineType: TextBaseline.alphabetic,
797
          child: DefaultTextStyle(
798
            style: TextStyle(
799
              fontFamily: 'FlutterTest',
Adam Barth's avatar
Adam Barth committed
800 801
              fontSize: 100.0,
            ),
802
            child: Wrap(
803
              textDirection: TextDirection.ltr,
804
              children: <Widget>[
805
                Text('X', textDirection: TextDirection.ltr),
Adam Barth's avatar
Adam Barth committed
806 807 808 809 810 811 812
              ],
            ),
          ),
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.text('X')).size, const Size(100.0, 100.0));
813 814
    expect(
      tester.renderObject<RenderBox>(find.byType(Baseline)).size,
815
      const Size(100.0, 200.0),
816
    );
817
  });
818

819
  testWidgetsWithLeakTracking('Spacing with slight overflow', (WidgetTester tester) async {
820
    await tester.pumpWidget(const Wrap(
821 822 823
      textDirection: TextDirection.ltr,
      spacing: 10.0,
      runSpacing: 10.0,
824
      children: <Widget>[
825 826 827 828
        SizedBox(width: 200.0, height: 10.0),
        SizedBox(width: 200.0, height: 10.0),
        SizedBox(width: 200.0, height: 10.0),
        SizedBox(width: 171.0, height: 10.0),
829 830 831 832 833
      ],
    ));

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
834
      Offset.zero,
835 836
      const Offset(210.0, 0.0),
      const Offset(420.0, 0.0),
837
      const Offset(0.0, 20.0),
838 839
    ]);
  });
840

841
  testWidgetsWithLeakTracking('Object exactly matches container width', (WidgetTester tester) async {
842
    await tester.pumpWidget(
843 844
      const Column(
        children: <Widget>[
845
          Wrap(
846 847 848
            textDirection: TextDirection.ltr,
            spacing: 10.0,
            runSpacing: 10.0,
849
            children: <Widget>[
850
              SizedBox(width: 800.0, height: 10.0),
851 852 853
            ],
          ),
        ],
854
      ),
855
    );
856

857
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 10.0)));
858
    verify(tester, <Offset>[Offset.zero]);
859 860

    await tester.pumpWidget(
861 862
      const Column(
        children: <Widget>[
863
          Wrap(
864 865 866
            textDirection: TextDirection.ltr,
            spacing: 10.0,
            runSpacing: 10.0,
867
            children: <Widget>[
868 869
              SizedBox(width: 800.0, height: 10.0),
              SizedBox(width: 800.0, height: 10.0),
870 871 872
            ],
          ),
        ],
873
      ),
874 875 876 877
    );

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 30.0)));
    verify(tester, <Offset>[
878
      Offset.zero,
879 880
      const Offset(0.0, 20.0),
    ]);
881
  });
882

883
  testWidgetsWithLeakTracking('Wrap can set and update clipBehavior', (WidgetTester tester) async {
884
    await tester.pumpWidget(const Wrap(textDirection: TextDirection.ltr));
885
    final RenderWrap renderObject = tester.allRenderObjects.whereType<RenderWrap>().first;
886
    expect(renderObject.clipBehavior, equals(Clip.none));
887

888
    await tester.pumpWidget(const Wrap(textDirection: TextDirection.ltr, clipBehavior: Clip.antiAlias));
889 890
    expect(renderObject.clipBehavior, equals(Clip.antiAlias));
  });
891

892
  testWidgetsWithLeakTracking('Horizontal wrap - IntrinsicsHeight', (WidgetTester tester) async {
893 894
    // Regression test for https://github.com/flutter/flutter/issues/48679.
    await tester.pumpWidget(
895
      const Directionality(
896 897 898
        textDirection: TextDirection.ltr,
        child: Center(
          child: IntrinsicHeight(
899
            child: ColoredBox(
900 901 902
              color: Colors.green,
              child: Wrap(
                children: <Widget>[
903
                  Text('Start', style: TextStyle(height: 1.0, fontSize: 16)),
904
                  Row(
905
                    children: <Widget>[
906 907 908
                      SizedBox(height: 40, width: 60),
                    ],
                  ),
909
                  Text('End', style: TextStyle(height: 1.0, fontSize: 16)),
910 911 912 913 914 915 916 917 918 919 920 921 922 923
                ],
              ),
            ),
          ),
        ),
      ),
    );

    // The row takes up the full width, therefore the "Start" and "End" text
    // are placed before and after it and the total height is the sum of the
    // individual heights.
    expect(tester.getSize(find.byType(IntrinsicHeight)).height, 2 * 16 + 40);
  });

924
  testWidgetsWithLeakTracking('Vertical wrap - IntrinsicsWidth', (WidgetTester tester) async {
925 926
    // Regression test for https://github.com/flutter/flutter/issues/48679.
    await tester.pumpWidget(
927
      const Directionality(
928 929 930
        textDirection: TextDirection.ltr,
        child: Center(
          child: IntrinsicWidth(
931
            child: ColoredBox(
932 933 934 935
              color: Colors.green,
              child: Wrap(
                direction: Axis.vertical,
                children: <Widget>[
936
                  Text('Start', style: TextStyle(height: 1.0, fontSize: 16)),
937
                  Column(
938
                    children: <Widget>[
939 940 941
                      SizedBox(height: 40, width: 60),
                    ],
                  ),
942
                  Text('End', style: TextStyle(height: 1.0, fontSize: 16)),
943 944 945 946 947 948 949 950 951 952 953 954 955
                ],
              ),
            ),
          ),
        ),
      ),
    );

    // The column takes up the full height, therefore the "Start" and "End" text
    // are placed to the left and right of it and the total width is the sum of
    // the individual widths.
    expect(tester.getSize(find.byType(IntrinsicWidth)).width, 5 * 16 + 60 + 3 * 16);
  });
Adam Barth's avatar
Adam Barth committed
956
}