The non-nullable local variable 'newTaskTitle' must be assigned before it can be used

46 Views Asked by At

enter image description hereenter image description here

I'm Trying to capture onChanged property value which is comming from my TextField and use it inside my onPressed textButton but it's not working. I've read most of the related issues in stack overflow but none of it actually helping in the problem. Do you have any better suggestion that I should do.

2

There are 2 best solutions below

3
On

You have not initialized newTaskTile before accessing it. So, at line 12 instead of:

String newTaskTile;

use:

String newTaskTile='';
1
On

You can use

    late String? newTaskTile;

and assign a value on init

  @override
  void initState() {
    super.initState();
    newTaskTile = 'some value';
  }