user11290639
user11290639

Reputation:

Instance member 'readLineSync' can't be accessed using static

I'm trying to make a BMI calculator as a beginner project, as I am learning Dart. However, when I'm trying to take input, it outputs an error

import 'dart:io';

void main() {

  print('What is your weight in kgs?');
  var weight = Stdin.readLineSync();

  print("Your weight is $weight");


}

enter image description here

Upvotes: 1

Views: 284

Answers (1)

Ben Konyi
Ben Konyi

Reputation: 3219

You're trying to call readLineSync on the class, not on an instance. Since readLineSync isn't static, you'll need to call this on an instance of Stdin.

There's a global instance of Stdin named stdin exposed through dart:io that you can use for this.

Upvotes: 4

Related Questions