Dart : Input From User


In every programming language we can input value by two method either it is static means we can store value in variable when we write code and this value can not change during run time or we can get input from user which means when code is running at that time compiler ask to user to enter input and then compiler do further process.
In dart we can use one line code for getting user input.
Here , I am writing syntax and one example of how we can take unput from user.
Using this we can get input from user either value is String , Int , double , we can get type of input from user.
Using this we do not need to set pre-defined value of variable.
But , remember that there is small change in syntax between String and int, double which I have mentioned below.
Syntax
String? name = stdin.readLineSync(); (for String)
int? num= int.parse(stdin.readLineSync()!); (for Int)
double? num = double.parse(stdin.readLineSync()!); (for Double)
void main() { print("Enter Name : "); String? name = stdin.readLineSync(); print("You Enter $name" ); }
Subscribe to my newsletter
Read articles from Vinit Mepani directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

Vinit Mepani
Vinit Mepani
"Hello World, I'm Vinit Mepani, a coding virtuoso driven by passion, fueled by curiosity, and always poised to conquer challenges. Picture me as a digital explorer, navigating through the vast realms of code, forever in pursuit of innovation. In the enchanting kingdom of algorithms and syntax, I wield my keyboard as a magical wand, casting spells of logic and crafting solutions to digital enigmas. With each line of code, I embark on an odyssey of learning, embracing the ever-evolving landscape of technology. Eager to decode the secrets of the programming universe, I see challenges not as obstacles but as thrilling quests, opportunities to push boundaries and uncover new dimensions in the realm of possibilities. In this symphony of zeros and ones, I am Vinit Mepani, a coder by passion, an adventurer in the digital wilderness, and a seeker of knowledge in the enchanting world of code. Join me on this quest, and let's create digital wonders together!"