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

5 6 7
// This file is run as part of a reduced test set in CI on Mac and Windows
// machines.
@Tags(<String>['reduced-test-set'])
8
library;
9

10
import 'package:flutter/material.dart';
11 12
import 'package:flutter_test/flutter_test.dart';

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

15
void main() {
16
  testWidgets('Container control test', (WidgetTester tester) async {
17
    final Container container = Container(
18
      alignment: Alignment.bottomRight,
19
      padding: const EdgeInsets.all(7.0),
20 21
      // uses color, not decoration:
      color: const Color(0xFF00FF00),
22
      foregroundDecoration: const BoxDecoration(color: Color(0x7F0000FF)),
23 24 25 26 27 28 29 30 31
      width: 53.0,
      height: 76.0,
      constraints: const BoxConstraints(
        minWidth: 50.0,
        maxWidth: 55.0,
        minHeight: 78.0,
        maxHeight: 82.0,
      ),
      margin: const EdgeInsets.all(5.0),
32
      child: const SizedBox(
33 34
        width: 25.0,
        height: 33.0,
35
        child: DecoratedBox(
36
          // uses decoration, not color:
37
          decoration: BoxDecoration(color: Color(0xFFFFFF00)),
38 39 40 41 42 43
        ),
      ),
    );

    expect(container, hasOneLineDescription);

44
    await tester.pumpWidget(Align(
45
      alignment: Alignment.topLeft,
46
      child: container,
47 48
    ));

49
    final RenderBox box = tester.renderObject(find.byType(Container));
50 51 52
    expect(box, isNotNull);

    expect(box, paints
Dan Field's avatar
Dan Field committed
53 54 55
      ..rect(rect: const Rect.fromLTWH(5.0, 5.0, 53.0, 78.0), color: const Color(0xFF00FF00))
      ..rect(rect: const Rect.fromLTWH(26.0, 43.0, 25.0, 33.0), color: const Color(0xFFFFFF00))
      ..rect(rect: const Rect.fromLTWH(5.0, 5.0, 53.0, 78.0), color: const Color(0x7F0000FF)),
56
    );
57 58 59

    expect(box, hasAGoodToStringDeep);
    expect(
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
      box.toStringDeep(minLevel: DiagnosticLevel.info),
      equalsIgnoringHashCodes(
        'RenderPadding#00000 relayoutBoundary=up1\n'
        ' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
        ' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
        ' │ size: Size(63.0, 88.0)\n'
        ' │ padding: EdgeInsets.all(5.0)\n'
        ' │\n'
        ' └─child: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
        '   │ parentData: offset=Offset(5.0, 5.0) (can use size)\n'
        '   │ constraints: BoxConstraints(0.0<=w<=790.0, 0.0<=h<=590.0)\n'
        '   │ size: Size(53.0, 78.0)\n'
        '   │ additionalConstraints: BoxConstraints(w=53.0, h=78.0)\n'
        '   │\n'
        '   └─child: RenderDecoratedBox#00000\n'
        '     │ parentData: <none> (can use size)\n'
        '     │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
        '     │ size: Size(53.0, 78.0)\n'
        '     │ decoration: BoxDecoration:\n'
        '     │   color: Color(0x7f0000ff)\n'
        '     │ configuration: ImageConfiguration(bundle:\n'
        '     │   PlatformAssetBundle#00000(), devicePixelRatio: 1.0, platform:\n'
        '     │   android)\n'
        '     │\n'
84
        '     └─child: _RenderColoredBox#00000\n'
85 86 87
        '       │ parentData: <none> (can use size)\n'
        '       │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
        '       │ size: Size(53.0, 78.0)\n'
88
        '       │ behavior: opaque\n'
89 90 91 92 93 94 95 96 97 98 99
        '       │\n'
        '       └─child: RenderPadding#00000\n'
        '         │ parentData: <none> (can use size)\n'
        '         │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
        '         │ size: Size(53.0, 78.0)\n'
        '         │ padding: EdgeInsets.all(7.0)\n'
        '         │\n'
        '         └─child: RenderPositionedBox#00000\n'
        '           │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
        '           │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
        '           │ size: Size(39.0, 64.0)\n'
100
        '           │ alignment: Alignment.bottomRight\n'
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
        '           │ widthFactor: expand\n'
        '           │ heightFactor: expand\n'
        '           │\n'
        '           └─child: RenderConstrainedBox#00000 relayoutBoundary=up1\n'
        '             │ parentData: offset=Offset(14.0, 31.0) (can use size)\n'
        '             │ constraints: BoxConstraints(0.0<=w<=39.0, 0.0<=h<=64.0)\n'
        '             │ size: Size(25.0, 33.0)\n'
        '             │ additionalConstraints: BoxConstraints(w=25.0, h=33.0)\n'
        '             │\n'
        '             └─child: RenderDecoratedBox#00000\n'
        '                 parentData: <none> (can use size)\n'
        '                 constraints: BoxConstraints(w=25.0, h=33.0)\n'
        '                 size: Size(25.0, 33.0)\n'
        '                 decoration: BoxDecoration:\n'
        '                   color: Color(0xffffff00)\n'
        '                 configuration: ImageConfiguration(bundle:\n'
        '                   PlatformAssetBundle#00000(), devicePixelRatio: 1.0, platform:\n'
        '                   android)\n',
      ),
    );

    expect(
123
      box.toStringDeep(),
124 125
      equalsIgnoringHashCodes(
        'RenderPadding#00000 relayoutBoundary=up1\n'
126 127
        ' │ creator: Padding ← Container ← Align ← View-[GlobalObjectKey\n'
        ' │   TestWindow#00000] ← [root]\n'
128 129 130 131 132 133
        ' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
        ' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
        ' │ size: Size(63.0, 88.0)\n'
        ' │ padding: EdgeInsets.all(5.0)\n'
        ' │\n'
        ' └─child: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
134 135
        '   │ creator: ConstrainedBox ← Padding ← Container ← Align ←\n'
        '   │   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
136 137 138 139 140 141 142
        '   │ parentData: offset=Offset(5.0, 5.0) (can use size)\n'
        '   │ constraints: BoxConstraints(0.0<=w<=790.0, 0.0<=h<=590.0)\n'
        '   │ size: Size(53.0, 78.0)\n'
        '   │ additionalConstraints: BoxConstraints(w=53.0, h=78.0)\n'
        '   │\n'
        '   └─child: RenderDecoratedBox#00000\n'
        '     │ creator: DecoratedBox ← ConstrainedBox ← Padding ← Container ←\n'
143
        '     │   Align ← View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
144 145 146 147 148 149 150 151 152
        '     │ parentData: <none> (can use size)\n'
        '     │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
        '     │ size: Size(53.0, 78.0)\n'
        '     │ decoration: BoxDecoration:\n'
        '     │   color: Color(0x7f0000ff)\n'
        '     │ configuration: ImageConfiguration(bundle:\n'
        '     │   PlatformAssetBundle#00000(), devicePixelRatio: 1.0, platform:\n'
        '     │   android)\n'
        '     │\n'
153 154
        '     └─child: _RenderColoredBox#00000\n'
        '       │ creator: ColoredBox ← DecoratedBox ← ConstrainedBox ← Padding ←\n'
155 156
        '       │   Container ← Align ← View-[GlobalObjectKey TestWindow#00000] ←\n'
        '       │   [root]\n'
157 158 159
        '       │ parentData: <none> (can use size)\n'
        '       │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
        '       │ size: Size(53.0, 78.0)\n'
160
        '       │ behavior: opaque\n'
161 162
        '       │\n'
        '       └─child: RenderPadding#00000\n'
163
        '         │ creator: Padding ← ColoredBox ← DecoratedBox ← ConstrainedBox ←\n'
164 165
        '         │   Padding ← Container ← Align ← View-[GlobalObjectKey\n'
        '         │   TestWindow#00000] ← [root]\n'
166 167 168 169 170 171
        '         │ parentData: <none> (can use size)\n'
        '         │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
        '         │ size: Size(53.0, 78.0)\n'
        '         │ padding: EdgeInsets.all(7.0)\n'
        '         │\n'
        '         └─child: RenderPositionedBox#00000\n'
172
        '           │ creator: Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
173 174
        '           │   ConstrainedBox ← Padding ← Container ← Align ←\n'
        '           │   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
175 176 177
        '           │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
        '           │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
        '           │ size: Size(39.0, 64.0)\n'
178
        '           │ alignment: Alignment.bottomRight\n'
179 180 181 182
        '           │ widthFactor: expand\n'
        '           │ heightFactor: expand\n'
        '           │\n'
        '           └─child: RenderConstrainedBox#00000 relayoutBoundary=up1\n'
183
        '             │ creator: SizedBox ← Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
184 185
        '             │   ConstrainedBox ← Padding ← Container ← Align ←\n'
        '             │   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
186 187 188 189 190 191
        '             │ parentData: offset=Offset(14.0, 31.0) (can use size)\n'
        '             │ constraints: BoxConstraints(0.0<=w<=39.0, 0.0<=h<=64.0)\n'
        '             │ size: Size(25.0, 33.0)\n'
        '             │ additionalConstraints: BoxConstraints(w=25.0, h=33.0)\n'
        '             │\n'
        '             └─child: RenderDecoratedBox#00000\n'
192 193
        '                 creator: DecoratedBox ← SizedBox ← Align ← Padding ← ColoredBox ←\n'
        '                   DecoratedBox ← ConstrainedBox ← Padding ← Container ← Align ←\n'
194
        '                   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
195 196 197 198 199 200 201
        '                 parentData: <none> (can use size)\n'
        '                 constraints: BoxConstraints(w=25.0, h=33.0)\n'
        '                 size: Size(25.0, 33.0)\n'
        '                 decoration: BoxDecoration:\n'
        '                   color: Color(0xffffff00)\n'
        '                 configuration: ImageConfiguration(bundle:\n'
        '                   PlatformAssetBundle#00000(), devicePixelRatio: 1.0, platform:\n'
202
        '                   android)\n'
203 204 205 206 207 208 209
      ),
    );

    expect(
      box.toStringDeep(minLevel: DiagnosticLevel.fine),
      equalsIgnoringHashCodes(
        'RenderPadding#00000 relayoutBoundary=up1\n'
210 211
        ' │ creator: Padding ← Container ← Align ← View-[GlobalObjectKey\n'
        ' │   TestWindow#00000] ← [root]\n'
212 213 214 215 216 217 218 219 220
        ' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
        ' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
        ' │ layer: null\n'
        ' │ semantics node: null\n'
        ' │ size: Size(63.0, 88.0)\n'
        ' │ padding: EdgeInsets.all(5.0)\n'
        ' │ textDirection: null\n'
        ' │\n'
        ' └─child: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
221 222
        '   │ creator: ConstrainedBox ← Padding ← Container ← Align ←\n'
        '   │   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
223 224 225 226 227 228 229 230 231
        '   │ parentData: offset=Offset(5.0, 5.0) (can use size)\n'
        '   │ constraints: BoxConstraints(0.0<=w<=790.0, 0.0<=h<=590.0)\n'
        '   │ layer: null\n'
        '   │ semantics node: null\n'
        '   │ size: Size(53.0, 78.0)\n'
        '   │ additionalConstraints: BoxConstraints(w=53.0, h=78.0)\n'
        '   │\n'
        '   └─child: RenderDecoratedBox#00000\n'
        '     │ creator: DecoratedBox ← ConstrainedBox ← Padding ← Container ←\n'
232
        '     │   Align ← View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
        '     │ parentData: <none> (can use size)\n'
        '     │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
        '     │ layer: null\n'
        '     │ semantics node: null\n'
        '     │ size: Size(53.0, 78.0)\n'
        '     │ decoration: BoxDecoration:\n'
        '     │   color: Color(0x7f0000ff)\n'
        '     │   image: null\n'
        '     │   border: null\n'
        '     │   borderRadius: null\n'
        '     │   boxShadow: null\n'
        '     │   gradient: null\n'
        '     │   shape: rectangle\n'
        '     │ configuration: ImageConfiguration(bundle:\n'
        '     │   PlatformAssetBundle#00000(), devicePixelRatio: 1.0, platform:\n'
        '     │   android)\n'
        '     │\n'
250 251
        '     └─child: _RenderColoredBox#00000\n'
        '       │ creator: ColoredBox ← DecoratedBox ← ConstrainedBox ← Padding ←\n'
252 253
        '       │   Container ← Align ← View-[GlobalObjectKey TestWindow#00000] ←\n'
        '       │   [root]\n'
254 255 256 257 258
        '       │ parentData: <none> (can use size)\n'
        '       │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
        '       │ layer: null\n'
        '       │ semantics node: null\n'
        '       │ size: Size(53.0, 78.0)\n'
259
        '       │ behavior: opaque\n'
260 261
        '       │\n'
        '       └─child: RenderPadding#00000\n'
262
        '         │ creator: Padding ← ColoredBox ← DecoratedBox ← ConstrainedBox ←\n'
263 264
        '         │   Padding ← Container ← Align ← View-[GlobalObjectKey\n'
        '         │   TestWindow#00000] ← [root]\n'
265 266 267 268 269 270 271 272 273
        '         │ parentData: <none> (can use size)\n'
        '         │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
        '         │ layer: null\n'
        '         │ semantics node: null\n'
        '         │ size: Size(53.0, 78.0)\n'
        '         │ padding: EdgeInsets.all(7.0)\n'
        '         │ textDirection: null\n'
        '         │\n'
        '         └─child: RenderPositionedBox#00000\n'
274
        '           │ creator: Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
275 276
        '           │   ConstrainedBox ← Padding ← Container ← Align ←\n'
        '           │   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
277 278 279 280 281
        '           │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
        '           │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
        '           │ layer: null\n'
        '           │ semantics node: null\n'
        '           │ size: Size(39.0, 64.0)\n'
282
        '           │ alignment: Alignment.bottomRight\n'
283 284 285 286 287
        '           │ textDirection: null\n'
        '           │ widthFactor: expand\n'
        '           │ heightFactor: expand\n'
        '           │\n'
        '           └─child: RenderConstrainedBox#00000 relayoutBoundary=up1\n'
288
        '             │ creator: SizedBox ← Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
289 290
        '             │   ConstrainedBox ← Padding ← Container ← Align ←\n'
        '             │   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
291 292 293 294 295 296 297 298
        '             │ parentData: offset=Offset(14.0, 31.0) (can use size)\n'
        '             │ constraints: BoxConstraints(0.0<=w<=39.0, 0.0<=h<=64.0)\n'
        '             │ layer: null\n'
        '             │ semantics node: null\n'
        '             │ size: Size(25.0, 33.0)\n'
        '             │ additionalConstraints: BoxConstraints(w=25.0, h=33.0)\n'
        '             │\n'
        '             └─child: RenderDecoratedBox#00000\n'
299 300
        '                 creator: DecoratedBox ← SizedBox ← Align ← Padding ← ColoredBox ←\n'
        '                   DecoratedBox ← ConstrainedBox ← Padding ← Container ← Align ←\n'
301
        '                   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
        '                 parentData: <none> (can use size)\n'
        '                 constraints: BoxConstraints(w=25.0, h=33.0)\n'
        '                 layer: null\n'
        '                 semantics node: null\n'
        '                 size: Size(25.0, 33.0)\n'
        '                 decoration: BoxDecoration:\n'
        '                   color: Color(0xffffff00)\n'
        '                   image: null\n'
        '                   border: null\n'
        '                   borderRadius: null\n'
        '                   boxShadow: null\n'
        '                   gradient: null\n'
        '                   shape: rectangle\n'
        '                 configuration: ImageConfiguration(bundle:\n'
        '                   PlatformAssetBundle#00000(), devicePixelRatio: 1.0, platform:\n'
317
        '                   android)\n'
318 319 320 321 322
      ),
    );

    expect(
      box.toStringDeep(minLevel: DiagnosticLevel.hidden),
323 324
      equalsIgnoringHashCodes(
        'RenderPadding#00000 relayoutBoundary=up1\n'
325
        ' │ needsCompositing: false\n'
326 327
        ' │ creator: Padding ← Container ← Align ← View-[GlobalObjectKey\n'
        ' │   TestWindow#00000] ← [root]\n'
328 329
        ' │ parentData: offset=Offset(0.0, 0.0) (can use size)\n'
        ' │ constraints: BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0)\n'
330 331 332 333
        ' │ layer: null\n'
        ' │ semantics node: null\n'
        ' │ isBlockingSemanticsOfPreviouslyPaintedNodes: false\n'
        ' │ isSemanticBoundary: false\n'
334
        ' │ size: Size(63.0, 88.0)\n'
335
        ' │ padding: EdgeInsets.all(5.0)\n'
336
        ' │ textDirection: null\n'
337 338
        ' │\n'
        ' └─child: RenderConstrainedBox#00000 relayoutBoundary=up2\n'
339
        '   │ needsCompositing: false\n'
340 341
        '   │ creator: ConstrainedBox ← Padding ← Container ← Align ←\n'
        '   │   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
342 343
        '   │ parentData: offset=Offset(5.0, 5.0) (can use size)\n'
        '   │ constraints: BoxConstraints(0.0<=w<=790.0, 0.0<=h<=590.0)\n'
344 345 346 347
        '   │ layer: null\n'
        '   │ semantics node: null\n'
        '   │ isBlockingSemanticsOfPreviouslyPaintedNodes: false\n'
        '   │ isSemanticBoundary: false\n'
348 349 350 351
        '   │ size: Size(53.0, 78.0)\n'
        '   │ additionalConstraints: BoxConstraints(w=53.0, h=78.0)\n'
        '   │\n'
        '   └─child: RenderDecoratedBox#00000\n'
352
        '     │ needsCompositing: false\n'
353
        '     │ creator: DecoratedBox ← ConstrainedBox ← Padding ← Container ←\n'
354
        '     │   Align ← View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
355 356
        '     │ parentData: <none> (can use size)\n'
        '     │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
357 358 359 360
        '     │ layer: null\n'
        '     │ semantics node: null\n'
        '     │ isBlockingSemanticsOfPreviouslyPaintedNodes: false\n'
        '     │ isSemanticBoundary: false\n'
361
        '     │ size: Size(53.0, 78.0)\n'
362
        '     │ decoration: BoxDecoration:\n'
363
        '     │   color: Color(0x7f0000ff)\n'
364 365 366 367 368 369
        '     │   image: null\n'
        '     │   border: null\n'
        '     │   borderRadius: null\n'
        '     │   boxShadow: null\n'
        '     │   gradient: null\n'
        '     │   shape: rectangle\n'
370 371 372 373
        '     │ configuration: ImageConfiguration(bundle:\n'
        '     │   PlatformAssetBundle#00000(), devicePixelRatio: 1.0, platform:\n'
        '     │   android)\n'
        '     │\n'
374
        '     └─child: _RenderColoredBox#00000\n'
375
        '       │ needsCompositing: false\n'
376
        '       │ creator: ColoredBox ← DecoratedBox ← ConstrainedBox ← Padding ←\n'
377 378
        '       │   Container ← Align ← View-[GlobalObjectKey TestWindow#00000] ←\n'
        '       │   [root]\n'
379 380
        '       │ parentData: <none> (can use size)\n'
        '       │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
381 382 383 384
        '       │ layer: null\n'
        '       │ semantics node: null\n'
        '       │ isBlockingSemanticsOfPreviouslyPaintedNodes: false\n'
        '       │ isSemanticBoundary: false\n'
385
        '       │ size: Size(53.0, 78.0)\n'
386
        '       │ behavior: opaque\n'
387 388
        '       │\n'
        '       └─child: RenderPadding#00000\n'
389
        '         │ needsCompositing: false\n'
390
        '         │ creator: Padding ← ColoredBox ← DecoratedBox ← ConstrainedBox ←\n'
391 392
        '         │   Padding ← Container ← Align ← View-[GlobalObjectKey\n'
        '         │   TestWindow#00000] ← [root]\n'
393 394
        '         │ parentData: <none> (can use size)\n'
        '         │ constraints: BoxConstraints(w=53.0, h=78.0)\n'
395 396 397 398
        '         │ layer: null\n'
        '         │ semantics node: null\n'
        '         │ isBlockingSemanticsOfPreviouslyPaintedNodes: false\n'
        '         │ isSemanticBoundary: false\n'
399
        '         │ size: Size(53.0, 78.0)\n'
400
        '         │ padding: EdgeInsets.all(7.0)\n'
401
        '         │ textDirection: null\n'
402 403
        '         │\n'
        '         └─child: RenderPositionedBox#00000\n'
404
        '           │ needsCompositing: false\n'
405
        '           │ creator: Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
406 407
        '           │   ConstrainedBox ← Padding ← Container ← Align ←\n'
        '           │   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
408 409
        '           │ parentData: offset=Offset(7.0, 7.0) (can use size)\n'
        '           │ constraints: BoxConstraints(w=39.0, h=64.0)\n'
410 411 412 413
        '           │ layer: null\n'
        '           │ semantics node: null\n'
        '           │ isBlockingSemanticsOfPreviouslyPaintedNodes: false\n'
        '           │ isSemanticBoundary: false\n'
414
        '           │ size: Size(39.0, 64.0)\n'
415
        '           │ alignment: Alignment.bottomRight\n'
416
        '           │ textDirection: null\n'
417 418 419 420
        '           │ widthFactor: expand\n'
        '           │ heightFactor: expand\n'
        '           │\n'
        '           └─child: RenderConstrainedBox#00000 relayoutBoundary=up1\n'
421
        '             │ needsCompositing: false\n'
422
        '             │ creator: SizedBox ← Align ← Padding ← ColoredBox ← DecoratedBox ←\n'
423 424
        '             │   ConstrainedBox ← Padding ← Container ← Align ←\n'
        '             │   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
425 426
        '             │ parentData: offset=Offset(14.0, 31.0) (can use size)\n'
        '             │ constraints: BoxConstraints(0.0<=w<=39.0, 0.0<=h<=64.0)\n'
427 428 429 430
        '             │ layer: null\n'
        '             │ semantics node: null\n'
        '             │ isBlockingSemanticsOfPreviouslyPaintedNodes: false\n'
        '             │ isSemanticBoundary: false\n'
431 432 433 434
        '             │ size: Size(25.0, 33.0)\n'
        '             │ additionalConstraints: BoxConstraints(w=25.0, h=33.0)\n'
        '             │\n'
        '             └─child: RenderDecoratedBox#00000\n'
435
        '                 needsCompositing: false\n'
436 437
        '                 creator: DecoratedBox ← SizedBox ← Align ← Padding ← ColoredBox ←\n'
        '                   DecoratedBox ← ConstrainedBox ← Padding ← Container ← Align ←\n'
438
        '                   View-[GlobalObjectKey TestWindow#00000] ← [root]\n'
439 440
        '                 parentData: <none> (can use size)\n'
        '                 constraints: BoxConstraints(w=25.0, h=33.0)\n'
441 442 443 444
        '                 layer: null\n'
        '                 semantics node: null\n'
        '                 isBlockingSemanticsOfPreviouslyPaintedNodes: false\n'
        '                 isSemanticBoundary: false\n'
445
        '                 size: Size(25.0, 33.0)\n'
446
        '                 decoration: BoxDecoration:\n'
447
        '                   color: Color(0xffffff00)\n'
448 449 450 451 452 453
        '                   image: null\n'
        '                   border: null\n'
        '                   borderRadius: null\n'
        '                   boxShadow: null\n'
        '                   gradient: null\n'
        '                   shape: rectangle\n'
454 455
        '                 configuration: ImageConfiguration(bundle:\n'
        '                   PlatformAssetBundle#00000(), devicePixelRatio: 1.0, platform:\n'
456
        '                   android)\n'
457 458
      ),
    );
459 460 461

    final RenderBox decoratedBox = tester.renderObject(find.byType(DecoratedBox).last);
    final PaintingContext context = _MockPaintingContext();
462
    late FlutterError error;
463
    try {
464
      decoratedBox.paint(context, Offset.zero);
465 466 467 468 469 470 471 472 473 474 475 476 477 478
    } on FlutterError catch (e) {
      error = e;
    }
    expect(error, isNotNull);
    expect(
      error.toStringDeep(),
      'FlutterError\n'
      '   BoxDecoration painter had mismatching save and restore calls.\n'
      '   Before painting the decoration, the canvas save count was 0.\n'
      '   After painting it, the canvas save count was 2. Every call to\n'
      '   save() or saveLayer() must be matched by a call to restore().\n'
      '   The decoration was:\n'
      '     BoxDecoration(color: Color(0xffffff00))\n'
      '   The painter was:\n'
479
      '     BoxPainter for BoxDecoration(color: Color(0xffffff00))\n',
480
    );
481 482
  });

483
  testWidgets('Can be placed in an infinite box', (WidgetTester tester) async {
484
    await tester.pumpWidget(
485
      Directionality(
486
        textDirection: TextDirection.ltr,
487
        child: ListView(children: <Widget>[Container()]),
488 489
      ),
    );
490
  });
491

492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
  testWidgets('Container transformAlignment', (WidgetTester tester) async {
    final Key key = UniqueKey();

    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: Stack(
          children: <Widget>[
            Positioned(
              top: 100.0,
              left: 100.0,
              child: Container(
                width: 100.0,
                height: 100.0,
                color: const Color(0xFF0000FF),
              ),
            ),
            Positioned(
              top: 100.0,
              left: 100.0,
              child: Container(
                width: 100.0,
                height: 100.0,
                key: key,
                transform: Matrix4.diagonal3Values(0.5, 0.5, 1.0),
517
                transformAlignment: Alignment.centerRight,
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
                child: Container(
                  color: const Color(0xFF00FFFF),
                ),
              ),
            ),
          ],
        ),
      ),
    );

    final Finder finder = find.byKey(key);

    expect(tester.getSize(finder), equals(const Size(100, 100)));

    expect(tester.getTopLeft(finder), equals(const Offset(100, 100)));
    expect(tester.getTopRight(finder), equals(const Offset(200, 100)));

    expect(tester.getBottomLeft(finder), equals(const Offset(100, 200)));
    expect(tester.getBottomRight(finder), equals(const Offset(200, 200)));
  });

