Warning: Undefined array key "lang_code" in /home/pmfnldmy/public_html/androidatc/ap/extension/classes/common.php on line 800
Input of Information to Dart Program

Input of Information to Dart Program

stdin.readLineSync() function allows the program user to enter string values or intercept keyboard input from the console as shown in following example:

Here, at the first line of code, add : import 'dart:io' to import the dart:io library. This library allows IntelliJ to accept the input of information commands.

import 'dart:io';

main() {

  print('=============================');

  print('Please enter your full name:');



  String Full_Name=stdin.readLineSync();

  print('Hello:$Full_Name');

  print('=============================');

}


When you run this program, you will get the following message:

Then, enter your full name, then press Enter or Return key, you will get the following result :

The stdin.readLineSync() is used to enter string data type only. To configure the Dart program to enter an integer, use int.parse(stdin.readLineSync()) to convert the string value to integer. The following code displays how to create a program to enter integer values:

import 'dart:io';

main() {



  print('Please enter the first number:');

  int num1=int.parse(stdin.readLineSync());



  print('Please enter the second number:');

  int num2=int.parse(stdin.readLineSync());



  var sum=num1+num2;


  print('The sum result = $sum');

  }


When you run this program, you will get the following message :

Enter 5, then press Enter or Return key. You will get the following message:

Please enter the second number:

Enter 3, then press Enter or Return key, you will get the following result :

* This topic is a part of lesson 2 of Flutter Application Development course. For more information about this course, click here.