wrap_test.dart 28.2 KB
Newer Older
Adam Barth's avatar
Adam Barth committed
1 2 3 4 5 6 7 8 9 10
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

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

11 12 13
void verify(WidgetTester tester, List<Offset> answerKey) {
  final List<Offset> testAnswers = tester.renderObjectList<RenderBox>(find.byType(SizedBox)).map<Offset>(
    (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(
Adam Barth's avatar
Adam Barth committed
22
        alignment: WrapAlignment.start,
23
        textDirection: TextDirection.ltr,
24
        children: const <Widget>[
25 26 27 28
          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
29 30 31
        ],
      ),
    );
32 33 34 35 36
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      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
37 38 39
    ]);

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

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

    await tester.pumpWidget(
78
      Wrap(
Adam Barth's avatar
Adam Barth committed
79 80
        alignment: WrapAlignment.start,
        crossAxisAlignment: WrapCrossAlignment.start,
81
        textDirection: TextDirection.ltr,
82
        children: const <Widget>[
83 84 85 86
          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
87 88 89
        ],
      ),
    );
90 91 92 93 94
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      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
95 96 97
    ]);

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

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

  });

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

    await tester.pumpWidget(
198
      Wrap(
199 200 201 202
        alignment: WrapAlignment.start,
        crossAxisAlignment: WrapCrossAlignment.start,
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
203
        children: const <Widget>[
204 205 206 207
          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),
208 209 210 211 212 213 214 215 216 217 218
        ],
      ),
    );
    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(
219
      Wrap(
220 221 222 223
        alignment: WrapAlignment.start,
        crossAxisAlignment: WrapCrossAlignment.center,
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
224
        children: const <Widget>[
225 226 227 228
          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),
229 230 231 232 233 234 235 236 237 238 239
        ],
      ),
    );
    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(
240
      Wrap(
241 242 243 244
        alignment: WrapAlignment.start,
        crossAxisAlignment: WrapCrossAlignment.end,
        textDirection: TextDirection.ltr,
        verticalDirection: VerticalDirection.up,
245
        children: const <Widget>[
246 247 248 249
          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),
250 251 252 253 254 255 256 257 258 259 260 261
        ],
      ),
    );
    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
262
  testWidgets('Empty wrap', (WidgetTester tester) async {
263
    await tester.pumpWidget(Center(child: Wrap(alignment: WrapAlignment.center)));
Adam Barth's avatar
Adam Barth committed
264 265 266
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(Size.zero));
  });

267
  testWidgets('Wrap alignment (LTR)', (WidgetTester tester) async {
268
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
269 270
      alignment: WrapAlignment.center,
      spacing: 5.0,
271
      textDirection: TextDirection.ltr,
272
      children: const <Widget>[
273 274 275
        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
276 277 278
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
279 280 281 282
    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
283 284
    ]);

285
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
286 287
      alignment: WrapAlignment.spaceBetween,
      spacing: 5.0,
288
      textDirection: TextDirection.ltr,
289
      children: const <Widget>[
290 291 292
        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
293 294 295
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
296 297 298 299
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(200.0, 0.0),
      const Offset(500.0, 0.0),
Adam Barth's avatar
Adam Barth committed
300 301
    ]);

302
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
303 304
      alignment: WrapAlignment.spaceAround,
      spacing: 5.0,
305
      textDirection: TextDirection.ltr,
306
      children: const <Widget>[
307 308 309
        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
310 311 312
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
313 314 315 316
    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
317 318
    ]);

319
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
320 321
      alignment: WrapAlignment.spaceEvenly,
      spacing: 5.0,
322
      textDirection: TextDirection.ltr,
323
      children: const <Widget>[
324 325 326
        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
327 328 329
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
330 331 332 333
    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
334 335 336
    ]);
  });

337
  testWidgets('Wrap alignment (RTL)', (WidgetTester tester) async {
338
    await tester.pumpWidget(Wrap(
339 340 341
      alignment: WrapAlignment.center,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
342
      children: const <Widget>[
343 344 345
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
346 347 348 349 350 351 352 353 354
      ],
    ));
    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),
    ]);

