Why Dart ignoring my null check?
Because when the following code executed:
Widget? footer;
...
if (footer != null && index == data.length) {
return footer;
}
There is a probability that your footer
is set to null
from the other part of your code hence the error is shown.
You can add !
if you're completely sure that the footer
won't be nulled for the rest of its life. So, you can use this:
if (footer != null && index == data.length) {
return footer!;
}
but your solution much safer because it always check if footer
not null:
if (footer != null && index == data.length) {
// whenever footer is nulled, return SizedBox
return footer ?? const SizedBox();
}