539
  testWidgets('giving clipBehaviour Clip.None, will not add a ClipPath to the tree', (WidgetTester tester) async {
540 541 542
    await tester.pumpWidget(
      Container(
        decoration: const BoxDecoration(
543
        borderRadius: BorderRadius.all(Radius.circular(1)),
544 545 546 547 548 549 550 551 552 553 554 555 556
      ),
      child: const SizedBox(),
    ));

    expect(
      find.byType(ClipPath),
      findsNothing,
    );
  });

  testWidgets('giving clipBehaviour not a Clip.None, will add a ClipPath to the tree', (WidgetTester tester) async {
    final Container container = Container(
      clipBehavior: Clip.hardEdge,
557 558
      decoration: const BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(1)),
559 560 561 562 563 564 565 566 567 568 569
      ),
      child: const SizedBox(),
    );

    await tester.pumpWidget(container);

    expect(
      find.byType(ClipPath),
      findsOneWidget,
    );
  });
570

571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600
  testWidgets('getClipPath() works for lots of kinds of decorations', (WidgetTester tester) async {
    Future<void> test(Decoration decoration) async {
      await tester.pumpWidget(
        Directionality(
          textDirection: TextDirection.rtl,
          child: Center(
            child: SizedBox(
              width: 100.0,
              height: 100.0,
              child: RepaintBoundary(
                child: Container(
                  clipBehavior: Clip.hardEdge,
                  decoration: decoration,
                  child: ColoredBox(
                    color: Colors.yellow.withOpacity(0.5),
                  ),
                ),
              ),
            ),
          ),
        ),
      );
      await expectLater(find.byType(Container), matchesGoldenFile('container_test.getClipPath.${decoration.runtimeType}.png'));
    }
    await test(const BoxDecoration());
    await test(const UnderlineTabIndicator());
    await test(const ShapeDecoration(shape: StadiumBorder()));
    await test(const FlutterLogoDecoration());
  });