355
    await tester.pumpWidget(Wrap(
356 357 358
      alignment: WrapAlignment.spaceBetween,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
359
      children: const <Widget>[
360 361 362
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 300.0, height: 30.0),
363 364 365 366 367 368 369 370 371
      ],
    ));
    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),
      const Offset(0.0, 0.0),
    ]);

372
    await tester.pumpWidget(Wrap(
373 374 375
      alignment: WrapAlignment.spaceAround,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
376
      children: const <Widget>[
377 378 379
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
380 381 382 383 384 385 386 387 388
      ],
    ));
    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),
    ]);

389
    await tester.pumpWidget(Wrap(
390 391 392
      alignment: WrapAlignment.spaceEvenly,
      spacing: 5.0,
      textDirection: TextDirection.rtl,
393
      children: const <Widget>[
394 395 396
        SizedBox(width: 100.0, height: 10.0),
        SizedBox(width: 200.0, height: 20.0),
        SizedBox(width: 310.0, height: 30.0),
397 398 399 400 401 402 403 404 405 406 407
      ],
    ));
    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 {
408
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
409 410
      runAlignment: WrapAlignment.center,
      runSpacing: 5.0,
411
      textDirection: TextDirection.ltr,
412
      children: const <Widget>[
413 414 415 416 417
        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
418 419 420
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
421 422 423 424 425 426
    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
427 428
    ]);

429
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
430 431
      runAlignment: WrapAlignment.spaceBetween,
      runSpacing: 5.0,
432
      textDirection: TextDirection.ltr,
433
      children: const <Widget>[
434 435 436 437 438
        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
439 440 441
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
442 443 444 445 446 447
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      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
448 449
    ]);

450
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
451 452
      runAlignment: WrapAlignment.spaceAround,
      runSpacing: 5.0,
453
      textDirection: TextDirection.ltr,
454
      children: const <Widget>[
455 456 457 458 459
        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
460 461 462
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
463 464 465 466 467 468
    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
469 470
    ]);

471
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
472 473
      runAlignment: WrapAlignment.spaceEvenly,
      runSpacing: 5.0,
474
      textDirection: TextDirection.ltr,
475
      children: const <Widget>[
476 477 478 479 480
        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
481 482 483
      ],
    ));
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
484 485 486 487 488 489
    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
490 491 492 493
    ]);

  });

494
  testWidgets('Wrap runAlignment (UP)', (WidgetTester tester) async {
495
    await tester.pumpWidget(Wrap(
496 497 498 499
      runAlignment: WrapAlignment.center,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
500
      children: const <Widget>[
501 502 503 504 505
        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),
506 507 508 509 510 511 512 513 514 515 516
      ],
    ));
    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),
    ]);

517
    await tester.pumpWidget(Wrap(
518 519 520 521
      runAlignment: WrapAlignment.spaceBetween,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
522
      children: const <Widget>[
523 524 525 526 527
        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),
528 529 530 531 532 533 534 535 536 537 538
      ],
    ));
    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),
      const Offset(0.0, 0.0),
    ]);

539
    await tester.pumpWidget(Wrap(
540 541 542 543
      runAlignment: WrapAlignment.spaceAround,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
544
      children: const <Widget>[
545 546 547 548 549
        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),
550 551 552 553 554 555 556 557 558 559 560
      ],
    ));
    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),
    ]);

561
    await tester.pumpWidget(Wrap(
562 563 564 565
      runAlignment: WrapAlignment.spaceEvenly,
      runSpacing: 5.0,
      textDirection: TextDirection.ltr,
      verticalDirection: VerticalDirection.up,
566
      children: const <Widget>[
567 568 569 570 571
        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),
572 573 574 575 576 577 578 579 580 581 582 583 584
      ],
    ));
    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
