0

i have a FutureBuilder with a ListView.builder. Inside that i want to show a container with a text only if a FIELD from the document exists. I have tried the following from the documentation and from multiple stack answers but no succes.

snapshot.data.docs[index].data()["Field"]!=null 
  ?
  Container(
     child: Text("Null check works");
  )
:Container()
snapshot.data.docs[index].data().containsKey("Field") ?
 Container(
   child: Text("Null check works");
 ) 
:Container()

If i try to null check the field inside a function separately and print a text to confirm if the field is or not null, it works, but when i try to null check a field as above, it doesnt work. Did anyone have this problem?

Victor Eronmosele
  • 7,040
  • 2
  • 10
  • 33
Alexm
  • 1
  • 2
  • what exactly you meant by - it doesn't work? Is there any error? As you're returning a `Container()` you'll not see anything in UI as you haven't given any width or hight to that container. – Hitesh Patil Aug 27 '21 at 06:05
  • Hi Hitesh Patil. There is no error in the console. Even if i check if it's != null or i use containsKey, the statement is always false and therefore it shows Container(). (it doesn't matter if the container for the false response doesnt have a child, it is just an example) – Alexm Aug 27 '21 at 07:11

1 Answers1

0

Solved

After restarting android studio multiple times, i got the same behaviour. Only after i restarted the PC, it worked without any change to the code above. Before i only received false from the statement (both containsKey and !=null). I suspect it may be a flutter version problem.

Alexm
  • 1
  • 2