601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
  testWidgets('Container is hittable only when having decorations', (WidgetTester tester) async {
    bool tapped = false;
    await tester.pumpWidget(GestureDetector(
      onTap: () { tapped = true; },
      child: Container(
        decoration: const BoxDecoration(color: Colors.black),
      ),
    ));

    await tester.tap(find.byType(Container));
    expect(tapped, true);
    tapped = false;

    await tester.pumpWidget(GestureDetector(
      onTap: () { tapped = true; },
      child: Container(
        foregroundDecoration: const BoxDecoration(color: Colors.black),
      ),
    ));

    await tester.tap(find.byType(Container));
    expect(tapped, true);
    tapped = false;

    await tester.pumpWidget(GestureDetector(
      onTap: () { tapped = true; },
      child: Container(
        color: Colors.black,
      ),
    ));

    await tester.tap(find.byType(Container));
    expect(tapped, true);
    tapped = false;

    // Everything but color or decorations
    await tester.pumpWidget(GestureDetector(
      onTap: () { tapped = true; },
      child: Center(
        child: Container(
          alignment: Alignment.bottomRight,
          padding: const EdgeInsets.all(2),
          width: 50,
          height: 50,
          margin: const EdgeInsets.all(2),
          transform: Matrix4.rotationZ(1),
        ),
      ),
    ));

651
    await tester.tap(find.byType(Container), warnIfMissed: false);
652 653
    expect(tapped, false);
  });