585 586
  testWidgets('Shrink-wrapping Wrap test', (WidgetTester tester) async {
    await tester.pumpWidget(
587
      Align(
588
        alignment: Alignment.topLeft,
589
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
590 591
          alignment: WrapAlignment.end,
          crossAxisAlignment: WrapCrossAlignment.end,
592
          textDirection: TextDirection.ltr,
593
          children: const <Widget>[
594 595 596 597
            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
598 599 600 601 602
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(600.0, 70.0)));
603 604 605 606 607
    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
608 609 610
    ]);

    await tester.pumpWidget(
611
      Align(
612
        alignment: Alignment.topLeft,
613
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
614 615
          alignment: WrapAlignment.end,
          crossAxisAlignment: WrapCrossAlignment.end,
616
          textDirection: TextDirection.ltr,
617
          children: const <Widget>[
618 619 620 621
            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
622 623 624 625 626
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(700.0, 60.0)));
627 628 629 630 631
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      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
632 633 634 635 636
    ]);
  });

  testWidgets('Wrap spacing test', (WidgetTester tester) async {
    await tester.pumpWidget(
637
      Align(
638
        alignment: Alignment.topLeft,
639
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
640 641 642
          runSpacing: 10.0,
          alignment: WrapAlignment.start,
          crossAxisAlignment: WrapCrossAlignment.start,
643
          textDirection: TextDirection.ltr,
644
          children: const <Widget>[
645 646 647 648
            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
649 650 651 652 653
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(500.0, 130.0)));
654 655 656 657 658
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      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
659 660 661 662 663
    ]);
  });

  testWidgets('Vertical Wrap test with spacing', (WidgetTester tester) async {
    await tester.pumpWidget(
664
      Align(
665
        alignment: Alignment.topLeft,
666
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
667 668 669 670 671
          direction: Axis.vertical,
          spacing: 10.0,
          runSpacing: 15.0,
          alignment: WrapAlignment.start,
          crossAxisAlignment: WrapCrossAlignment.start,
672
          textDirection: TextDirection.ltr,
673
          children: const <Widget>[
674 675 676 677 678 679
            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
680 681 682 683 684
          ],
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(150.0, 510.0)));
685 686 687 688 689 690 691
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      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
692 693 694
    ]);

    await tester.pumpWidget(
695
      Align(
696
        alignment: Alignment.topLeft,
697
        child: Wrap(
Adam Barth's avatar
Adam Barth committed
698 699 700
          direction: Axis.horizontal,
          spacing: 12.0,
          runSpacing: 8.0,
701
          textDirection: TextDirection.ltr,
702
          children: const <Widget>[
703 704 705 706 707 708
            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
709 710 711 712
          ],
        ),
      ),
    );
713
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(270.0, 250.0)));
714 715 716 717 718 719 720
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      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
721 722 723 724
    ]);
  });

  testWidgets('Visual overflow generates a clip', (WidgetTester tester) async {
725
    await tester.pumpWidget(Wrap(
726
      textDirection: TextDirection.ltr,
727
      children: const <Widget>[
728
        SizedBox(width: 500.0, height: 500.0),
Adam Barth's avatar
Adam Barth committed
729 730 731 732 733
      ],
    ));

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

734
    await tester.pumpWidget(Wrap(
735
      textDirection: TextDirection.ltr,
736
      children: const <Widget>[
737 738
        SizedBox(width: 500.0, height: 500.0),
        SizedBox(width: 500.0, height: 500.0),
Adam Barth's avatar
Adam Barth committed
739 740 741 742 743 744 745 746 747
      ],
    ));

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

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

748
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
749 750
      spacing: 10.0,
      runSpacing: 15.0,
751
      textDirection: TextDirection.ltr,
Adam Barth's avatar
Adam Barth committed
752
      children: <Widget>[
753 754 755 756
        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),
757
        SizedBox(
Adam Barth's avatar
Adam Barth committed
758 759
          width: 200.0,
          height: 300.0,
760
          child: GestureDetector(
Adam Barth's avatar
Adam Barth committed
761 762 763 764 765 766 767
            behavior: HitTestBehavior.opaque,
            onTap: () { log.add('hit'); },
          ),
        ),
      ],
    ));

768
    await tester.tapAt(const Offset(209.0, 314.0));
Adam Barth's avatar
Adam Barth committed
769 770
    expect(log, isEmpty);

771
    await tester.tapAt(const Offset(211.0, 314.0));
