1

Every example of async code I have tried in Dart, mostly from their site does not seem to work for me.

import 'dart:io';

main() async {
  var socket = await Socket.connect('127.0.0.1', 4041);
  print(socket.runtimeType);
  socket.write('Hello, World!');
}

Example code from their cookbook

And it throws me

error: line 3 pos 1: unexpected token 'main'
main() async {

I think its looking for a return type for the function? But I can't find any kind of documentmentation where you can tell what it is looking for, thanks for the help!

1
  • My dart says its version is 1.5.3 I run the install as choco install dart-sdk -version 1.18.1 Commented Aug 22, 2016 at 22:59

1 Answer 1

3

Dart asynchrony support (async, await etc.) came in version 1.9. You need to update your SDK.

Presumably your update did not work. Try choco upgrade dart-sdk. Or you may have to uninstall then re-install the latest version.

Sign up to request clarification or add additional context in comments.

2 Comments

Yup, thanks I ended up using the unofficial install method and it seemed to isntall the correct version, I installed it like yesterday, and I checked the version file in the dart-sdk folder and it said 1.18.2, not sure what messed up, thanks for the clarification on version numbers
You may have had the current sdk and an older one installed, The older one being run when you invoked dart.exe. Which is whydart.exe --version printed 1.5.3 even though the version file you checked indicated 1.18.2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.