'Flutter stream does not update global variable
On my firebase server i have a document which contains a bool field with the value "true"
I created a stream to listen for this value:
final CollectionReference _ref = FirebaseFirestore.instance.collection('collection');
Stream? getValue;
bool value = false;//Global variable
void initState() {
super.initState();
getValue = _ref.doc().collection("list").doc().snapshots();
getValue.forEach((element){
value = element["value"];
print(value);//Shows the correct value if it changes
});
}
//Somewhere else in the code but in the same class print(value);//Shows always false even if i change it on firebase to true and i don`t know why?
Let meh know if you needmore information, Thank you!
Solution 1:[1]
To update your value in a StatefulWidget, you should wrap with a setState.
_ref.doc().collection("list").doc().snapshots().listen((element) {
if (!mounted) {
return;
}
setState(() {
value = element["value"];
});
});
Solution 2:[2]
the hover is apply if button is enabled or disabled if you want to only apply style when button is enabled you can use the selector
button:hover:enabled
button:hover:enabled { border-color: red; color: red; }
button:active:enabled { border-color: green; color: green; }
button > span { background-color: #aaa; }
<button disabled>
<span>click</span>
<span>me</span>
</button>
Solution 3:[3]
According to W3Schools
A disabled button is unusable and un-clickable.
That's it, just because it's disabled doesn't mean it is un-hoverable.
Solution 4:[4]
You could use this on the button:
pointer-events: none;
It will disable all events of the pointer for the element you use it on. Beware that sometimes on hover elements, you got to place it on the parent. Depends on how it's built.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | jeremy-denis |
| Solution 3 | phucbm |
| Solution 4 | Frizzant |
