-1

i want to make a dodging (Multiplication) Table...and wanna take input from user from TexteditingController, but i am not able to take the integer value from the Text Editing controller. looking forward if someone would look into it,

TextEditingController num = TextEditingController();
  void table() {
    print('enter the number $num');

    for (var i = 1; i <= 10; i++) {
      print('$num*$i = ${num * i}'); //<error>(The operator '*' isn't defined for the type,,'')
    }
  }
    
  Scaffold(
    body: Column(
      children: [
        TextFormField(
          controller: TextEditingController(),
        ),
        Container(
          height: 400,
          width: 400,
          decoration: BoxDecoration(
            color: Colors.black,
            borderRadius: BorderRadius.circular(20),
          ),
          child: ElevatedButton(
            onPressed: table, 
            child: Text('')),
          ),
        ],
      ));
    }
  }
jraufeisen
  • 3,005
  • 7
  • 27
  • 43

1 Answers1

0

The error comes from the fact that you access the TextEditingController directly instead of grabbing the text it contains.

Correct would be:

TextEditingController controller = TextEditingController();
void table() {
  var enteredText = controller.text;
  var enteredNumber = int.parse(enteredText)

  for (var i = 1; i <= 10; i++) {
    print('$enteredNumber*$i = ${enteredNumber * i}');
  }
}
jraufeisen
  • 3,005
  • 7
  • 27
  • 43