Home > Mobile >  get input value from user
get input value from user

Time:08-02

I was using an online compiler where I write simple code for the grading system but it cannot input from users about marks. I tried many youtube tutorials and articles to fix this nothing is working

print("Enter Your Marks");
String marks = stdin.readLineSync(); 
print("You Enter ${marks} marks");

input function not working

help me to solve this issue in this piece of code

CodePudding user response:

can you try with this

String? marks = stdin.readLineSync(); 

CodePudding user response:

You can view this reference: https://www.geeksforgeeks.org/dart-standard-input-output/

import 'dart:io';
print("Enter Your Marks");
String? marks = stdin.readLineSync();
print("You Enter ${marks} marks");

CodePudding user response:

readLineSync returns nullable String. Therefore, you cannot assign it on String.

In order to accept nullable data dart use dataType? yourVariableName

For your case,

  String? marks = stdin.readLineSync();

You can explore more about null-safety

  • Related