Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in using Stdin.readLineSync(); in dart

Tags:

dart

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();
                      ^^^^^^^^^^^^
like image 541
Aditya Karad Avatar asked Feb 17 '26 15:02

Aditya Karad


2 Answers

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.

like image 55
salauddin23shumon Avatar answered Feb 20 '26 02:02

salauddin23shumon


You must add:

import 'dart:io';

before your main function

like image 34
aymanebenhima Avatar answered Feb 20 '26 03:02

aymanebenhima



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!