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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @dart = 2.8
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'rendering_tester.dart';
void main() {
test('LimitedBox: parent max size is unconstrained', () {
final RenderBox child = RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
);
final RenderBox parent = RenderConstrainedOverflowBox(
minWidth: 0.0,
maxWidth: double.infinity,
minHeight: 0.0,
maxHeight: double.infinity,
child: RenderLimitedBox(
maxWidth: 100.0,
maxHeight: 200.0,
child: child,
),
);
layout(parent);
expect(child.size.width, 100.0);
expect(child.size.height, 200.0);
expect(parent, hasAGoodToStringDeep);
expect(
parent.toStringDeep(minLevel: DiagnosticLevel.info),
equalsIgnoringHashCodes(
'RenderConstrainedOverflowBox#00000 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
' │ parentData: <none>\n'
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ size: Size(800.0, 600.0)\n'
' │ alignment: center\n'
' │ minWidth: 0.0\n'
' │ maxWidth: Infinity\n'
' │ minHeight: 0.0\n'
' │ maxHeight: Infinity\n'
' │\n'
' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
' │ parentData: offset=Offset(350.0, 200.0) (can use size)\n'
' │ constraints: BoxConstraints(unconstrained)\n'
' │ size: Size(100.0, 200.0)\n'
' │ maxWidth: 100.0\n'
' │ maxHeight: 200.0\n'
' │\n'
' └─child: RenderConstrainedBox#00000 relayoutBoundary=up2 NEEDS-PAINT\n'
' parentData: <none> (can use size)\n'
' constraints: BoxConstraints(0.0<=w<=100.0, 0.0<=h<=200.0)\n'
' size: Size(100.0, 200.0)\n'
' additionalConstraints: BoxConstraints(w=300.0, h=400.0)\n',
),
);
});
test('LimitedBox: parent maxWidth is unconstrained', () {
final RenderBox child = RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
);
final RenderBox parent = RenderConstrainedOverflowBox(
minWidth: 0.0,
maxWidth: double.infinity,
minHeight: 500.0,
maxHeight: 500.0,
child: RenderLimitedBox(
maxWidth: 100.0,
maxHeight: 200.0,
child: child,
),
);
layout(parent);
expect(child.size.width, 100.0);
expect(child.size.height, 500.0);
});
test('LimitedBox: parent maxHeight is unconstrained', () {
final RenderBox child = RenderConstrainedBox(
additionalConstraints: const BoxConstraints.tightFor(width: 300.0, height: 400.0)
);
final RenderBox parent = RenderConstrainedOverflowBox(
minWidth: 500.0,
maxWidth: 500.0,
minHeight: 0.0,
maxHeight: double.infinity,
child: RenderLimitedBox(
maxWidth: 100.0,
maxHeight: 200.0,
child: child,
),
);
layout(parent);
expect(child.size.width, 500.0);
expect(child.size.height, 200.0);
});
test('LimitedBox: no child', () {
RenderBox box;
final RenderBox parent = RenderConstrainedOverflowBox(
minWidth: 10.0,
maxWidth: 500.0,
minHeight: 0.0,
maxHeight: double.infinity,
child: box = RenderLimitedBox(
maxWidth: 100.0,
maxHeight: 200.0,
),
);
layout(parent);
expect(box.size, const Size(10.0, 0.0));
expect(parent, hasAGoodToStringDeep);
expect(
parent.toStringDeep(minLevel: DiagnosticLevel.info),
equalsIgnoringHashCodes(
'RenderConstrainedOverflowBox#00000 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
' │ parentData: <none>\n'
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ size: Size(800.0, 600.0)\n'
' │ alignment: center\n'
' │ minWidth: 10.0\n'
' │ maxWidth: 500.0\n'
' │ minHeight: 0.0\n'
' │ maxHeight: Infinity\n'
' │\n'
' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT\n'
' parentData: offset=Offset(395.0, 300.0) (can use size)\n'
' constraints: BoxConstraints(10.0<=w<=500.0, 0.0<=h<=Infinity)\n'
' size: Size(10.0, 0.0)\n'
' maxWidth: 100.0\n'
' maxHeight: 200.0\n',
),
);
});
test('LimitedBox: no child use parent', () {
RenderBox box;
final RenderBox parent = RenderConstrainedOverflowBox(
minWidth: 10.0,
child: box = RenderLimitedBox(
maxWidth: 100.0,
maxHeight: 200.0,
),
);
layout(parent);
expect(box.size, const Size(10.0, 600.0));
expect(parent, hasAGoodToStringDeep);
expect(
parent.toStringDeep(minLevel: DiagnosticLevel.info),
equalsIgnoringHashCodes(
'RenderConstrainedOverflowBox#00000 NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE\n'
' │ parentData: <none>\n'
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ size: Size(800.0, 600.0)\n'
' │ alignment: center\n'
' │ minWidth: 10.0\n'
' │ maxWidth: use parent maxWidth constraint\n'
' │ minHeight: use parent minHeight constraint\n'
' │ maxHeight: use parent maxHeight constraint\n'
' │\n'
' └─child: RenderLimitedBox#00000 relayoutBoundary=up1 NEEDS-PAINT\n'
' parentData: offset=Offset(395.0, 0.0) (can use size)\n'
' constraints: BoxConstraints(10.0<=w<=800.0, h=600.0)\n'
' size: Size(10.0, 600.0)\n'
' maxWidth: 100.0\n'
' maxHeight: 200.0\n',
),
);
});
}