Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: Operand of null-aware operation '??' has type 'String' which excludes null

Tags:

flutter

dart

I have the below 2 line code . I do say the controllers can be null in initialisation. And if it is null, take empty string. So why would it throw this error ?

final List<String>? controllers;
_nameController.text = widget.controllers[widget.index] ?? '';
like image 442
Anish Hemachandran Avatar asked Oct 23 '25 04:10

Anish Hemachandran


1 Answers

Try declaring like this:

final List<String?> controllers;
like image 76
NelsonThiago Avatar answered Oct 26 '25 00:10

NelsonThiago