I have the following code to filter a list from data to be shown in a listView:
child: FutureBuilder(
future: fetchPacientes('todo'),
builder: (context, snapshot) {
if (snapshot.hasData) {
var filteredList = snapshot.data;
print("a minusculas:" +
_controller.text.toLowerCase());
filteredList = filteredList
.where((element) => (element.nombre
.toLowerCase()
.contains(
_controller.text.toLowerCase()) ||
element.NHC.toLowerCase().contains(
_controller.text.toLowerCase()) ||
element.apellidos.toLowerCase().contains(
_controller.text.toLowerCase())))
.toList();
But I am getting an error at point:
.where(...
This is the error output:
The method 'where' can't be unconditionally invoked because the receiver can be 'null'.
I am trying to migrate an old app to Null Safety, but I am not able to solve this issue. The proposed solution is to add a null check at filteredList! but the error is not removed when doing that way