Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

dart
communitycreator

How to get input from users in Dart

Muhammad Hameed

Dart is a client optimized programming language that can be used for apps on multiple platforms. It is based on object oriented programming and it can be compiled to JavaScript or native code.

How to take input in Dart

To take input from a user in Dart, you need to import the dart:io library. The input is taken through the console using the .readLineSync() function.

Code

In the code below, enter your name in stdin column first and then press the run button:

import 'dart:io';  
void main() 
{ 
    String name = stdin.readLineSync(); 
    print("Hello, $name"); 
} 

Enter the input below

add the name in stdin section

This was how you can take a string as input in the console. Below, we will see how we can take an integer value as input in the console:

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

Enter the input below

add the number in stdin section

RELATED TAGS

dart
communitycreator
RELATED COURSES

View all Courses

Keep Exploring