Does dartpad not support I/O?

Issue

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 ??

Solution

The dart:io library is not supported in DartPad. However you can use this Dart compiler, it supports dart:io.

Answered By – Andrej

Answer Checked By – Mary Flores (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.