wrap_test.dart 30.8 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 7 8 9 10 11
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';

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

12 13 14
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
15 16 17 18 19
  ).toList();
  expect(testAnswers, equals(answerKey));
}

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

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

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

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

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

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

  });

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

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

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

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

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

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

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

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

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

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

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

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

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

  });

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    expect(tester.renderObject<RenderBox>(find.byType(Wrap)).size, equals(const Size(800.0, 30.0)));
    verify(tester, <Offset>[
896
      Offset.zero,
897 898
      const Offset(0.0, 20.0),
    ]);
899
  });
900 901 902 903

  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;
904
    expect(renderObject.clipBehavior, equals(Clip.none));
905 906 907 908

    await tester.pumpWidget(Wrap(textDirection: TextDirection.ltr, clipBehavior: Clip.antiAlias));
    expect(renderObject.clipBehavior, equals(Clip.antiAlias));
  });
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 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973

  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
974
}