Does dartpad not support I/O?
1,501
Solution 1
The dart:io
library is not supported in DartPad. However you can use this Dart compiler, it supports dart:io
.
Solution 2
As noted in the dart:io
documentation:
Important: Browser-based apps can't use this library. Only the following can import and use the dart:io library:
- Servers
- Command-line scripts
- Flutter mobile apps
- Flutter desktop apps
Author by
Jay
Updated on December 28, 2022Comments
-
Jay over 1 year
Recently I was trying out some code snippets from "Dart For Absolute Beginners" on DartPad. Specifically:
import 'dart:math'; import 'dart:io'; void main() { int guess; Random rand = new Random(); //create a random number generator int answer = rand.nextInt(100); //gets a random integer from 0 to 99 do { print("Enter your guess:"); String temp = stdin.readLineSync(); //read in from the keyboard guess = int.parse(temp); //convert String to integer if (guess < answer) { print("Too low!"); } else if (guess > answer) { print("Too high!"); } } while (guess != answer); print("You got it!"); }
However upon running, it shows the error "Error compiling to JavaScript: unsupported import: dart:io"
So my question is
Is it that we can't run I/O operations on DartPad and we need a full fledge editor for that ? or is there something else wrong ??
-
Jay about 3 yearsSo, do we have to use desktop editor for that ?
-
Andrej about 3 yearsYeah, that is the way to go.
-
Jay about 3 yearsThanks! @Andrej
-
Andrej about 3 yearsHey, I just found an online Dart compiler, I left you a link in the answer.
-
Jay about 3 yearsthe compiler is otherwise great but does not give manual control over NULL safety like DartPad
-
Andrej about 3 yearsIf you want null safety control then you should download a desktop editor. :)
-
Jay about 3 yearsLet us continue this discussion in chat.