654

655 656 657 658 659 660 661 662 663 664 665 666 667 668 669
  testWidgets('Container discards alignment when the child parameter is null and constraints is not Tight', (WidgetTester tester) async {
    await tester.pumpWidget(
      Container(
        decoration: const BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(1)),
      ),
      alignment: Alignment.centerLeft
    ));

    expect(
      find.byType(Align),
      findsNothing,
    );
  });

670 671 672
  testWidgets('using clipBehaviour and shadow, should not clip the shadow', (WidgetTester tester) async {
    final Container container = Container(
      clipBehavior: Clip.hardEdge,
673 674
      decoration: const BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(30)),
675
        color: Colors.red,
676
        boxShadow: <BoxShadow>[
677 678 679 680 681 682 683
          BoxShadow(
            color: Colors.blue,
            spreadRadius: 10,
            blurRadius: 20.0,
          ),
        ],
      ),
684 685 686 687 688 689 690 691
      child: const SizedBox(width: 50, height: 50),
    );

    await tester.pumpWidget(
      RepaintBoundary(
        child: Padding(
          padding: const EdgeInsets.all(30.0),
          child: container,
692 693
        ),
      ),
694 695 696 697 698 699 700
    );

    await expectLater(
      find.byType(RepaintBoundary),
      matchesGoldenFile('container.clipBehaviour.with.shadow.png'),
    );
  });
701
}
702

703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
class _MockPaintingContext extends Fake implements PaintingContext {
  @override
  final Canvas canvas = _MockCanvas();
}

class _MockCanvas extends Fake implements Canvas {
  int saveCount = 0;

  @override
  int getSaveCount() {
    return saveCount++;
  }

  @override
  void drawRect(Rect rect, Paint paint) { }
}