I have a unique situation where flutter/dart seems to be requiring a coma for line endings instead of semi colon and I am completely baffled. Is this correct behavior or is there some major bug going on?
SharedPreferences.getInstance().then((prefs) => {
prefs.setString("auth", sr.data);
prefs.setString("phone", myPhone);
}
produces the error "Expected to find ‘}’
if I change them to commas its totall fine
SharedPreferences.getInstance().then((prefs) => {
prefs.setString("auth", sr.data),
prefs.setString("phone", myPhone),
}
I have a lot more code in here with if statements and other things going on but its all the same. Any semicolon produces the error and commas seem to make everything happy. If this is correct behavior how do I know when commas are needed??
2
Answers
() {} requires semi column
() => {} requires comma
The solution doesn’t actually give the answer, and @noone392 in its comment does not know what he’s talking about.
() {}
is a function, whose code exists inside of{}
.() => {}
is also a function, but one that return an emptyMap
object.This is the code that OP wants (notice the lack of
=>
):