Reputation: 325
I have an app which has a list and when its empty it shows "null", but i wanted to show nothing instead of it but i can't. I have tried to make a verification but it still showing null for some reason.
Here is the code:
child: Text(
produtosList1.isEmpty ||
produtosList1[index].qtd == "" ||
produtosList1[index].qtd == null
? " "
: produtosList1[index].qtd,
style: TextStyle(fontWeight: FontWeight.bold),
),
But here is how it shows:
What am i doing wrong?
Upvotes: 1
Views: 894
Reputation: 3225
If you have a variable that can be null
you can do this to show something else instead of it:
produtosList1[index].qtd ?? 'Instead of null'
.
??
returns the expression on its left unless that expression’s value is null, in which case it evaluates and returns the expression on its right.
Upvotes: 0
Reputation: 12353
Add this check also to your ||
produtosList1[index].qtd == "null"
.
Your app is displaying null
and not an empty string ""
because most likely the value in qtd
is a String "null"
.
Upvotes: 1