text
stringlengths
1
474
Text widget tries to be as wide as all the characters
it needs to display. The self-determined width of the
Text widget then gets adopted by the Column, which
clashes with the maximum amount of horizontal space its parent,
the Row widget, can provide.How to fix it?Well, you need to make sure the Column won’t attempt
to be wider than it can be. To achieve this,
you need to constrain its width. One way to do it is to
wrap the Column in an Expanded widget:
<code_start>return const Row(
children: [
Icon(Icons.message),
Expanded(
child: Column(
// code omitted
),
),
],
);<code_end>
Another way is to wrap the Column in a Flexible widget
and specify a flex factor. In fact,
the Expanded widget is equivalent to the Flexible widget
with a flex factor of 1.0, as its source code shows.
To further understand how to use the Flex widget in Flutter layouts,
check out this 90-second Widget of the Week video
on the Flexible widget.Further information:The resources linked below provide further information about this error.<topic_end>
<topic_start>
‘RenderBox was not laid out’
While this error is pretty common,
it’s often a side effect of a primary error
occurring earlier in the rendering pipeline.What does the error look like?The message shown by the error looks like this:How might you run into this error?Usually, the issue is related to violation of box constraints,
and it needs to be solved by providing more information
to Flutter about how you’d like to constrain the widgets in question.
You can learn more about how constraints work
in Flutter on the Understanding constraints page.The RenderBox was not laid out error is often
caused by one of two other errors:<topic_end>
<topic_start>
‘Vertical viewport was given unbounded height’
This is another common layout error you could run into
while creating a UI in your Flutter app.What does the error look like?The message shown by the error looks like this:How might you run into this error?The error is often caused when a ListView
(or other kinds of scrollable widgets such as GridView)
is placed inside a Column. A ListView takes all
the vertical space available to it,
unless it’s constrained by its parent widget.
However, a Column doesn’t impose any constraint
on its children’s height by default.
The combination of the two behaviors leads to the failure of
determining the size of the ListView.
<code_start>Widget build(BuildContext context) {
return Center(
child: Column(
children: <Widget>[
const Text('Header'),
ListView(
children: const <Widget>[
ListTile(
leading: Icon(Icons.map),
title: Text('Map'),
),
ListTile(
leading: Icon(Icons.subway),
title: Text('Subway'),
),
],
),
],
),
);
}<code_end>
How to fix it?To fix this error, specify how tall the ListView should be.
To make it as tall as the remaining space in the Column,
wrap it using an Expanded widget (as shown in the following example).
Otherwise, specify an absolute height using a SizedBox
widget or a relative height using a Flexible widget.
<code_start>Widget build(BuildContext context) {
return Center(
child: Column(
children: <Widget>[
const Text('Header'),
Expanded(
child: ListView(
children: const <Widget>[
ListTile(
leading: Icon(Icons.map),
title: Text('Map'),
),
ListTile(
leading: Icon(Icons.subway),
title: Text('Subway'),
),
],
),
),
],
),
);
}<code_end>
Further information:The resources linked below provide
further information about this error.<topic_end>
<topic_start>
‘An InputDecorator…cannot have an unbounded width’