The inner map function is causing the error in the title and I don't know how I can fix this. I want to make a calculation in the inner map function before returning the Widget.
var rowOnee = Column(children: [
...stampRows.map((i) => Row(
children: [
...[0,1,2,3,4].map((i) => {
return Text("hi");
})
],
))
]);
CodePudding user response:
There are a few ways to fix it. One way is to remove the arrow:
var rowOnee = Column(children: [
...stampRows.map((i) => Row(
children: [
...[0,1,2,3,4].map((i) {
return Text("hi");
})
],
))
]);
Or you could remove the curly brackets and return statement:
var rowOnee = Column(children: [
...stampRows.map((i) => Row(
children: [
...[0,1,2,3,4].map((i) => Text("hi"))
],
))
]);
CodePudding user response:
This is not the correct way to write an anonymous function in dart:
(i) => {
return Text("hi");
}
You can either do:
(i) {
return Text("hi");
}
or
(i) => Text("hi"),
Note that the anonymous function has either =>
for single expression anonymous functions or {}
for multiline anonymous functions, but not both.
When you have both, the {}
is interpreted instead as a set literal.
That said, you really should use collection-for instead of combining ...
and .map
. I suggest rewriting your code as the following:
var rowOnee = Column(children: [
for (var i in stampRows)
Row(children: [
for (var i in [0, 1, 2, 3, 4]) Text("hi")
]),
]);