wrap_test.dart 30 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';
Adam Barth's avatar
Adam Barth committed
8 9 10

import '../rendering/mock_canvas.dart';

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

void main() {
19
  testWidgets('Basic Wrap test (LTR)', (WidgetTester tester) async {
Adam Barth's avatar
Adam Barth committed
20
    await tester.pumpWidget(
21
      Wrap(
22
        textDirection: TextDirection.ltr,
23
        children: const <Widget>[
24 25 26 27
          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
28 29 30
        ],
      ),
    );
31
    verify(tester, <Offset>[
32
      Offset.zero,
33 34 35
      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
36 37 38
    ]);

    await tester.pumpWidget(
39
      Wrap(
Adam Barth's avatar
Adam Barth committed
40
        alignment: WrapAlignment.center,
41
        textDirection: TextDirection.ltr,
42
        children: const <Widget>[
43 44 45 46
          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
47 48 49
        ],
      ),
    );
50 51 52 53 54
    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
55 56 57
    ]);

    await tester.pumpWidget(
58
      Wrap(
Adam Barth's avatar
Adam Barth committed
59
        alignment: WrapAlignment.end,
60
        textDirection: TextDirection.ltr,
61
        children: const <Widget>[
62 63 64 65
          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
66 67 68
        ],
      ),
    );
69 70 71 72 73
    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
74 75 76
    ]);

    await tester.pumpWidget(
77
      Wrap(
78
        textDirection: TextDirection.ltr,
79
        children: const <Widget>[
80 81 82 83
          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
84 85 86
        ],
      ),
    );
87
    verify(tester, <Offset>[
88
      Offset.zero,
89 90 91
      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
92 93 94
    ]);

    await tester.pumpWidget(
95
      Wrap(
Adam Barth's avatar
Adam Barth committed
96
        crossAxisAlignment: WrapCrossAlignment.center,
97
        textDirection: TextDirection.ltr,
98
        children: const <Widget>[
99 100 101 102
          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
103 104 105
        ],
      ),
    );
106 107 108 109 110
    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
111 112 113
    ]);

    await tester.pumpWidget(
114
      Wrap(
Adam Barth's avatar
Adam Barth committed
115
        crossAxisAlignment: WrapCrossAlignment.end,
116
        textDirection: TextDirection.ltr,
117
        children: const <Widget>[
118 119 120 121
          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
122 123 124
        ],
      ),
    );
125 126 127 128 129
    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
130 131 132 133
    ]);

  });

134 135
  testWidgets('Basic Wrap test (RTL)', (WidgetTester tester) async {
    await tester.pumpWidget(
136
      Wrap(
137
        textDirection: TextDirection.rtl,
138
        children: const <Widget>[
139 140 141 142
          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),
143 144 145 146 147 148 149 150 151 152 153
        ],
      ),
    );
    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(
154
      Wrap(
155 156
        alignment: WrapAlignment.center,
        textDirection: TextDirection.rtl,
157
        children: const <Widget>[
158 159 160 161
          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),
162 163 164 165 166 167 168 169 170 171 172
        ],
      ),
    );
    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(
173
      Wrap(
174 175
        alignment: WrapAlignment.end,
        textDirection: TextDirection.rtl,
176
        children: const <Widget>[
177 178 179 180
          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),
181 182 183 184 185
        ],
      ),
    );
    verify(tester, <Offset>[
      const Offset(300.0, 0.0),
186
      Offset.zero,
187 188 189 190 191
      const Offset(300.0, 100.0),
      const Offset(0.0, 100.0),
    ]);

    await tester.pumpWidget(
192
      Wrap(
193 194
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
195
        children: const <Widget>[
196 197 198 199
          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),
200 201 202 203 204 205 206 207 208 209 210
        ],
      ),
    );
    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(
211
      Wrap(
212 213 214
        crossAxisAlignment: WrapCrossAlignment.center,
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
215
        children: const <Widget>[
216 217 218 219
          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),
220 221 222 223 224 225 226 227 228 229 230
        ],
      ),
    );
    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(
231
      Wrap(
232 233 234
        crossAxisAlignment: WrapCrossAlignment.end,
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
235
        children: const <Widget>[
236 237 238 239
          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),
240 241 242 243 244 245 246 247 248 249 250 251
        ],
      ),
    );
    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),
    ]);

  });

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

