1
votes

Row( mainAxisAlignment: MainAxisAlignment.center, children: [ Padding( padding: const EdgeInsets.all(8.0), child: Icon( password[0] == null ? unchangedPassword : changedPassword, color: Colors.white, size: 20, ),

Can someone please explain why I can't write an if statement that checks if the value of the index is equal to a null value?

2
what is password? Add more details..Tirth Patel
List<int> password = [];M A

2 Answers

1
votes

password[0] doesn't exist. It appears password is a List

you could do password[0] == null if it was a map, but it's not. It's a list. That value doesn't exist. It's not null. It doesn't exist. So it blows up.

Why doesn't it exist? Because the memory wasn't allocated. Flutter will allocated the memory automatically when you need it. If you do password.add(value), then password[0] will exist at that point. But since you're getting the range error you haven't used password.add

For lists, use password.isNotEmpty or password.length == 0;

0
votes

Use password.isEmpty instead of password[0] == null