text stringlengths 1 372 |
|---|
further information: |
the resources linked below provide |
further information about this error. |
<topic_end> |
<topic_start> |
‘an InputDecorator…cannot have an unbounded width’ |
the error message suggests that it’s also related |
to box constraints, which are important to understand |
to avoid many of the most common flutter framework errors. |
what does the error look like? |
the message shown by the error looks like this: |
how might you run into the error? |
this error occurs, for example, when a row contains a |
TextFormField or a TextField but the latter has |
no width constraint. |
<code_start> |
widget build(BuildContext context) { |
return MaterialApp( |
home: scaffold( |
appBar: AppBar( |
title: const Text('Unbounded width of the TextField'), |
), |
body: const row( |
children: [ |
TextField(), |
], |
), |
), |
); |
} |
<code_end> |
how to fix it? |
as suggested by the error message, |
fix this error by constraining the text field |
using either an expanded or SizedBox widget. |
the following example demonstrates using an expanded widget: |
<code_start> |
widget build(BuildContext context) { |
return MaterialApp( |
home: scaffold( |
appBar: AppBar( |
title: const Text('Unbounded width of the TextField'), |
), |
body: row( |
children: [ |
expanded(child: TextFormField()), |
], |
), |
), |
); |
} |
<code_end> |
<topic_end> |
<topic_start> |
‘incorrect use of ParentData widget’ |
this error is about missing an expected parent widget. |
what does the error look like? |
the message shown by the error looks like this: |
how might you run into the error? |
while flutter’s widgets are generally flexible |
in how they can be composed together in a UI, |
a small subset of those widgets expect specific parent widgets. |
when this expectation can’t be satisfied in your widget tree, |
you’re likely to encounter this error. |
here is an incomplete list of widgets that expect |
specific parent widgets within the flutter framework. |
feel free to submit a PR (using the doc icon in |
the top right corner of the page) to expand this list. |
how to fix it? |
the fix should be obvious once you know |
which parent widget is missing. |
<topic_end> |
<topic_start> |
‘setstate called during build’ |
the build method in your flutter code isn’t |
a good place to call setState, |
either directly or indirectly. |
what does the error look like? |
when the error occurs, |
the following message is displayed in the console: |
how might you run into the error? |
in general, this error occurs when the setState |
method is called within the build method. |
a common scenario where this error occurs is when |
attempting to trigger a dialog from within the |
build method. this is often motivated by the need to |
immediately show information to the user, |
but setState should never be called from a build method. |
the following snippet seems to be a common culprit of this error: |
<code_start> |
widget build(BuildContext context) { |
// don't do this. |
showDialog( |
context: context, |
builder: (context) { |
return const AlertDialog( |
title: Text('Alert dialog'), |
); |
}); |
return const center( |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.