Search code examples
flutterdartdart-null-safety

Dart, stdin.readLineSync();


I'm new in world of dart and I have problem with this:

import 'dart:io';
void main() {
  print('Please your name:');
  String name = stdin.readLineSync();
  print('$name');
}
I/flutter ( 7962): Please your name:

I/flutter ( 7962): null

Every time the value is null.


Solution

  • import 'dart:io';
    
    void main() {
      print('Please your name:');
      String? name = stdin.readLineSync();
      print('$name');
    }