Home > Mobile >  Exception "Global evaluation requires a thread to have been loaded" on VSCode when reading
Exception "Global evaluation requires a thread to have been loaded" on VSCode when reading

Time:04-24

I've been trying to run a Dart code like that on VSCode:

import "dart:io";
void main() {
  print("Input a number");
  int numA = int.parse(stdin.readLineSync()!);
  print("The number is $numA");
}

However, after printing "Input a number" for the user input a number (duh), the program freezes with the message Global evaluation requires a thread to have been loaded:

Exception when reading values

The same program runs fine everywhere, e.g., JDoodle and IntelliJ. Any clue of what is happening, folks? No thread here on Stackoverflow provided an answer.

CodePudding user response:

By default applications run in the Debug Console, where the input is used as a REPL to evaluate expressions. If you want to interact with stdin for the process, you'll need to set the app to run in the Terminal.

You can do this with a launch configuration that includes:

"console": "terminal",

Or, you could set the dart.cliConsole setting in VS Code:

"dart.cliConsole": "terminal"
  • Related