You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 1.2. Responsive Apps On Various Mobile Screen Sizes
102
+
## 1.2. Responsiveness on Mobile Screens
101
103
When creating an app across various mobile screen, we want to make sure they are responsive and expand or collapse based on the screen dimensions. So we will look at how to achieve that with Columns and Rows.
102
104
105
+

106
+
107
+
<br/>
108
+
103
109
### 1.2.1. Columns
104
110
105
111
So, Columns, unlike Scaffold or Container don't pass constraint along the main axis and will build the height from the children. This is because Columns children are dynamic.
@@ -135,7 +141,7 @@ class ColumnExample1 extends StatelessWidget {
135
141
),
136
142
Container(
137
143
color: Colors.orange,
138
-
height: 500,
144
+
height: 1000,
139
145
),
140
146
],
141
147
),
@@ -146,14 +152,59 @@ class ColumnExample1 extends StatelessWidget {
146
152
</p>
147
153
</details>
148
154
149
-
As you saw with the example, the overflow error generally happens with Columns and Rows because they don't pass constraint to the children along the main axis.
155
+
As you saw with the example, the overflow error generally happens with Columns and Rows because they don't pass constraint to the children along the main axis to restric the child's height.
//if the containers height are infite here, the app will //crash
176
+
body: Column(
177
+
children: [
178
+
Container(
179
+
color: Colors.green,
180
+
height: 100,
181
+
),
182
+
Container(
183
+
color: Colors.blue,
184
+
height: 300,
185
+
),
186
+
Container(
187
+
color: Colors.orange,
188
+
height: 100,
189
+
),
190
+
],
191
+
),
192
+
);
193
+
}
194
+
}
195
+
```
196
+
</p>
197
+
</details>
198
+
199
+
Here, there is unused space. The dimensions could work for one mobile device but not for others as
200
+
different mobile devices have different heights.
201
+
202
+
So how do we solve the problem of widgets going out of bounds? We use a special widget called **Expanded** or **Flexible**. These widgets can only be used by Columns or Rows.
152
203
153
204
**Expanded** will fill the remaining space with the child widget, which in our case is the orange widget. Note that when using Expanded, it will completely ignore the child's height.
154
205
155
206
<details>
156
-
<summary>Example 1</summary>
207
+
<summary>Example - Responsive With Expanded</summary>
157
208
158
209
<p>
159
210
@@ -195,12 +246,26 @@ class ColumnExampleResponsive extends StatelessWidget {
195
246
</p>
196
247
</details>
197
248
198
-
Additonal Notes:
199
-
-**Flexible** is similar to Expanded but with more options on the Columns on how children should take up space.
249
+
Notes:
200
250
- Rows is pretty similar to Column, except that the main axis is controlled by width.
251
+
- Use Flex widget if you want dynamic control, i.e, switch between Column and Row.
252
+
-**Flexible** is similar to **Expanded** but with more options on the Columns on how children should take up space.
253
+
- Use **flex** attribute with Expanded to more fine grained control of the space taken by children
0 commit comments