So I have a flutter program which is reading values from Cloud Firestore and stores them into variables. I can normally show their value with Text(), or change them. Now I wanted to make a Color display with a simple if statement. So if the Firestore value for example is bigger than 1 (>1), the color shall be blue. If it is smaller, then red.
But for some reason, when opening the page, it gives me this error: The method '>=' was called on null. Receiver: null Tried calling: >=(0.0)
But if I simply remove my if code, start the program again, and then add it again, it works just fine. It seems that it has a problem with the start values, but how do I fix that?
stream: FirebaseFirestore.instance
.collection('Digitaluhr')
.snapshots(),
builder: (context,
AsyncSnapshot<QuerySnapshot> snapshot) {
int itemCount =
snapshot.data.docs.length; //Dokumentlänge
itemCount--; //-1 weil Index
Luftguete = snapshot.data.docs[itemCount]
['Luftgüte']; //Luftgüte Wert zum Verarbeiten
return ListTile(
if (Luftguete > 2.00 && Luftguete <= 3.00)
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 40, color: Colors.yellow),
),
child: Text('Mäßig',
style: TextStyle(
height: 0.00001,
color: Colors.white,
backgroundColor: Colors.yellow)),
),
if (Luftguete > 3.00 && Luftguete <= 4.00)
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
width: 40, color: Colors.orange),
),
child: Text('Schlecht',
style: TextStyle(
height: 0.00001,
color: Colors.white,
backgroundColor: Colors.orange)),
),