257
  testWidgets('Wrap alignment (LTR)', (WidgetTester tester) async {
258
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
259 260
      alignment: WrapAlignment.center,
      spacing: 5.0,
261
      textDirection: TextDirection.ltr,
262
      children: const <Widget>[
263 264 265
        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
266 267 268
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
269 270 271 272
    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
273 274
    ]);

275
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
276 277
      alignment: WrapAlignment.spaceBetween,
      spacing: 5.0,
278
      textDirection: TextDirection.ltr,
279
      children: const <Widget>[
280 281 282
        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
283 284 285
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
286
    verify(tester, <Offset>[
287
      Offset.zero,
288 289
      const Offset(200.0, 0.0),
      const Offset(500.0, 0.0),
Adam Barth's avatar
Adam Barth committed
290 291
    ]);

292
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
293 294
      alignment: WrapAlignment.spaceAround,
      spacing: 5.0,
295
      textDirection: TextDirection.ltr,
296
      children: const <Widget>[
297 298 299
        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
300 301 302
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
303 304 305 306
    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
307 308
    ]);

309
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
310 311
      alignment: WrapAlignment.spaceEvenly,
      spacing: 5.0,
312
      textDirection: TextDirection.ltr,
313
      children: const <Widget>[
314 315 316
        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
317 318 319
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
320 321 322 323
    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
324 325 326
    ]);
  });

327
  testWidgets('Wrap alignment (RTL)', (WidgetTester tester) async {
328
    await tester.pumpWidget(Wrap(
329 330 331
      alignment: WrapAlignment.center,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
332
      children: const <Widget>[
333 334 335
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
336 337 338 339 340 341 342 343 344
      ],
    ));
    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),
    ]);

345
    await tester.pumpWidget(Wrap(
346 347 348
      alignment: WrapAlignment.spaceBetween,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
349
      children: const <Widget>[
350 351 352
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
353 354 355 356 357 358
      ],
    ));
    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),
359
      Offset.zero,
360 361
    ]);

362
    await tester.pumpWidget(Wrap(
363 364 365
      alignment: WrapAlignment.spaceAround,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
366
      children: const <Widget>[
367 368 369
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
370 371 372 373 374 375 376 377 378
      ],
    ));
    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),
    ]);

379
    await tester.pumpWidget(Wrap(
380 381 382
      alignment: WrapAlignment.spaceEvenly,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
383
      children: const <Widget>[
384 385 386
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
387 388 389 390 391 392 393 394 395 396 397
      ],
    ));
    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),
    ]);
  });

  testWidgets('Wrap runAlignment (DOWN)', (WidgetTester tester) async {
398
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
399 400
      runAlignment: WrapAlignment.center,
      runSpacing: 5.0,
401
      textDirection: TextDirection.ltr,
402
      children: const <Widget>[
403 404 405 406 407
        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
408 409 410
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
411 412 413 414 415 416
    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
417 418
    ]);

419
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
420 421
      runAlignment: WrapAlignment.spaceBetween,
      runSpacing: 5.0,
422
      textDirection: TextDirection.ltr,
423
      children: const <Widget>[
424 425 426 427 428
        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
429 430 431
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
432
    verify(tester, <Offset>[
433
      Offset.zero,
434 435 436 437
      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
438 439
    ]);

440
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
441 442
      runAlignment: WrapAlignment.spaceAround,
      runSpacing: 5.0,
443
      textDirection: TextDirection.ltr,
444
      children: const <Widget>[
445 446 447 448 449
        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
450 451 452
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
453 454 455 456 457 458
    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
459 460
    ]);

461
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
462 463
      runAlignment: WrapAlignment.spaceEvenly,
      runSpacing: 5.0,
464
      textDirection: TextDirection.ltr,
465
      children: const <Widget>[
466 467 468 469 470
        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
471 472 473
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
474 475 476 477 478 479
    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
480 481 482 483
    ]);

  });

484
  testWidgets('Wrap runAlignment (UP)', (WidgetTester tester) async {
485
    await tester.pumpWidget(Wrap(
486 487 488 489
      runAlignment: WrapAlignment.center,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
490
      children: const <Widget>[
491 492 493 494 495
        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),
496 497 498 499 500 501 502 503 504 505 506
      ],
    ));
    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),
    ]);

507
    await tester.pumpWidget(Wrap(
508 509 510 511
      runAlignment: WrapAlignment.spaceBetween,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
512
      children: const <Widget>[
513 514 515 516 517
        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),
518 519 520 521 522 523 524 525
      ],
    ));
    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),
526
      Offset.zero,
527 528
    ]);

529
    await tester.pumpWidget(Wrap(
530 531 532 533
      runAlignment: WrapAlignment.spaceAround,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
534
      children: const <Widget>[
535 536 537 538 539
        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),
540 541 542 543 544 545 546 547 548 549 550
      ],
    ));
    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),
    ]);

551
    await tester.pumpWidget(Wrap(
552 553 554 555
      runAlignment: WrapAlignment.spaceEvenly,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
556
      children: const <Widget>[
557 558 559 560 561
        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),
562 563 564 565 566 567 568 569 570 571 572 573 574
      ],
    ));
    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),
    ]);

  });

