1
My function was to obtain data from a system and mount the widgets
. It was synchronous and works perfectly.
children: _confere
.obterDados(data)
.map(
(d) => Conferencia(
dados: d,
),
)
.toList()
Now the need arose to make it asynchronous. Then came the headache with FutureBuilder
.
I tried several ways to iterate on the result and return a list of wigets
, but without success.
The closest I could get was with the code below:
children: <Widget>[
FutureBuilder(
future: _confere.obterDados(data),
builder: (_, AsyncSnapshot<ObservableList<Dados>> snapshot) {
if (snapshot.hasData) {
return Conferencia(dados: snapshot.data[2]);
} else {
return (Text('consultando'));
}
},
),
],
Obviously, in this code only a single result is returned. I would like to know how to return the iteration result using FutureBuilder
. Most of the examples I’ve seen only return widget
single and never, a list.
If your
snapshot.data
is a list and you also expect a list, you could create a new variable within the Builder function and with a repeat loop go through the snapshot and populate the variable. Then you could return this list inside your widget. You thought of something like?– Leonardo Paim
@Leonardopaim tried, but when I try to return a list shows the err: The Return type 'List<Widget>' isn’t a 'Widget', as required by the closure’s context.
acredito que devido
<Widget>[ If removed<Widget>
and leave return asList<Widget>
The argument type 'Futurebuilder<Observablelist<Data>>' can’t be Assigned to the Parameter type 'List<Widget>– rubStackOverflow
@Leonardopaim found a solution based on his information, but creating a new function
Future<List<Widget>> _widgets() async {
, I’ll wait if you want to post an answer, otherwise I’ll put the solution I found.– rubStackOverflow
No problem, post the solution that worked for you. Initially my suggestion was something generic so that I could direct you to the specific answer of your problem. Since Stack values effective answers to specific problems, it is best that you leave to the community the solution you applied and solved the problem you were initially.
– Leonardo Paim