Given the following block of code in Flutter, I am seeing syntax errors that I wouldn't expect
FloatingActionButton(
onPressed: () => {
//undefined name x, Expected to find ','
int x = 12;
//Unexpected text 'return'
if (_timer != null && _timer!.isActive)
{
return
}
_timer =
Timer.periodic(Duration(milliseconds: 250), (timer) {
for (var i = 0; i < 6; i++) {
myKeys[i].currentState?.roll();
}
})
},
child: const Icon(Icons.check),
),
In JS (or c#) something like this works fine:
const f = ()=> {
var j = "123";
console.log(j);
return;
}
Other than "because it wasn't implemented that way", why doesn't this work in Dart and what's the right way to do this?
() { ..., not() => { ...() => { ... }declares a zero-argument anonymous function that returns aSetliteral.