Adam Barth's avatar
Adam Barth committed
772 773
    expect(log, isEmpty);

774
    await tester.tapAt(const Offset(209.0, 316.0));
Adam Barth's avatar
Adam Barth committed
775 776
    expect(log, isEmpty);

777
    await tester.tapAt(const Offset(211.0, 316.0));
Adam Barth's avatar
Adam Barth committed
778 779 780 781
    expect(log, equals(<String>['hit']));
  });

  testWidgets('RenderWrap toStringShallow control test', (WidgetTester tester) async {
782
    await tester.pumpWidget(Wrap(alignment: WrapAlignment.center));
Adam Barth's avatar
Adam Barth committed
783 784 785 786 787 788

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

  testWidgets('RenderWrap toString control test', (WidgetTester tester) async {
789
    await tester.pumpWidget(Wrap(
Adam Barth's avatar
Adam Barth committed
790 791
      direction: Axis.vertical,
      runSpacing: 7.0,
792
      textDirection: TextDirection.ltr,
793
      children: const <Widget>[
794 795 796 797
        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
798 799 800 801 802 803 804 805 806 807
      ],
    ));

    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(
808 809
      Center(
        child: Baseline(
Adam Barth's avatar
Adam Barth committed
810 811
          baseline: 180.0,
          baselineType: TextBaseline.alphabetic,
812
          child: DefaultTextStyle(
Adam Barth's avatar
Adam Barth committed
813 814 815 816
            style: const TextStyle(
              fontFamily: 'Ahem',
              fontSize: 100.0,
            ),
817
            child: Wrap(
818
              textDirection: TextDirection.ltr,
819
              children: const <Widget>[
820
                Text('X', textDirection: TextDirection.ltr),
Adam Barth's avatar
Adam Barth committed
821 822 823 824 825 826 827
              ],
            ),
          ),
        ),
      ),
    );
    expect(tester.renderObject<RenderBox>(find.text('X')).size, const Size(100.0, 100.0));
828 829
    expect(tester.renderObject<RenderBox>(find.byType(Baseline)).size,
           within<Size>(from: const Size(100.0, 200.0), distance: 0.001));
Adam Barth's avatar
Adam Barth committed
830
  });
831 832

  testWidgets('Spacing with slight overflow', (WidgetTester tester) async {
833
    await tester.pumpWidget(Wrap(
834 835 836 837
      direction: Axis.horizontal,
      textDirection: TextDirection.ltr,
      spacing: 10.0,
      runSpacing: 10.0,
838
      children: const <Widget>[
839 840 841 842
        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),
843 844 845 846 847 848 849 850
      ],
    ));

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 600.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(210.0, 0.0),
      const Offset(420.0, 0.0),
851
      const Offset(0.0, 20.0),
852 853
    ]);
  });
854 855

  testWidgets('Object exactly matches container width', (WidgetTester tester) async {
856
    await tester.pumpWidget(
857
      Column(
858
        children: <Widget>[
859
          Wrap(
860 861 862 863 864
            direction: Axis.horizontal,
            textDirection: TextDirection.ltr,
            spacing: 10.0,
            runSpacing: 10.0,
            children: const <Widget>[
865
              SizedBox(width: 800.0, height: 10.0),
866 867 868 869 870
            ],
          ),
        ],
      )
    );
871

872
    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 10.0)));
873
    verify(tester, <Offset>[const Offset(0.0, 0.0)]);
874 875

    await tester.pumpWidget(
876
      Column(
877
        children: <Widget>[
878
          Wrap(
879 880 881 882 883
            direction: Axis.horizontal,
            textDirection: TextDirection.ltr,
            spacing: 10.0,
            runSpacing: 10.0,
            children: const <Widget>[
884 885
              SizedBox(width: 800.0, height: 10.0),
              SizedBox(width: 800.0, height: 10.0),
886 887 888 889 890 891 892 893 894 895 896
            ],
          ),
        ],
      )
    );

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 30.0)));
    verify(tester, <Offset>[
      const Offset(0.0, 0.0),
      const Offset(0.0, 20.0),
    ]);
897
  });
Adam Barth's avatar
Adam Barth committed
898
}