/
main_row_super_playground.dart
220 lines (207 loc) · 6.91 KB
/
main_row_super_playground.dart
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import 'package:assorted_layout_widgets/assorted_layout_widgets.dart';
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(home: Demo()));
class Demo extends StatefulWidget {
const Demo({super.key});
@override
State<Demo> createState() => _DemoState();
}
class _DemoState extends State<Demo> {
late int itemCount;
late double height;
late double width;
late double outer;
late double inner;
late bool withSeparator;
late Alignment alignment;
late double separatorWidth;
late double? parentHeight;
late bool intrinsic;
@override
void initState() {
super.initState();
itemCount = 5;
height = width = 10.0;
inner = 8.0;
outer = 16.0;
withSeparator = true;
alignment = Alignment.center;
separatorWidth = 1.0;
parentHeight = null;
intrinsic = false;
}
void _reset() {
itemCount = 0;
height = width = 10.0;
inner = 0.0;
outer = 0.0;
withSeparator = true;
alignment = Alignment.center;
separatorWidth = 1.0;
parentHeight = null;
intrinsic = false;
}
@override
Widget build(BuildContext context) {
print('---');
print('count = $itemCount');
print('width = $height');
print('height = $width');
print('inner = $inner');
print('outer = $outer');
print('withSeparator = $withSeparator');
print('separatorHeight = $separatorWidth');
print('parentHeight = $parentHeight');
return Scaffold(
appBar: AppBar(title: const Text('RowSuper Playground')),
body: Column(
children: <Widget>[
Expanded(
child: Center(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
blueBox(),
if (intrinsic)
IntrinsicWidth(
child: IntrinsicHeight(child: _content()),
)
else
_content(),
blueBox(),
],
),
),
),
),
//
Container(
width: double.infinity,
color: Colors.grey,
padding: const EdgeInsets.symmetric(vertical: 6.0),
child: Column(
children: <Widget>[
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
button("Add Item", () => itemCount++, color: Colors.green),
button("Reset", _reset, color: Colors.red),
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
button("- Width", () => width -= (width > 0.0) ? 1.0 : 0.0),
button("+ Width", () => width += 1.0),
const Box(width: 10.0),
button("- Height", () => height -= (height > 0.0) ? 1.0 : 0.0),
button("+ Height", () => height += 1.0),
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
button("- Inner", () => inner -= 1.0),
button("+ Inner", () => inner += 1.0),
Text(" $inner"),
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
button("- Outer", () => outer -= 1.0),
button("+ Outer", () => outer += 1.0),
Text(" $outer"),
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
button("Separator ${withSeparator ? 'On' : 'Off'}",
() => withSeparator = !withSeparator),
button(
"- Sep",
withSeparator
? () => separatorWidth -= (separatorWidth > 0.0) ? 1.0 : 0.0
: null),
button("+ Sep", withSeparator ? () => separatorWidth += 1.0 : null),
Text(" $separatorWidth"),
],
),
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
button("Parent Height = $parentHeight", () {
if (parentHeight == null) {
parentHeight = 70.0;
} else if (parentHeight == 70.0) {
parentHeight = double.infinity;
} else if (parentHeight == double.infinity) {
parentHeight = null;
}
}),
const Box(width: 10.0),
button("Alignment = $alignment", () {
if (alignment == Alignment.center) {
alignment = Alignment.topLeft;
} else if (alignment == Alignment.topLeft) {
alignment = Alignment.bottomLeft;
} else if (alignment == Alignment.bottomLeft) {
alignment = Alignment.center;
}
})
],
),
button("Intrinsic Width/Height = $intrinsic", () => intrinsic = !intrinsic),
],
),
),
],
),
);
}
Container _content() {
return Container(
color: Colors.yellow,
height: parentHeight,
child: RowSuper(
alignment: alignment,
separator: withSeparator ? separator() : null,
innerDistance: inner,
outerDistance: outer,
children: [
for (int i = 0; i < itemCount; i++) coloredBox(i),
],
),
);
}
Widget button(String label, VoidCallback? func, {Color color = Colors.blue}) => Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: MaterialButton(
visualDensity: const VisualDensity(vertical: -1.0, horizontal: -3.0),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
color: color,
onPressed: (func == null) ? null : () => setState(func),
child: Text(label),
),
);
Widget separator() => Container(
height: 100,
width: separatorWidth,
color: Colors.black.withOpacity(0.5),
);
Widget coloredBox(int index) => Container(
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.5),
border: Border.all(width: 0.5, color: Colors.black),
),
height: height + index * 10.0,
width: width,
);
Widget blueBox() => Container(
height: 120,
width: 15,
color: Colors.blue.withOpacity(0.80),
);
}