Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does dart/flutter sometimes require comma instead of semicolon in dart?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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??

>Solution :

() {} requires semi column

SharedPreferences.getInstance().then((prefs) {
    prefs.setString("auth", sr.data);
    prefs.setString("phone", myPhone);
}

() => {} requires comma

SharedPreferences.getInstance().then((prefs) => {
    prefs.setString("auth", sr.data),
    prefs.setString("phone", myPhone),
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading