Icallitvera Icallitvera - 1 year ago 144
Dart Question

Example async dart code not working

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('', 4041);
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!

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download