Reputation: 71
in vs code, i am getting this error in the basic input taking code from the user my complete code:
import 'dart:io';
void main(){
stdout.write("Enter your name : ");
var name = stdin.readLineSync();
stdout.write(name);
}
Error in the compiler:
playground.dart:9:23: Error: Method not found: 'Stdin.readLineSync'.
String name = Stdin.readLineSync();
^^^^^^^^^^^^
Upvotes: 3
Views: 11183
Reputation: 1
You can change this by going into File -> Preferences -> Settings. Here you go into Extensions -> Dart & Flutter. If you scroll down you can find "Dart: Cli Console". You can also just search for "Dart Cli console":
Upvotes: 0
Reputation: 155
Overall it's not good practice to use a null assertion operator !
whereby you're personally guaranteeing to the compiler that the variable in question will never have a null reference. In this case, it may be more prudent to write:
String? name = stdin.readLineSync();
https://api.dart.dev/stable/2.18.6/dart-io/dart-io-library.html
Upvotes: 0
Reputation: 31
Console applications aren't running on VSCode. I assume that your code is named "main.dart" You can use directly from the VSCode terminal:
dart run main.dart
My VSCode version is: 1.85.2
Upvotes: 2
Reputation: 21
you should write it -> stdout.writeln and also import the library for it, I amended the code for you below, and it works fine on VSCode
import 'dart:io';
void main(){
stdout.writeln("Enter your name : ");
var name = stdin.readLineSync();
stdout.write(name);
}
Upvotes: 0
Reputation: 1
The error you get with stdin.readLineSync() is due to null safety introduced in Dart 2.12. Just add (!)
var name = stdin.readLineSync()!;
Upvotes: 0
Reputation: 11
stdin.readLineSync()! use the '!' as I did below:
void main(){
stdout.write("Enter your name : ");
var name = stdin.readLineSync()!;
stdout.write(name);
}
Upvotes: 1
Reputation: 1
if you were getting error like
"Getter not found.'stdin'"
in VSCode check for the extension "dart" is installed on your VSCode then checkitout for run i.e dart run command
Upvotes: 0
Reputation: 165
To learn dart as console application you should use IntelliJ IDEA IDE.
This is the best IDE for dart.
vscode, dartpad does not support stdin stdout.
Upvotes: 4