
Unbounded height / width | Decoding Flutter
Unbounded height / width | Decoding Flutter
You put a ListView in a column and you get the error “Viewport was given unbounded height”. What do you do now? Learn why you might be getting this error and what you can do to fix it.
Leave us suggestions for code to unravel in the comments below!
How to debug layout issues with the Flutter Inspector → https://goo.gle/3x3OesY
Explain ‘Unbounded height/width’ errors → https://goo.gle/3jjIwPp
Watch more Decoding Flutter episodes → http://goo.gle/DecodingFlutter
Don’t miss an episode, subscribe to Flutter → http://goo.gle/FlutterYT
Get started with Flutter → http://goo.gle/Flutter
Learn more about the Dart Language → https://goo.gle/2YF9OCi
#DecodingFlutter #Flutter #Developer
Content
0 -> [Music]
7.44 -> you put a list view in a column
9.599 -> like this and you get an error viewport
13.2 -> was given unbounded height
16.8 -> what the flutter needs to perform layout
19.359 -> quickly
20.4 -> in other words it needs to decide where
23.279 -> to put each widget
24.56 -> on the screen very efficiently this
27.68 -> makes your app
28.88 -> faster and also more battery efficient
33.36 -> for that reason flutter's layout
35.6 -> algorithm is
36.8 -> single pass constraints go down
39.92 -> geometry goes up just one time there is
43.28 -> no
43.68 -> back and forth it looks kind of like
46.079 -> this
47.44 -> alright child this is how big or small
50.239 -> you can get
51.92 -> okay dad i want to be this size
55.6 -> all right you'll be here then
60 -> this happens to all widgets it starts
62.8 -> from the very top
64.159 -> something like my app and then it goes
67.439 -> down to every leaf node and then it goes
69.84 -> back up again
71.2 -> with things like column things get a
74 -> little
74.72 -> more interesting because column and
77.68 -> widgets like that
79.119 -> have several children alright kids
83.2 -> time to layout if you could have any
86.479 -> size you wanted
88.479 -> what would it be i want
91.759 -> 20 pixels please i want uh
95.119 -> 30 pixels all right this
98.4 -> is where you all will be that works
102 -> pretty nicely doesn't it but watch what
104.32 -> happens
105.119 -> when one of the kids is well let's view
109.2 -> alright kids it's that time again
112.64 -> if you could have any size you wanted
114.96 -> what would it be
116.799 -> i want 20 pixels please i want
120.56 -> everything all right wait
123.68 -> wait what as much as possible
128.399 -> but but that's infinity
134.64 -> and this is exactly what happens when
137.84 -> you have an unbounded
139.28 -> height error in your app now
142.56 -> you may be thinking why is column saying
145.68 -> you can have any size you wanted why
148.239 -> doesn't it
149.44 -> limit the size of each of the children
153.519 -> to its own size you know why doesn't it
156.4 -> say
156.8 -> you can be as tall as i am well that
159.76 -> would indeed remove
161.36 -> the error but it wouldn't remove the
164.8 -> underlying problem that the error is
167.76 -> trying to tell you about watch this
171.68 -> all right kids each of you can be at
174.319 -> most
174.879 -> as tall as i am 100 pixels
178.959 -> what size do you want 100
182.84 -> pixels hey
185.519 -> alright i guess listview gets
188.8 -> everything as a developer you see no
192.48 -> error
193.12 -> but the final layout is probably not
196 -> what you wanted
198.239 -> all the solutions that we can come up
200.319 -> with to this problem
201.519 -> mean that you either see the error which
204.4 -> is
204.72 -> what's currently happening or
208.08 -> you get weird behavior but no error
212 -> so you don't know what's happening or
215.44 -> the column needs to talk to each
218.879 -> child and you know do a little back and
221.599 -> forth
222.239 -> which means the layout algorithm is much
224.959 -> slower
227.2 -> what does this all mean for you then
231.12 -> so the good news is that if you
234.48 -> have this problem you know about it
237.12 -> immediately
238 -> you get the unbounded height error from
240.879 -> the flutter framework
242.239 -> now if you have this error what should
244.799 -> you be doing
246.159 -> you should be as explicit as possible
249.36 -> for example if you want the list view
252.64 -> to be as big as possible still
255.68 -> giving space to all the other children
258.32 -> of the column
259.44 -> then just wrap it with expanded or
261.759 -> flexible
263.12 -> if on the other hand you want the list
265.52 -> view to be
266.56 -> an exact size for example wrap it with
269.52 -> size box
271.68 -> all right the next time you will see the
274.4 -> dreaded
275.28 -> unbounded height error now you know
278.639 -> why it exists and how to get out of it
282.639 -> thanks for watching
Source: https://www.youtube.com/watch?v=jckqXR5CrPI