Solution for (FLUTTER) — RangeError (index): Invalid value: Valid value range is empty: 0
is Given Below:
padding: const EdgeInsets.all(8.0),
password == null ? unchangedPassword : changedPassword,
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?
password doesn’t exist.
It appears password is a List
you could do password == 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 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;
password.isEmpty instead of
password == null