Adam Barth's avatar
Adam Barth committed
575 576
  testWidgets('Shrink-wrapping Wrap test', (WidgetTester tester) async {
    await tester.pumpWidget(
577
      Align(
578
        alignment: Alignment.topLeft,
579
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
580 581
          alignment: WrapAlignment.end,
          crossAxisAlignment: WrapCrossAlignment.end,
582
          textDirection: TextDirection.ltr,
583
          children: const <Widget>[
584 585 586 587
            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
588 589 590 591 592
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(600.0, 70.0)));
593 594 595 596 597
    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
598 599 600
    ]);

    await tester.pumpWidget(
601
      Align(
602
        alignment: Alignment.topLeft,
603
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
604 605
          alignment: WrapAlignment.end,
          crossAxisAlignment: WrapCrossAlignment.end,
606
          textDirection: TextDirection.ltr,
607
          children: const <Widget>[
608 609 610 611
            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
612 613 614 615 616
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(700.0, 60.0)));
617
    verify(tester, <Offset>[
618
      Offset.zero,
619 620 621
      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
622 623 624 625 626
    ]);
  });

  testWidgets('Wrap spacing test', (WidgetTester tester) async {
    await tester.pumpWidget(
627
      Align(
628
        alignment: Alignment.topLeft,
629
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
630
          runSpacing: 10.0,
631
          textDirection: TextDirection.ltr,
632
          children: const <Widget>[
633 634 635 636
            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
637 638 639 640 641
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(500.0, 130.0)));
642
    verify(tester, <Offset>[
643
      Offset.zero,
644 645 646
      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
647 648 649 650 651
    ]);
  });

  testWidgets('Vertical Wrap test with spacing', (WidgetTester tester) async {
    await tester.pumpWidget(
652
      Align(
653
        alignment: Alignment.topLeft,
654
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
655 656 657
          direction: Axis.vertical,
          spacing: 10.0,
          runSpacing: 15.0,
658
          textDirection: TextDirection.ltr,
659
          children: const <Widget>[
660 661 662 663 664 665
            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
666 667 668 669 670
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(150.0, 510.0)));
671
    verify(tester, <Offset>[
672
      Offset.zero,
673 674 675 676 677
      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
678 679 680
    ]);

    await tester.pumpWidget(
681
      Align(
682
        alignment: Alignment.topLeft,
683
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
684 685
          spacing: 12.0,
          runSpacing: 8.0,
686
          textDirection: TextDirection.ltr,
687
          children: const <Widget>[
688 689 690 691 692 693
            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
694 695 696 697
          ],
        ),
      ),
    );
698
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(270.0, 250.0)));
699
    verify(tester, <Offset>[
700
      Offset.zero,
701 702 703 704 705
      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
706 707 708 709
    ]);
  });

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

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

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

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

  testWidgets('Hit test children in wrap', (WidgetTester tester) async {
    final List<String> log = <String>[];

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

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

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

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

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

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

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

  testWidgets('RenderWrap toString control test', (WidgetTester tester) async {
775
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
776 777
      direction: Axis.vertical,
      runSpacing: 7.0,
778
      textDirection: TextDirection.ltr,
779
      children: const <Widget>[
780 781 782 783
        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
784 785 786 787 788 789 790 791 792 793
      ],
    ));

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

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

  testWidgets('Spacing with slight overflow', (WidgetTester tester) async {
821
    await tester.pumpWidget(Wrap(
822 823 824
      textDirection: TextDirection.ltr,
      spacing: 10.0,
      runSpacing: 10.0,
825
      children: const <Widget>[
826 827 828 829
        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),
830 831 832 833 834
      ],
    ));

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

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

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

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

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

  testWidgets('Wrap can set and update clipBehavior', (WidgetTester tester) async {
    await tester.pumpWidget(Wrap(textDirection: TextDirection.ltr));
    final RenderWrap renderObject = tester.allRenderObjects.whereType<RenderWrap>().first;
887
    expect(renderObject.clipBehavior, equals(Clip.none));
888 889 890 891

    await tester.pumpWidget(Wrap(textDirection: TextDirection.ltr, clipBehavior: Clip.antiAlias));
    expect(renderObject.clipBehavior, equals(Clip.antiAlias));
  });
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956

  testWidgets('Horizontal wrap - IntrinsicsHeight', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/48679.
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Center(
          child: IntrinsicHeight(
            child: Container(
              color: Colors.green,
              child: Wrap(
                children: <Widget>[
                  const Text('Start', style: TextStyle(height: 1.0, fontSize: 16)),
                  Row(
                    children: const <Widget>[
                      SizedBox(height: 40, width: 60),
                    ],
                  ),
                  const Text('End', style: TextStyle(height: 1.0, fontSize: 16)),
                ],
              ),
            ),
          ),
        ),
      ),
    );

    // 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);
  });

  testWidgets('Vertical wrap - IntrinsicsWidth', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/48679.
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Center(
          child: IntrinsicWidth(
            child: Container(
              color: Colors.green,
              child: Wrap(
                direction: Axis.vertical,
                children: <Widget>[
                  const Text('Start', style: TextStyle(height: 1.0, fontSize: 16)),
                  Column(
                    children: const <Widget>[
                      SizedBox(height: 40, width: 60),
                    ],
                  ),
                  const Text('End', style: TextStyle(height: 1.0, fontSize: 16)),
                ],
              ),
            ),
          ),
        ),
      ),
    );

    // 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
957
}