1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
// 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/material.dart';
import 'package:flutter/rendering.dart';
import 'package:test/test.dart';
import 'rendering_tester.dart';
void main() {
test("should size to render view", () {
final RenderBox root = new RenderDecoratedBox(
decoration: new BoxDecoration(
color: const Color(0xFF00FF00),
gradient: new RadialGradient(
center: FractionalOffset.topLeft, radius: 1.8,
colors: <Color>[Colors.yellow[500], Colors.blue[500]],
),
boxShadow: kElevationToShadow[3],
),
);
layout(root);
expect(root.size.width, equals(800.0));
expect(root.size.height, equals(600.0));
});
test('Flex and padding', () {
final RenderBox size = new RenderConstrainedBox(
additionalConstraints: const BoxConstraints().tighten(height: 100.0),
);
final RenderBox inner = new RenderDecoratedBox(
decoration: const BoxDecoration(
color: const Color(0xFF00FF00),
),
child: size,
);
final RenderBox padding = new RenderPadding(
padding: const EdgeInsets.all(50.0),
child: inner,
);
final RenderBox flex = new RenderFlex(
children: <RenderBox>[padding],
direction: Axis.vertical,
crossAxisAlignment: CrossAxisAlignment.stretch,
);
final RenderBox outer = new RenderDecoratedBox(
decoration: const BoxDecoration(
color: const Color(0xFF0000FF),
),
child: flex,
);
layout(outer);
expect(size.size.width, equals(700.0));
expect(size.size.height, equals(100.0));
expect(inner.size.width, equals(700.0));
expect(inner.size.height, equals(100.0));
expect(padding.size.width, equals(800.0));
expect(padding.size.height, equals(200.0));
expect(flex.size.width, equals(800.0));
expect(flex.size.height, equals(600.0));
expect(outer.size.width, equals(800.0));
expect(outer.size.height, equals(600.0));
});
test("should not have a 0 sized colored Box", () {
final RenderBox coloredBox = new RenderDecoratedBox(
decoration: const BoxDecoration(),
);
final RenderBox paddingBox = new RenderPadding(
padding: const EdgeInsets.all(10.0),
child: coloredBox,
);
final RenderBox root = new RenderDecoratedBox(
decoration: const BoxDecoration(),
child: paddingBox,
);
layout(root);
expect(coloredBox.size.width, equals(780.0));
expect(coloredBox.size.height, equals(580.0));
});
test("reparenting should clear position", () {
final RenderDecoratedBox coloredBox = new RenderDecoratedBox(
decoration: const BoxDecoration(),
);
final RenderPadding paddedBox = new RenderPadding(
child: coloredBox,
padding: const EdgeInsets.all(10.0),
);
layout(paddedBox);
final BoxParentData parentData = coloredBox.parentData;
expect(parentData.offset.dx, isNot(equals(0.0)));
paddedBox.child = null;
final RenderConstrainedBox constraintedBox = new RenderConstrainedBox(
child: coloredBox,
additionalConstraints: const BoxConstraints(),
);
layout(constraintedBox);
expect(coloredBox.parentData?.runtimeType, ParentData);
});
}